5

I am developing a custom module if user purchase a particular product I need to send information to a particular system. I am just searching for event where i can write my code.

Please help if someone already implemented such functionlity.

Pankaj Pareek
  • 3,556
  • 3
  • 23
  • 46

2 Answers2

9

The event you're looking for is sales_order_invoice_save_after, this is triggered when an invoice is made so you are sure the order is paid as well.

config.xml

<config>
   [...]
   <global> 
      [...]
      <events>
         <sales_order_invoice_save_after>
            <observers>
               <[module]_order_export>
                  <type>singleton</type>
                  <class>[Namespace]_[Module]_Model_Observer</class>
                  <method>orderExport</method>
               </[module]_order_export>
            </observers>
         </sales_order_invoice_save_after>     
      </events>
      [...]
   </global>
   [...]
</config>

Observer.php

class [Namespace]_[Module]_Model_Observer
{

   public function orderExport(Varien_Event_Observer $observer)
   {
      $_event = $observer->getEvent();
      $_invoice = $_event->getInvoice();
      $_order = $_invoice->getOrder();

      [...]
      // your code to handle the export
      [...]
    }
}
Sander Mangel
  • 37,528
  • 5
  • 80
  • 148
  • is there any advantage of using sales_order_invoice_save_after over sales_order_payment_pay? – Erfan Aug 08 '16 at 07:34
1

Listen for event sales_order_payment_pay.

shahalpk
  • 325
  • 1
  • 7
  • 20