Alien(PL) Posted July 18, 2021 Share Posted July 18, 2021 (edited) Hi guys im adding custom field into presta product page. Hi guys I'm adding a custom field to the admin product page I need your help because I'm missing something. What did till now: 1. I've add new field to table ps_product hide_discount_table - tinyint(1) - NOT NULL 2. override/classes/Product.php public $hide_discount_table; public function __construct($id_product = null, $full = false, $id_lang = null, $id_shop = null, Context $context = null) { self::$definition['fields']['hide_discount_table'] = array('type' => self::TYPE_BOOL, 'shop' => true, 'validate' => 'isBool'); } 3. src/PrestaShopBundle/Form/Admin/Product/ProductInformation.php // LINE 238 ->add('hidden_discount_table', FormType\CheckboxType::class, [ 'label' => $this->translator->trans('Hide discount table', [], 'Admin.Global'), 'required' => false, ]) 4. src/PrestaShopBundle/Model/Product/AdminModelAdapter.php: private $translatableKeys = array( //...LINE 140 'hidden_discount_table', ); private $unmapKeys = array( //... LINE 161 'hidden_discount_table', ); private function mapStep1FromData(Product $product) { return array( //... LINE 518 'hide_discount_table' => $product->hide_discount_table== 0 ? false : true, ); } 5. src/PrestaShopBundle/Resources/views/Admin/Product/ProductPage/product.html.twig: {# PANEL ESSENTIALS #} {% block product_panel_essentials %} {% set formQuantityShortcut = form.step1.qty_0_shortcut is defined ? form.step1.qty_0_shortcut : null %} {{ include('@Product/ProductPage/Panels/essentials.html.twig', { 'formPackItems': form.step1.inputPackItems, 'productId': id_product, 'images': form.step1.vars.value.images, 'formShortDescription': form.step1.description_short, 'formDescription': form.step1.description, 'formManufacturer': form.step1.id_manufacturer, 'formHiddenDiscount': form.step1.hide_discount_table, // NEW ENTERY 'formFeatures': form.step1.features, 'formManufacturer': form.step1.id_manufacturer, 'formRelatedProducts': form.step1.related_products, 'is_combination_active': is_combination_active, 'has_combinations': has_combinations, 'formReference': form.step6.reference, 'formQuantityShortcut': formQuantityShortcut, 'formPriceShortcut': form.step1.price_shortcut, 'formPriceShortcutTTC': form.step1.price_ttc_shortcut, 'formCategories': form.step1, }) }} {% endblock %} 6. src/PrestaShopBundle/Resources/views/Admin/Product/ProductPage/Panels/essentials.html.twig (in right column) <div class="form-group mb-4"> <h2>Additional features</h2> {{ form_widget(formHiddenDiscount) }} </div> On front-end i can print the value from DB in product.tpl {$product->hide_discount_table} That works fine. What doesnt work: Saving changes - it save other changes but doesnt see checkbox Edited July 18, 2021 by Alien(PL) (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