Padrox Posted June 14, 2023 Share Posted June 14, 2023 Hey there, I'm developing a module for Prestashop version 8. I want my module to add a new variable for every products when you define a new product and to be able to retrieve it using the $params['product'] variable passed through some hooks. I need this variable to be able to toggle on and off to sell a related product of the product page of an actual product on my website. For example, if I click on the product "Super Red Shirt", I added a button that adds another product to the cart but I want to be able to enable or disable this feature in the BO when I create a product, because not every products must include this "related" product. I'm available if you need more details about my question, Thanks in advance, Padrox Link to comment Share on other sites More sharing options...
Padrox Posted June 19, 2023 Author Share Posted June 19, 2023 Anyone ? Link to comment Share on other sites More sharing options...
Med solver Posted June 22, 2023 Share Posted June 22, 2023 hi there, your idea is very scattered if you want to add a variable to the product and retrived whenever the product object called you just need to added to product model class if you want to show and hide the related products on product page go to /themes/your-theme/templates/catalog/product.tpl then you will find related products at the end of the file called ($accessories), so there add your if statment that check if your variable off or on to show/hide the section (related products) if you want to control the feature of enable/disable related products on each product on backoffice, you need to add a checkbox there, so you need entere your admin files Link to comment Share on other sites More sharing options...
Padrox Posted June 22, 2023 Author Share Posted June 22, 2023 Hey Med solver, First thing first, thank you very much for your answer ! Just to clarify, I first add my variable to the product model class like so: class ProductCore extends ObjectModel { /** * @var string Tax name * * @deprecated Since 1.4 */ public $tax_name; /** @var bool Enable Plinths rate */ public $enablePlinths; /** @var float Tax rate */ public $tax_rate; /** @var int Manufacturer identifier */ public $id_manufacturer; /** Some stuff */ Now I can access this variable through a product ? But how to make it configurable when creating a new product ? Link to comment Share on other sites More sharing options...
Med solver Posted June 22, 2023 Share Posted June 22, 2023 (edited) Your welcome Padrox if you want it configurable, its how i said you need to enter the admin files section and search where product edit and create placed then add your checkbox and after that you need to search where product submit (edit/create) handler and then you need to get the value of new checkbox you added and stored on database and of course you need to add column in database in ps_product for the checkbox value. and in productController.php you need get tha value from database and placed to the variable you just added to the model class product. the proccess of all this can be hard but its possible and need a lot of work, advice for me download the prestashop files on your local and start searching by class or name of the inputs that placed on product edit/create page, you dont have to do all stuff from scratch you just need to do copy past. for example the checkbox for making the product active or not, you just need to do the same but the value will placed to your new variable not to active/desactive product. i hope this help you Padrox and sorry for my english i just want the idea to be understood. Edited June 22, 2023 by Med solver (see edit history) 1 Link to comment Share on other sites More sharing options...
Med solver Posted June 22, 2023 Share Posted June 22, 2023 (edited) product page (edit,create) where checkobx active/descative placed is here \src\PrestaShopBundle\Resources\views\Admin\Product\ProductPage\Blocks\footer.html.twig Edited June 22, 2023 by Med solver (see edit history) Link to comment Share on other sites More sharing options...
Padrox Posted June 30, 2023 Author Share Posted June 30, 2023 Hey, Thank you so much for your return, I think I can the point, I'll mess around and come back to you soon! Thank again 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