Update product from a module in prestashop

2019-09-08 19:27发布

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?

1条回答
兄弟一词,经得起流年.
2楼-- · 2019-09-08 19:45

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);
查看更多
登录 后发表回答