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

前端 未结 5 1590
刺人心
刺人心 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:25

    Just create cron job with that code snippet:

    public function setBackInStock()
    {
        $collection = Mage::getResourceModel('cataloginventory/stock_item_collection');
        $outQty = Mage::getStoreConfig('cataloginventory/item/options_min_qty');
        $collection->addFieldToFilter('qty', array('gt' => $outQty));
        $collection->addFieldToFilter('is_in_stock', 0);
    
        foreach($collection as $item) {
            $item->setData('is_in_stock', 1);
        }
        $collection->save();
    }
    

    Small note, you can set cron job for every minute, because if there are no results job won't be consuming time/resources

提交回复
热议问题