Update product from a module in prestashop

て烟熏妆下的殇ゞ 提交于 2019-12-11 20:36:47

问题


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:


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);


来源:https://stackoverflow.com/questions/30602713/update-product-from-a-module-in-prestashop

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!