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?