How to add custom field prestashop
Step 1
Step 3
Step 1
first in database in the table ps_product_lang add your field "my_extra_field_description" type TEXT
Step 2
add an override of class product in override/classes
class Product extends ProductCore { public $my_extra_field_description; public function __construct($id_product = null, $full = false, $id_lang = null, $id_shop = null, Context $context = null) { Product::$definition['fields']['my_extra_field_description'] = array('type' => self::TYPE_HTML, 'lang' => true, 'validate' => 'isString'); parent::__construct($id_product, $full, $id_lang, $id_shop, $context); } }
Step 3
src/PrestaShopBundle/Form/Admin/Product/ProductInformation.php
->add('my_extra_field_description', 'PrestaShopBundle\Form\Admin\Type\TranslateType', array( 'type' => 'Symfony\Component\Form\Extension\Core\Type\TextareaType', 'options' => [ 'attr' => array('class' => 'autoload_rte'), 'required' => false ], 'locales' => $this->locales, 'hideTabs' => true, 'label' => $this->translator->trans('my_extra_field_description', [], 'Admin.Global'), 'required' => false ))
Step 4
in src/PrestaShopBundle/Model/Product/AdminModelAdapter.php:
//define translatable key $this->translatableKeys = array( 'name', 'description', 'description_short', 'my_extra_field_description', 'link_rewrite', 'meta_title', 'meta_description', 'available_now', 'available_later', 'tags', ); //define unused key for manual binding $this->unmapKeys = array('name', 'description', 'description_short', 'my_extra_field_description', 'images', 'related_products', 'categories', 'suppliers', 'display_options', 'features', 'specific_price', 'virtual_product', 'attachment_product', );
step 5
and below in the function getFormData() add field :
'my_extra_field_description' => $this->product->my_extra_field_description,
Step 6
in src/PrestaShopBundle/Resources/views/Admin/Product/ProductPage/product.html.twig:
'formInfoSupp': form.step1.my_extra_field_description
and in src/PrestaShopBundle/Resources/views/Admin/Product/ProductPage/Panels/essentials.html.twig:
add:
<div class="tab-pane panel panel-default " id="my_extra_field_description">
{{ form_widget(formInfoSupp) }}
</div>
add after decription
<li id="tab_my_extra_field_description" class="nav-item"><a href="#my_extra_field_description" data-toggle="tab" class="nav-link description-tab">Info supplémentaire</a></li>
Don't foreget to remove cache