I want to create an event to export inventory when status of order is changed to completed.
I created module to overwrite Mage_Sales_Model_Order and tried to generated an event
(sales_order_status_change).
When from magento admin panel I view and order and change order state to complete, it works mean print something in my extended class, it shows, its fine. Here I generate event.(Problem could be here, may be event not generated)
I created an other module to observe this event. But I am unable to get into my Observer class. I cannot print anything and exit, means code does not run.
But in the same observer class if change config and observe some other event (From Magento built in events) it works. Like I tested catalog_controller_product_view
Here Is my Event Generator Module.
app/etc/modules/Gol_Eventgenerator.xml
<?xml version="1.0"?>
<config>
<modules>
<Gol_Eventgenerator>
<active>true</active>
<codePool>local</codePool>
</Gol_Eventgenerator>
</modules>
</config>
app\code\local\Gol\Eventgenerator\etc\config.xml
<?xml version="1.0" encoding="utf-8"?>
<config>
<modules>
<Gol_Eventgenerator>
<version>0.1.0</version>
</Gol_Eventgenerator>
</modules>
<global>
<models>
<sales>
<rewrite>
<order>Gol_Eventgenerator_Model_Order</order>
</rewrite>
</sales>
</models>
</global>
</config>
app\code\local\Gol\Eventgenerator\Model\Order.php
<?php
class Gol_Eventgenerator_Model_Order extends Mage_Sales_Model_Order
{
public function setState($state, $status = false, $comment = '', $isCustomerNotified = null)
{
//if I print something here and exit, it does will.
Mage::dispatchEvent('sales_order_status_change', array('order' => $this, 'state' => $state, 'status' => $status, 'comment' => $comment, 'isCustomerNotified' => $isCustomerNotified));
return parent::setState($state, $status, $comment, $isCustomerNotified);
}
}
Here are the details of observer module
app/etc/modules/Gol_Inventory.xml
<?xml version="1.0"?>
<config>
<modules>
<Gol_Inventory>
<active>true</active>
<codePool>local</codePool>
</Gol_Inventory>
</modules>
</config>
app\code\local\Gol\Inventory\etc\config.xml
<?xml version="1.0" encoding="utf-8"?>
<config>
<modules>
<Gol_Inventory>
<version>0.1.0</version>
</Gol_Inventory>
</modules>
<global>
<events>
<sales_order_status_change>
<observers>
<Gol_Inventory_observer>
<type>singleton</type>
<class>Gol_Inventory_Model_Observer</class>
<method>exportEnventory</method>
</Gol_Inventory_observer>
</observers>
</sales_order_status_change>
</events>
</global>
</config>
app\code\local\Gol\Inventory\Model\Observer.php
<?php
class Gol_Inventory_Model_Observer
{
public function exportEnventory($observer)
{
echo "Inside exportEvnentory method";
exit;
//$order = $observer->getEvent()->getOrder();
//$state = $observer->getEvent()->getState();
//$status = $observer->getEvent()->getStatus();
}
}
Is there any difference in the way for generating events for frontend and admin??? except
, in config file.
Sorry in advance if I have not followed some very common thing. New to magento.
I have tried to follow .
sales_order_save_before
and check the new status with the previous one – OSdave