Sanjoy Roy

[MCM, MCP, SCJP] – Senior PHP Programmer

Magento observer sales order



/**
 * Register an event trigger after the order has been saved
 *
 * Is triggered by sales_order_save_after event 
 *
 */
public function hookSalesOrderSaveAfter ($observer)
{
    $order = $observer->getEvent()->getOrder(); // returns the Mage_Sales_Model_Order Object
    Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID); // Magento can only save attributes in admin mode
    $order->setVendor('LoremIpsum');
    $order->getResource()->saveAttribute($order, "vendor");
    $order->setCallToAction('ANC');
    $order->getResource()->saveAttribute($order, "call_to_action");
    $order->setKeycode('0x7474');
    $order->getResource()->saveAttribute($order, "keycode");
    return $this;
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: