从 prestashop 中的模块更新产品 [英] Update product from a module in prestashop

查看:59
本文介绍了从 prestashop 中的模块更新产品的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

据我所知,简单地执行 sql 命令并不是一个很好的选择,因为有很多表都有相似的信息.我读过应该创建 Product() 对象.

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

解决方案

你可以查看classes/Product.php中的ProductCore类的各种方法和属性

通常,你会写一些这样的代码

//假设你的产品id为$id_product$product = new Product($id_product);//改变产品属性$product->quantity = 10;$product->price = 60.2;//保存更改$product->save();

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

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

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?

解决方案

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

这篇关于从 prestashop 中的模块更新产品的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆