Jump to content

module custom prestashop 1.6.1.24


overbags
 Share

Recommended Posts

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

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More