从 prestashop 中的模块更新产品

Update product from a module in prestashop

我必须更新数据库中特定 productspricequantity 值。

据我了解,简单地执行 sql 命令并不是一个很好的选择,因为有很多表具有类似的信息。我读到应该创建 Product() 对象。

我应该如何创建 Product 对象然后在数据库中更新它?

您可以查看 classes/Product.php 中的 class ProductCore 了解各种方法和属性

一般来说,你会写这样的代码

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

编辑: 要更新数量,您可以使用此方法:

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