我正在 codeigniter 中编写一个外部应用程序,它将读取产品的条形码并更新 Prestashop 数据库中的数量。现在我不确定应该更新哪个表。数据库中有 _DB_PREFIX_product、_DB_PREFIX_product_attribute、_DB_PREFIX_stock_available 表,其中产品 id 和数量列可用。
条形码列 (ean13) 在前 2 个表中可用。 请让我知道我应该更新哪个或哪些表格以正确更改产品数量
(prestashop版本为1.6)
最佳答案
从_DB_PREFIX_product
中选择id_product
,然后更新_DB_PREFIX_stock_available
中的数量。
您可以使用 prestashop 类,我从未使用过条形码,所以不知道什么是 ean13,但代码一定是。
<?php
include('config/config.inc.php');
include('init.php');
$ean13 = "ean13";
$sql = "SELECT id_product FROM _DB_PREFIX_product WHERE ean13='$ean13'";
//replace _DB_PREFIX_ with your prefix or define _DB_PREFIX_ on top.
$product_id = Db::getInstance()->getValue($sql);
if (!empty($product_id)) {
$quantity = 100;
StockAvailable::setQuantity((int)$product_id, 0, $quantity);
}
?>
StockAvailable::setQuantity((int)$product_id, 0, $quantity);
这里第二个参数是 id_product_attribute
为什么我传递 0
由于 id_product_attribute
在 pestashop 中,用户可以为每个属性组合添加库存例如,蓝色和 Mediam 尺寸为 300 个数量
。因此,如果您想更新特定组合的数量,则必须将该组合的 id 作为 id_product_attribute
传递。将 0
作为 id_product_attribute
传递将更新产品的总体数量和库存。
如果您不想使用 prestashop 类并希望从外部类更新数据库,则查询将为 UPDATE _Db_PREFIX_stock_availble SET amount='$quantity' WHERE id_product='$productID' AND id_product_attribute=0
关于php - 在 prestashop 中手动更新产品数量(外部脚本),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46274011/