cancel
Showing results for 
Search instead for 
Did you mean: 

Reindex stock status after placing order

Reindex stock status after placing order

Hello,

 

i need to write a trigger which will reindex stock status after order is placed.
I've wrote an observer an it executes correctly after the order is placed, but...there is one 'but' :-)
If there is only one item (product) on stock the order is placed correctly, but index is not processing - after the order is placed index has status 'Reindex required'.

 

config.xml

    <global>
        <models>
            <imports>
                <class>Xxx_AutoStockStatus</class>
            </imports>
        </models>
        <events>
            <sales_order_place_after>
                <observers>
                    <Xxx_AutoStockStatus_stock_observer>
                        <type>singleton</type>
                        <class>Xxx_AutoStockStatus_Model_Observer</class>
                        <method>runindex</method>
                    </Xxx_AutoStockStatus_stock_observer>
                </observers>
            </sales_order_place_after>
        </events>
    </global>
Observer.php


class Xxx_AutoStockStatus_Model_Observer extends Varien_Event_Observer
{

    public function runindex($observer)
    {

        Mage::log('sales_order_place_after - testing 111');
        $process=Mage::getSingleton('index/indexer')->getProcessByCode('cataloginventory_stock');
        $process->reindexEverything();
        Mage::log('sales_order_place_after - testing 222');
    }
}

Any help would be appreciated. Thanks in advanced.

3 REPLIES 3

Re: Reindex stock status after placing order

@agu84 Have you  checked log report testing 222 ? Do it seems ok?  Event observer and reindex code seems okay.

-
Magento Programmer | Was my answer helpful? You can accept it as a solution.

Re: Reindex stock status after placing order

@GauravMehta04 yes, i've checked log and both 'testing 111' and 'testing 222' are there, but unfortunately stock index status stays as 'Reindex required' Smiley Frustrated

The situation appears only when i order the last product from stock. Stock status should be updated, so the next person who wants to order the same product sees right away that it's currently not available.

Re: Reindex stock status after placing order

I had the same problem. Fix it by replacing event to "checkout_submit_all_after"