문제

How I can change stock availability ie in stock and out of stock of product programmatically using product ID?

도움이 되었습니까?

해결책

The following code should work for you

$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 ~와 함께 속성
제휴하지 않습니다 magento.stackexchange
scroll top