久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

無法在 Magento 1.6.2 中更新產品的庫存項目數量

Cannot update Stock Item Quantity for a Product in Magento 1.6.2(無法在 Magento 1.6.2 中更新產品的庫存項目數量)
本文介紹了無法在 Magento 1.6.2 中更新產品的庫存項目數量的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我正在嘗試從腳本中更新 Magento 中產品的庫存數量.

I am trying to update the stock quantities of products in Magento from within a script.

我加載了產品,設置了庫存數量,然后保存 - 但數量保持不變.

I load the product, set the stock quantity, and save - but the quantity remains unchanged.

// get stock data
$stockData = $product->getStockItem();
printf(PHP_EOL.'Stock: qty=%d, instock=%s, man_stock=%s, use_cfg_man_stock=%s'.PHP_EOL,
    $stockData->getData('qty'),
    $stockData->getData('is_in_stock'),
    $stockData->getData('manage_stock'),
    $stockData->getData('use_config_manage_stock')
);
// prints out qty=0, instock=, man_stock=, use_cfg_man_stock=


// $stockQty = 1
$product->stockItem->setData('qty', $stockQty);
$product->stockItem->setData('is_in_stock', $stockQty>0 ? 1 : 0);
$product->stockItem->setData('manage_stock', 1);
$product->stockItem->setData('use_config_manage_stock', 0);

$product->save();                           
$product->load();                           
$stockData = $product->getStockItem();
printf('New Stock: qty=%d, instock=%s, man_stock=%s, use_cfg_man_stock=%s'.PHP_EOL,
    $stockData->getData('qty'),
    $stockData->getData('is_in_stock'),
    $stockData->getData('manage_stock'),
    $stockData->getData('use_config_manage_stock')
);
// prints out qty=0, instock=, man_stock=, use_cfg_man_stock=

我哪里出錯了?

推薦答案

您所缺少的只是保存 $stockItem.您不需要創建新的 stock_item,也不需要保存產品.

All you were missing is to save the $stockItem. You shouldn't need to create a new stock_item nor should you have to save the product.

if (!($stockItem = $product->getStockItem())) {
    $stockItem = Mage::getModel('cataloginventory/stock_item');
    $stockItem->assignProduct($product)
              ->setData('stock_id', 1)
              ->setData('store_id', 1);
}
$stockItem->setData('qty', $stockQty)
          ->setData('is_in_stock', $stockQty > 0 ? 1 : 0)
          ->setData('manage_stock', 1)
          ->setData('use_config_manage_stock', 0)
          ->save();

這篇關于無法在 Magento 1.6.2 中更新產品的庫存項目數量的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Joining 2 tables in SELECT(MYSQL/PHP)(在 SELECT(MYSQL/PHP) 中加入 2 個表)
How to make lt;option selected=quot;selectedquot;gt; set by MySQL and PHP?(如何使lt;option selected=“selectedgt;由 MySQL 和 PHP 設置?)
Auto populate a select box using an array in PHP(使用 PHP 中的數組自動填充選擇框)
PHP SQL SELECT where like search item with multiple words(PHP SQL SELECT where like search item with multiple words)
json_encode produce JSON_ERROR_UTF8 from MSSQL-SELECT(json_encode 從 MSSQL-SELECT 產生 JSON_ERROR_UTF8)
MySQL ORDER BY rand(), name ASC(MySQL ORDER BY rand(),名稱 ASC)
主站蜘蛛池模板: 欧美一区二区在线观看 | 国产精品视频免费观看 | 黄色在线观看 | 免费一区在线观看 | 黄色三级毛片 | 日韩一二区在线观看 | 亚洲精品9999久久久久 | 欧美日韩在线成人 | 在线欧美一区二区 | 国产一区二区久久久 | 18性欧美| 国产综合av | 国产成人免费一区二区60岁 | 免费视频成人国产精品网站 | 九九视频在线观看视频6 | 91国自产| 欧美日日| 亚洲精品一区二区三区 | 国产黄色av网站 | 久久成人免费 | 久久99这里只有精品 | 激情a| 国产在线精品一区二区三区 | 黄免费观看视频 | 亚洲网站在线播放 | 国产99久久久久 | 日韩成人在线观看 | 成人3d动漫一区二区三区91 | 精品无码三级在线观看视频 | 精品久久国产老人久久综合 | 熟女毛片 | 亚洲一区av | 国产99久久精品一区二区永久免费 | 在线观看日本高清二区 | 久久久久国产 | 亚洲成人99| 婷婷久久综合 | 男女国产网站 | 妞干网福利视频 | 正在播放国产精品 | 国内精品久久久久 |