Skip to main content
replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link

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

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

Source Link
fja3omega
  • 265
  • 3
  • 19

How to set products in stock after import

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"?>
<config>
    <modules>
        <Myweb_Stockin>
            <active>true</active>
            <codePool>local</codePool>
        </Myweb_Stockin>
    </modules>
</config>

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

<?xml version="1.0"?>
<config>
    <modules>
        <Myweb_Stockin>
            <version>0.0.1</version>
        </Myweb_Stockin>
    </modules>
    <adminhtml>
        <models>
            <mywebstockin>
                <class>Stockin_Model</class>
            </mywebstockin>
        </models>
        <events>
            <catalog_product_import_finish_before>
                <observers>
                    <stockin>
                        <type>model</type>
                        <class>Myweb_Stockin_Model_Observer</class>
                        <method>product_save_after</method>
                    </stockin>
                </observers>
            </catalog_product_import_finish_before>
        </events>
    </adminhtml>
</config>

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

<?php
    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);
            }
            $collection->save();
        }
    }
?>

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.