I managed to create a module to update the product set to in stock when an import is done.

The only problem I see now is that the cache is invalidated afterwards and I also need to update the cache after reindexing the site.

This is my code for the modules app/etc/modules/Myweb_Stockin.xml

<?xml version="1.0"?>

This is my code for the config app/code/local/Myweb/Stockin/etc/config.xml

<?xml version="1.0"?>

This is my code for the observer app/code/local/Myweb/Stockin/Model/Observer.php which is from this page: https://stackoverflow.com/questions/7168295/magento-auto-changing-the-stock-availability-from-out-of-stock-to-in-stock

    class Myweb_Stockin_Model_Observer {
        public function product_save_after($observer) {
            $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);

I need to know if there is something wrong with this code.

I am at a loss trying to find out where the invalidated cache is coming from.


If it's block cache, I believe product it comes directly from product save action. (page looks differnt for in-stock/out of stock product)

You can try refreshing cache after import.





| improve this answer | |
  • I will test this out. – fja3omega May 12 '17 at 7:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.