Cannot update Stock Item Quantity for a Product in Magento 1.6.2

前端 未结 4 403
感动是毒
感动是毒 2020-12-16 06:25

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 remai

4条回答
  •  悲&欢浪女
    2020-12-16 07:04

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

提交回复
热议问题