jeremiezip Posted April 24, 2017 Share Posted April 24, 2017 Hello everybody, I'have recently installed PS 1.7 for a project. I discover the framework Symfony, and i would like to know the best way for override the Admin Product. (for example: add a field in the product information) I changed these informations directly in the bundle Prestashop, but it is not clean. It would be interesting to talk about it, all together ! Thanks for your contribution, J. I Link to comment Share on other sites More sharing options...
phinq1910 Posted April 24, 2017 Share Posted April 24, 2017 Do you know about the displayAdminProductsExtra hook, actionProductUpdate hook and actionProductAdd hook I think you can add your custom field easy with them. Link to comment Share on other sites More sharing options...
jeremiezip Posted April 25, 2017 Author Share Posted April 25, 2017 Hello phinq, thank you for you reply. Yes i know these hook, very usefull when you creating Module. But i have the case of a customer who specifically wants to add fields in the main info of product BackOffice (not in a hook). Do you have any idea? But I have the case of a client who specifically wants to add fields in the main info of the product (back office But I have the case of a client who specifically wants to add fields in the main info of the product (back office But I have the case of a client who specifically wants to add fields in the main info of the product (back office ut I have the case of a client who specifically wants to add fields in the main info of the product (back office But I have the case of a client who specifically wants to add fields in the main info of the product (back office Link to comment Share on other sites More sharing options...
Zordiak Posted April 27, 2017 Share Posted April 27, 2017 Hi jeremiezip, I have the same issue, and I need to add new fields in Combinations too. I have read the documentation but there is no too much about it, except that Product works with Symfony and currently the only way (that I know) to add new fiels is through modules and hooks. Maybe in next updates we will have other ways to do that, but for now, it is neccessary modify prestashop bundle if you want to make it easy for employee's experience. I am trying to override some prestashopbundle controllers and templates through Symfony but I am not lucky for the moment. Have you encountered any better solution? Link to comment Share on other sites More sharing options...
phinq1910 Posted April 28, 2017 Share Posted April 28, 2017 (edited) I think you can do with 2 cases: 1/ Edit the core of prestashop (Edit the controller, model, .tpl,...) 2/ Try to using hook + javascript Good luck for you Edited April 28, 2017 by phinq1910 (see edit history) Link to comment Share on other sites More sharing options...
jeremiezip Posted May 2, 2017 Author Share Posted May 2, 2017 (edited) yes, this is my code, it works but it's not a good way because if you update Prestashop, you'll loose all your changes. This is the case of a customer who wants absolutely a textarea field in the product information tpl (not in a hook) : first in database in the table ps_product_lang add your field "my_extra_field_description" type TEXT add an override of class product in override/classes , with the new field (for this case, it doesn't work for me, i adding the field directly in the class, not in a override)... but this is an example 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); } } (don't forget to remove the cache) 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 )) 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', ); and below in the function getFormData() add field : 'my_extra_field_description' => $this->product->my_extra_field_description, in src/PrestaShopBundle/Resources/views/Admin/Product/form.html.twig: <ul class="nav nav-tabs bordered"> <li id="tab_description_short" class="nav-item"><a href="#description_short" data-toggle="tab" class="nav-link description-tab active">[spam-filter] 'Summary'|trans({}, 'Admin.Catalog.Feature') [spam-filter]</a></li> <li id="tab_description" class="nav-item"><a href="#description" data-toggle="tab" class="nav-link description-tab">[spam-filter] 'Description vin'|trans({}, 'Admin.Global') [spam-filter]</a></li> <li id="tab_my_extra_field_description" class="nav-item"><a href="#la_presse_en_parle" data-toggle="tab" class="nav-link description-tab">[spam-filter] 'My extra field description'|trans({}, 'Admin.Global') [spam-filter]</a></li> </ul> <div class="tab-content bordered"> <div class="tab-pane panel panel-default active" id="description_short"> [spam-filter] form_widget(form.step1.description_short) [spam-filter] </div> <div class="tab-pane panel panel-default " id="description"> [spam-filter] form_widget(form.step1.description) [spam-filter] </div> <div class="tab-pane panel panel-default " id="my_extra_field_description"> [spam-filter] form_widget(form.step1.my_extra_field_description) [spam-filter] </div> </div><br/> So, if somebody know how to override a bundle ... thanks Edited May 23, 2017 by jeremiezip (see edit history) 2 1 Link to comment Share on other sites More sharing options...
oowwaa Posted May 10, 2017 Share Posted May 10, 2017 (edited) Thanks for these precious indications. I try to change the field for a simple text field rather than HTML tab. Everything works when i use form.step1 HTML field, if i change for from.html.twig for form.step6 (text field) or any for other type i got errors, does anyone know what i am missing? <h2> [spam-filter] "Short name"|trans({}, 'Admin.Catalog.Feature') [spam-filter] <span class="help-box" data-toggle="popover" data-content="[spam-filter] "Add short name. Allowed special characters: .-_#\."|trans({}, 'Admin.Catalog.Help') [spam-filter]" ></span> </h2> [spam-filter] form_errors(form.step6.short_name) [spam-filter] <div class="row"> <div class="col-xl-12 col-lg-12" id="short_name"> [spam-filter] form_widget(form.step6.short_name) [spam-filter] </div> </div> Neither the property "short_name" nor one of the methods "short_name()", "getshort_name()"/"isshort_name()" or "__call()" exist and have public access in class "Symfony\Component\Form\FormView" in "/home/www/ps2/src/PrestaShopBundle/Resources/views/Admin/Product/form.html.twig" at line 310. Edited May 10, 2017 by oowwaa (see edit history) Link to comment Share on other sites More sharing options...
lucesmo Posted May 17, 2017 Share Posted May 17, 2017 (edited) yes, this is my code, it works but it's not a good way because if you update Prestashop, you'll loose all your changes. This is the case of a customer who wants absolutely a textarea field in the product information tpl (not in a hook) : first in database in the table ps_product_lang add your field "my_extra_field_description" type TEXT add an override of class product in override/classes , with the new field (for this case, it doesn't work for me, i adding the field directly in the class, not in a override)... but this is an example 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); } } (don't forget to remove the cache) 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 )) 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', ); in src/PrestaShopBundle/Resources/views/Admin/Product/form.html.twig: <ul class="nav nav-tabs bordered"> <li id="tab_description_short" class="nav-item"><a href="#description_short" data-toggle="tab" class="nav-link description-tab active">[spam-filter] 'Summary'|trans({}, 'Admin.Catalog.Feature') [spam-filter]</a></li> <li id="tab_description" class="nav-item"><a href="#description" data-toggle="tab" class="nav-link description-tab">[spam-filter] 'Description vin'|trans({}, 'Admin.Global') [spam-filter]</a></li> <li id="tab_my_extra_field_description" class="nav-item"><a href="#la_presse_en_parle" data-toggle="tab" class="nav-link description-tab">[spam-filter] 'My extra field description'|trans({}, 'Admin.Global') [spam-filter]</a></li> </ul> <div class="tab-content bordered"> <div class="tab-pane panel panel-default active" id="description_short"> [spam-filter] form_widget(form.step1.description_short) [spam-filter] </div> <div class="tab-pane panel panel-default " id="description"> [spam-filter] form_widget(form.step1.description) [spam-filter] </div> <div class="tab-pane panel panel-default " id="my_extra_field_description"> [spam-filter] form_widget(form.step1.my_extra_field_description) [spam-filter] </div> </div><br/> So, if somebody know how to override a bundle ... thanks Hi Jeremiezip, Thank you for your comment, it was very useful. First of all, I tried overriding product class and it worked. I declare a new variable and it works properly. But when I try to visualize in the backend the new field I got some issues: I add the declared variable in the overriden file in the getFormData() method from the AdminModelAdapter.php file and I obtain it completely empty. It seems like the variable wasn’t declared. However, if I declare it in the product class it finally works. May it be because AdminModelAdapter.php file just loads parent class? File src/PrestaShopBundle/Model/Product/AdminModelAdapter.php (onlye declare prent class) public function __construct( \ProductCore $product, .... File override\classes\Product.php class Product extends ProductCore { public $tablas_nutricionales; public function __construct($id_product = null, $full = false, $id_lang = null, $id_shop = null, Context $context = null) { parent::$definition['fields']['tablas_nutricionales'] = array('type' => self::TYPE_HTML, 'lang' => true, 'validate' => 'isCleanHtml'); parent::__construct($id_product, $full, $id_lang, $id_shop); } } In another hand, it would be really useful to override a budle for not losing information when updating the shop. Did you get how to do it? Thank you. Best regards, Edited May 17, 2017 by lucesmo (see edit history) Link to comment Share on other sites More sharing options...
jeremiezip Posted May 17, 2017 Author Share Posted May 17, 2017 (edited) Of course Lucesmo, I have exactly the same result of you. Pressed for time, i finally modify the product class directly. (symfony doesn't takes the override) But it's a very bad practice... I don't know if it is a new philosophy of prestashop for encourages the usage of AdminProductHook... But I think it is necessary to have an explanation in the official documentation of Presta'. I've send a message to the Prestashop Team. developer Be on, if i solve the problem i forward the code here. Edited May 17, 2017 by jeremiezip (see edit history) Link to comment Share on other sites More sharing options...
Martin Fabre Posted May 18, 2017 Share Posted May 18, 2017 So this mean we can't override in 1.7 ? Link to comment Share on other sites More sharing options...
jeremiezip Posted May 23, 2017 Author Share Posted May 23, 2017 Thanks for these precious indications. I try to change the field for a simple text field rather than HTML tab. Everything works when i use form.step1 HTML field, if i change for from.html.twig for form.step6 (text field) or any for other type i got errors, does anyone know what i am missing? <h2> [spam-filter] "Short name"|trans({}, 'Admin.Catalog.Feature') [spam-filter] <span class="help-box" data-toggle="popover" data-content="[spam-filter] "Add short name. Allowed special characters: .-_#\."|trans({}, 'Admin.Catalog.Help') [spam-filter]" ></span> </h2> [spam-filter] form_errors(form.step6.short_name) [spam-filter] <div class="row"> <div class="col-xl-12 col-lg-12" id="short_name"> [spam-filter] form_widget(form.step6.short_name) [spam-filter] </div> </div> Neither the property "short_name" nor one of the methods "short_name()", "getshort_name()"/"isshort_name()" or "__call()" exist and have public access in class "Symfony\Component\Form\FormView" in "/home/www/ps2/src/PrestaShopBundle/Resources/views/Admin/Product/form.html.twig" at line 310. hello, I edited my post because I realized that I had forgotten a part... sorry. don't forget to add field in your product class. Link to comment Share on other sites More sharing options...
bogdan90i Posted August 18, 2017 Share Posted August 18, 2017 Hello, Does anybody have any idea on how to edit the Product Option page of the product? I edited: in src/PrestaShopBundle/Form/Admin/Product/ProductOptions.php I added after the ean13 add: ->add('ean13_current_shop', 'Symfony\Component\Form\Extension\Core\Type\TextType', array( 'required' => false, 'error_bubbling' => true, 'label' => $this->translator->trans('EAN-13 or JAN barcodez', [], 'Admin.Catalog.Feature'), 'constraints' => array( new Assert\Regex("/^[0-9]{0,13}$/"), ) )) in src/PrestaShopBundle/Model/Product/AdminModelAdapter.php: Also after ean13: 'ean13_current_shop' => $this->product->ean13_current_shop, in src/PrestaShopBundle/Resources/views/Admin/Product/form.html.twig Also after ean13 field: <fieldset class="col-md-4 form-group"> <label class="form-control-label"> [spam-filter] form.step6.ean13_current_shop.vars.label [spam-filter] <span class="help-box" data-toggle="popover" data-content="[spam-filter] "This type of product code is specific to Europe and Japan, but is widely used internationally. It is a superset of the UPC code: all products marked with an EAN will be accepted in North America."|trans({}, 'Admin.Catalog.Help') [spam-filter]" ></span> </label> [spam-filter] form_errors(form.step6.ean13_current_shop) [spam-filter] [spam-filter] form_widget(form.step6.ean13_current_shop) [spam-filter] </fieldset> And also edited the Product.php class directly. And i added: /** @var string Ean-13 barcode */ public $ean13_current_shop; and 'ean13_current_shop' => array('type' => self::TYPE_STRING, 'validate' => 'isEan13', 'size' => 13), And still it does not show on the front office. And as a test i deleted the file form.html.twig and nothing disappeared from the Product Options tab of the product. Any idea? Using prestashop 1.7.2.0 Thanks Link to comment Share on other sites More sharing options...
jeremiezip Posted August 18, 2017 Author Share Posted August 18, 2017 Have you refresh the cache of the website? Otherwise, i have some information about our initial problem. I discussed with a Prestashop Teacher. He told me that it is no longer possible to override the admin product. It is done to encourage the exclusive usage of hooks. I don't know if it's a fake news or not, but I think we can believe it. Link to comment Share on other sites More sharing options...
bogdan90i Posted August 18, 2017 Share Posted August 18, 2017 (edited) Hello, I have the website in maintenance mode. And i have force recompile and no cache. also checked the smarty folder and nothing to delete. Edit: So now it works, i think something was blocked. I tried it from different browsers and it did not work. But after i changed the original ean13 to what i wanted and back it started working. So the code is just fine. Edited August 21, 2017 by bogdan90i (see edit history) Link to comment Share on other sites More sharing options...
amerigeau Posted January 29, 2018 Share Posted January 29, 2018 Hello guys, Maybe it will help you, this is a post to override products in PrestaShop 1.7 in order to add custom fields. Just click on the image or the link under. You can like and comment the post if it helps you https://www.arnaud-merigeau.fr/prestashop-1-7-ajouter-des-champs-texte-aux-produits/ Bye ! Link to comment Share on other sites More sharing options...
Klemart3D Posted January 28, 2019 Share Posted January 28, 2019 Hello, I'm searching to override PrestaShopBundle\Model\Product\AdminModelAdapter class into module or override folder to don't be affected by a Prestashop update. How can I do that? I tried some solutions but no one seems works : namespace MyBundle\Model\Product; class AdminModelAdapter extends PrestaShopBundle\Model\Product\AdminModelAdapter class AdminModelAdapterOverride extends PrestaShopBundle\Model\Product\AdminModelAdapter namespace PrestaShopBundle\Model\Product; class AdminModelAdapterOverride extends AdminModelAdapter Link to comment Share on other sites More sharing options...
veijari Posted April 2, 2020 Share Posted April 2, 2020 Any information on how to make overrides on 1.7.6.4, some hook perhaps? 1 Link to comment Share on other sites More sharing options...
maiskiykot Posted November 1, 2020 Share Posted November 1, 2020 Any ideas for copying field to another tab? 1.7.6.1 Link to comment Share on other sites More sharing options...
karpoj23 Posted November 18, 2020 Share Posted November 18, 2020 I have only one problem, I cant save the data in the table. I show the field and get the value but I cant save. Link to comment Share on other sites More sharing options...
Guest Posted November 19, 2020 Share Posted November 19, 2020 (edited) . Edited July 26, 2021 by Guest (see edit history) Link to comment Share on other sites More sharing options...
karpoj23 Posted November 20, 2020 Share Posted November 20, 2020 23 hours ago, Guest said: @karpoj23 my_field = your field name In module: hookActionProductUpdate () { $id_product = Tools::getValue('id_product'); $my_field = Tools::getValue('my_field'); Db::getInstance()->execute("UPDATE "._DB_PREFIX_."product SET my_field = '".$my_field."' WHERE id_product = ".$id_product); } Thanks!! Link to comment Share on other sites More sharing options...
karpoj23 Posted November 26, 2020 Share Posted November 26, 2020 (edited) Hi again, i have with the same problem when I try to save or add a new product, I change debug mode to true and I only receive Error 500, but Validator it is ok and I do not display the error. I have compared with another domain with the same version and I see this: domain fail: only launch 1 hook - moduleRoutes domain good: launch 4 hooks - moduleRoutes, actionClearCache, actionProductSave, actionProductUpdate Edited November 26, 2020 by karpoj23 (see edit history) Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now