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.

2 Answers 2

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
      [...]
    }
}
1
  • is there any advantage of using sales_order_invoice_save_after over sales_order_payment_pay?
    – Erfan
    Commented Aug 8, 2016 at 7:34
1

Listen for event sales_order_payment_pay.

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.