rezadri Posted January 18, 2023 Share Posted January 18, 2023 Hi, I want to add a new checkbox in the product tab that will be called product_unchecked in Prestashop 1.7.8.3. My problem is that when I check the checkbox and hit save no error appears, but when I refresh the product tab again, the checkbox is unchecked and in the database does not change the value to 1. I have seen several tutorials but I can't find the solution, as they are quite old. These are the steps I have followed, I attach screenshots to see if a solution can be found. 1.- Add field in the database 2.- I create the file product.php in override/classes/Product.php <?php public $producto_descatalogado ; public function __construct ( $id_product = null , $full = false , $id_lang = null , $id_shop = null , Context $context = null ) { self::$definition['fields']['producto_descatalogado'] = array('type' => self::TYPE_BOOL, 'shop' => true, 'validate' => 'isBool'); } ?> 3.- I add the following lines in src/PrestaShopBundle/Form/Admin/Product/ProductInformation.php ->add('producto_descatalogado', FormType\CheckboxType::class, [ 'label' => $this->translator->trans('producto descatalogado', [], 'Admin.Global'), 'required' => false, ]) 4.- I add the following lines in src/PrestaShopBundle/Model/Product/AdminModelAdapter.php: private $multiShopKeys = [ [...] 'producto_descatalogado', ]; private $translatableKeys = [ [...] 'producto_descatalogado', ]; private $unmapKeys = [ [...] 'producto_descatalogado', ]; private function mapStep1FromData(Product $product) { [...] 'producto_descatalogado' => $product->producto_descatalogado== 0 ? false : true, ]; } 5.- I add the following lines 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', { [...] 'formDescatalogado': form.step1.producto_descatalogado, }) }} {% endblock %} 6. I add the following lines src/PrestaShopBundle/Resources/views/Admin/Product/ProductPage/Panels/essentials.html.twig <div class="form-group mb-4"> <h2>Descatalogado</h2> {{ form_widget(formDescatalogado) }} </div> Attached is a screenshot of the product sheet with the checkbox That's all, thank you. 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