[英]Prestashop - PHP - update combination quantity raises error
我正在嘗試創建一個 PHP 腳本來更新PrestaShop 1.6.1.11中組合的數量
我想我可以通過他們的代碼得到組合:
$product = new Product("COMB CODE");
$product->quantity = 5; // your quantity
$product->save();
但是 PHP 提出:
PHP Deprecated: array_key_exists(): Using array_key_exists() on objects is deprecated. Use isset() or property_exists() instead in /home/w.sk/web/Adapter/Adapter_EntityMapper.php on line 84
PHP Warning: count(): Parameter must be an array or an object that implements Countable in /home/w.sk/web/classes/ObjectModel.php on line 478
PHP Fatal error: Uncaught Out of range value for column 'id_product' at row 1<br /><br /><pre>INSERT INTO `ps_product` (`id_shop_default`, `id_manufacturer`, `id_supplier`, `reference`, `supplier_reference`, `location`, `width`, `height`, `depth`, `weight`, `quantity_discount`, `ean13`, `upc`, `cache_is_pack`, `cache_has_attachments`, `is_virtual`, `id_category_default`, `id_tax_rules_group`, `on_sale`, `online_only`, `ecotax`, `minimal_quantity`, `price`, `wholesale_price`, `unity`, `unit_price_ratio`, `additional_shipping_cost`, `customizable`, `text_fields`, `uploadable_files`, `active`, `redirect_type`, `id_product_redirected`, `available_for_order`, `available_date`, `condition`, `show_price`, `indexed`, `visibility`, `cache_default_attribute`, `advanced_stock_management`, `date_add`, `date_upd`, `pack_stock_type`) VALUES ('1', '0', '0', '', '', '', '0', '0', '0', '0', '0', '', '', '0', '0', '0', '0', '1', '0', '0', '0', '1', '0', '0', '', '0', '0', '0', '0', '0', '1', '', '0', '1', '0000-00-00', 'new', '1', '0', 'both', in /home/w.sk/web/classes/db/Db.php on line 791
您知道如何獲取現有組合並更新其數量嗎?
您可以使用此代碼更新組合數量:
$id_product = your product id
$id_product_attribute = your combination id
$quantity = your quantity
StockAvailable::setQuantity($id_product,$id_product_attribute, $quantity);
要添加到 Danoosh 的答案,如果您有產品的 ID,您可以執行以下操作:
$product = new Product($id_product);
$combinations = $product->getAttributeCombinations($id_lang, $groupByIdAttributeGroup); // 1, true for example
foreach ($combinations as $combination)
{
$idAttribute = $combination['id_product_attribute']
// product, id attribute (if simple product set to 0), quantity
StockAvailable::setQuantity($product->id, $idAttribute, $quantity); // There is no need to save/update the product/combination
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.