Jakubek Posted August 29, 2022 Share Posted August 29, 2022 Hi, I'm trying to add custom field in product page and admin panel 1. I added field in my database in ps_product_lang 2. In overrides/classes/Product.php: public function __construct($id_product = null, $full = false, $id_lang = null, $id_shop = null, Context $context = null) { self::$definition['fields']['price_week'] = array('type' => self::TYPE_STRING, 'shop' => true, 'validate' => 'isGenericName'); } 3. In src/PrestaShopBundle/Form/Admin/Product/ProductInformation.php ->add('price_week', FormType\TextType::class, [ 'label' => $this->translator->trans('Cena za tydzień', [], 'Admin.Global'), 'required' => false, ]) 4. In src/PrestaShopBundle/Model/Product/AdminModelAdapter.php: private $translatableKeys = array( //...LINE 140 'price_week', ); private $unmapKeys = array( //... LINE 161 'price_week', ); private function mapStep1FromData(Product $product) { return array( //... LINE 518 'price_week' => $product->price_week, ); } 5. In 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, 'priceWeek': price_week, // 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. In src/PrestaShopBundle/Resources/views/Admin/Product/ProductPage/Panels/essentials.html.twig (in right column): <div class="form-group mb-4"> <h2>Cena za tydzień</h2> <div class="input-group money-type week-price"> {{ form_widget(priceWeek) }} <div class="input-group-append"> <span class="input-group-text"> zł</span> </div> </div> </div> 7. In product-prices.tpl <td><span>{$product.price_week}</span></td> Im not getting any errors, but its not saving and the span in the product page is empty. What is wrong with my code? Link to comment Share on other sites More sharing options...
endriu107 Posted August 29, 2022 Share Posted August 29, 2022 I think it is not good idea overrding core file, any update will be painfull for you, better way is create custom module here is sample module https://github.com/PululuK/democustomfields17 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