新创建产品的插入量
insertion amount of a newly created product
我在 prestashop 上创建产品,我使用此功能输入金额:
echo "1";
StockAvailable::setQuantity($id_prod, 0, $quantity,1);
echo "2";
结果是:
1fatal error
在后端,产品和金额设置正确。
我怎样才能避免"fatal error"?
在这里报告我的错误:classes/Product.php in line 2582: if (!$id_cart && !isset($context->employee)) die(Tools::displayError());
此代码在函数 "getPriceStatic" 中。拉到执行是正常的"StockAvailable::setQuantity"?
我没有更改类并且我没有覆盖
通常我使用这个片段(根据您的需要进行调整):
$shop_is_feature_active = Shop::isFeatureActive();
$shops = Shop::getContextListShopID();
if ($shop_is_feature_active) {
foreach ($shops as $shop) {
StockAvailable::setQuantity((int)$product->id, 0, (int)$product->quantity, (int)$shop);
}
} else {
StockAvailable::setQuantity((int)$product->id, 0, (int)$product->quantity, (int)$this->context->shop->id);
}
不过,我总是建议检查产品是否在那家商店。
重要的是要检查
Context::getContext()->employee
不为空,否则输入:
$psContext = Context::getContext();
if (!$psContext->employee) {
$psContext->employee = new Employee(PS_DEFAULT_EMPLOYEE);
}
我在 prestashop 上创建产品,我使用此功能输入金额:
echo "1";
StockAvailable::setQuantity($id_prod, 0, $quantity,1);
echo "2";
结果是:
1fatal error
在后端,产品和金额设置正确。 我怎样才能避免"fatal error"? 在这里报告我的错误:classes/Product.php in line 2582: if (!$id_cart && !isset($context->employee)) die(Tools::displayError());
此代码在函数 "getPriceStatic" 中。拉到执行是正常的"StockAvailable::setQuantity"?
我没有更改类并且我没有覆盖
通常我使用这个片段(根据您的需要进行调整):
$shop_is_feature_active = Shop::isFeatureActive();
$shops = Shop::getContextListShopID();
if ($shop_is_feature_active) {
foreach ($shops as $shop) {
StockAvailable::setQuantity((int)$product->id, 0, (int)$product->quantity, (int)$shop);
}
} else {
StockAvailable::setQuantity((int)$product->id, 0, (int)$product->quantity, (int)$this->context->shop->id);
}
不过,我总是建议检查产品是否在那家商店。
重要的是要检查
Context::getContext()->employee
不为空,否则输入:
$psContext = Context::getContext();
if (!$psContext->employee) {
$psContext->employee = new Employee(PS_DEFAULT_EMPLOYEE);
}