I’ve figured out how to add new field to database using Prestashop (1.4.3, but I think for the newer versions would be the same). This solution gives you new field in database and you will be able to edit / save data to this field, for my example I needed a field which was called “number of photos”. Below you can see how it works.
When you want to get it you should make some improvements. First of all just create a new field in your database it will be called “nb_photos” in my case. And then:
1. Open AdminProducts.php file (/[admin_panel]/tabs/AdminProducts.php) and add this line (line 2194):
|
1 2 3 4 5 6 7 |
<tr>
<td class="col-left">'.$this->l('Number of photos:').'</td>
<td style="padding-bottom:5px;">
<input size="55" type="text" name="nb_photos" value="'.htmlentities($this->getFieldValue($obj, 'nb_photos'), ENT_COMPAT, 'UTF-8').'" style="width: 130px; margin-right: 44px;" />
<span class="hint" name="help_box">'.$this->l('Number of photos') . '</span>
</td>
</tr> |
2. Open Product.php (classes/Product.php) and add:
Line 130
|
1 2 |
/** @var integer Number of photos */
public $nb_photos; |
Line 231
|
1 2 3 |
'ean13' => 'isEan13',
'nb_photos' => 'isUnsignedInt', // this field
'upc' => 'isUpc', |
Line 340
|
1 2 3 |
$fields['ean13'] = pSQL($this->ean13);
$fields['nb_photos'] = pSQL($this->nb_photos);
$fields['upc'] = pSQL($this->upc); |
And that’s all. If you have any questions for that let me know

Leave a Reply