1

I have to save the stock of each product when an order is placed.

The custom module is Tbb_StockRegistrar. It creates a column called order_stock_message in sales_flat_order and sales_flat_order_grid tables. This is OK.

Then, the observer should save the value in those tables (Not working):

config.xml

<events>
    <sales_order_place_after>
        <observers>                  
            <checkout_submit_all_after_handler>
                <type>model</type>                                   
                <class>Tbb_StockRegistrar_Model_Observer</class>
                <method>save</method>       
            </checkout_submit_all_after_handler>
        </observers>
    </sales_order_place_after>
</events>

Observer.php

<?php

class Tbb_StockRegistrar_Model_Observer
{

    public function save($observer)
    {
        $order  = $observer->getEvent()->getOrder();
        $stocks = $this->saveComment($order);
        $this->saveOrderGridColumn($order, $stocks);
    }

    protected function saveComment($order)
    {
        # Save the stocks as an order comment (Working)
    }

    protected function saveOrderGridColumn($order, $stocks)
    {
        $stockMessage = ... // It populates the message to be saved

        $orderModel = Mage::getModel('sales/order')->load($order->getId());
        $orderModel->setOrderStockMessage($stockMessage);
        $orderModel->save();

    }

}

The method setOrderStockMessage is not saving anything. Why?

Plus, how can I store the same value in sales_flat_order_grid table on sales_order_place_after observer?

1 Answer 1

0

Need to change as per below code config.xml

<events>
    <sales_order_place_after>
        <observers>                  
            <Tbb_StockRegistrar_Model_Observer>
                <type>model</type>                                   
                <class>Tbb_StockRegistrar_Model_Observer</class>
                <method>save</method>       
            </Tbb_StockRegistrar_Model_Observer>
        </observers>
    </sales_order_place_after>
</events>
1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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