Magento: Auto-changing the “Stock Availability” from “Out of Stock” to “In Stock” (& vice-versa) on Quantity Change

前端 未结 5 1594
刺人心
刺人心 2020-12-29 15:46

So I’ve been looking for a way to change the Stock Availability back to In Stock when the quantity field is greater than 0. The system already automatically changes the Stoc

5条回答
  •  盖世英雄少女心
    2020-12-29 16:27

    I believe you can use Magento event catalog_product_save_after. Create an observer method that does the following on event catalog_product_save_after.

    public function catalog_product_save_after($observer) {
        $product = $observer->getProduct();
        $stockData = $product->getStockData();
    
        if ( $product && $stockData['qty'] ) {
            $stock = Mage::getModel('cataloginventory/stock_item')->loadByProduct($product->getEntityId()); // Load the stock for this product
            $stock->setData('is_in_stock', 1); // Set the Product to InStock                               
            $stock->save(); // Save
        }
    }
    

提交回复
热议问题