user3352135
user3352135

Reputation:

Update product from a module in prestashop

I have to update the price and quantity values of specific products in a database.

As I understand, simply executing sql commands is not a great option since there are a lot of tables which have similar informations. I have read that Product() object should be created.

How should I create the Product object and then update it in the database?

Upvotes: 0

Views: 6092

Answers (1)

unloco
unloco

Reputation: 7320

You can check the class ProductCore in classes/Product.php for various methods and properties

Generally, you would write some code like this

//assuming you have the product id as $id_product
$product = new Product($id_product);
//change the product properties
$product->quantity = 10;
$product->price = 60.2;
//save the changes
$product->save();

Edit: To update the quantity you can use this method:

StockAvailable::updateQuantity($id_product, $id_product_attribute, $delta_quantity, $id_shop = null);

Upvotes: 9

Related Questions