我如何更改股票可用性即 in stockout of stock 使用产品ID编程的产品?

有帮助吗?

解决方案

以下代码应该适合您

$stock_item = Mage::getModel('cataloginventory/stock_item')->loadByProduct($product_id);
if (!$stock_item->getId()) {
    $stock_item->setData('product_id', $product_id);
    $stock_item->setData('stock_id', 1); 
}

$stock_item->setData('is_in_stock', 1); // is 0 or 1
$stock_item->setData('manage_stock', 1); // should be 1 to make something out of stock

try {
    $stock_item->save();
} catch (Exception $e) {
    echo "{$e}";
}
许可以下: CC-BY-SA归因
scroll top