overbags Posted July 22, 2021 Share Posted July 22, 2021 Hello everybody I'm trying to make my first module for prestashop 1.6.1.24 somehow I managed to create a "reference_uni" field in the "product_attribute" table and to extract the quantity from the "stock_available" table only of the products of the new "reference_uni" field with this script -------------------------------------------------- ------------------ select a.reference_uni, a.id_product_attribute, a.id_product, b.quantity from ps_product_attribute a join ps_stock_available b on a.id_product_attribute = b.id_product_attribute where a.reference_uni> 0; -------------------------------------------------- ------------------ now I'm stopped because I should update the "quantity" field in the "stock_available" table only of the extracted "id_product_attribute". can you help me ? I think we need to create an array but I really don't know where to start Link to comment Share on other sites More sharing options...
Rhobur Posted July 23, 2021 Share Posted July 23, 2021 I recommend you study the official docs regarding the module creation. First of all you shouldn't alter the PS tables, create a new table for your module and link it with product_id for instance to other tables. Then do not use SQL queries to change quantities, use PS classes e.g. StockManager. Link to comment Share on other sites More sharing options...
overbags Posted July 23, 2021 Author Share Posted July 23, 2021 unfortunately it goes beyond my abilities I found some (empty) modules to compile, don't you have some example scripts ready to copy / paste in the main file or some links that can help me? Link to comment Share on other sites More sharing options...
Rhobur Posted July 23, 2021 Share Posted July 23, 2021 I am sorry, it wouldn't work this way, it is a bit more complex than copy/paste. I encourage you to read this https://devdocs.prestashop.com/1.7/modules/ . For a pointer of how to update a product quantity, something like this: StockAvailable ::setQuantity($product -> id, 0, $new_qty); where of course you previously initialize a product with $product = new Product($id_product); and you know this $id_product from your query. Link to comment Share on other sites More sharing options...
overbags Posted July 23, 2021 Author Share Posted July 23, 2021 thank you very much I will deepen Link to comment Share on other sites More sharing options...
overbags Posted July 23, 2021 Author Share Posted July 23, 2021 according to you what the file that manages the warehouse "I want to specify a quantity available manually." is StockAvailable.php? 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