I'm working with Magento 1.9, basically what I need to do is to send a request to an external API with information from the invoice (such as item id, price etc) once the invoice is created.
Do you have some ideas for this? Thanks
I think the correct way is to:
Magento supports out-of-the-box work with Google Analytics and on success checkout it basically is doing the same thing to track orders, although instead of calling an external API it just renders special tags with order which are processed on the client side. You could have a look at that module in app/core/Mage/GoogleAnalytics.
You could do this through custom module observer. Write your custom module step by step like this.
/app/etc/modules/Custom_Orderinfo.xml
<?xml version="1.0"?>
<config>
<modules>
<Custom_Orderinfo>
<active>true</active>
<codePool>local</codePool>
</Custom_Orderinfo>
</modules>
</config>
app/code/local/Custom/Orderinfo/etc/config.xml
<?xml version="1.0"?>
<config>
<modules>
<Custom_Orderinfo>
<version>0.1.0</version>
</Custom_Orderinfo>
</modules>
<frontend>
<events>
<checkout_onepage_controller_success_action>
<observers>
<your_sales_order_observer>
<type>singleton</type>
<class>orderinfo/observer</class>
<method>sendOrderInfo</method>
</your_sales_order_observer>
</observers>
</checkout_onepage_controller_success_action>
</events>
</frontend>
<global>
<models>
<orderinfo>
<class>Custom_Orderinfo_Model</class>
</orderinfo>
</models>
<resources>
<orderinfo_setup>
<setup>
<module>Custom_Orderinfo</module>
</setup>
</orderinfo_setup>
</resources>
<helpers>
<orderinfo>
<class>Custom_Orderinfo_Helper</class>
</orderinfo>
</helpers>
</global>
</config>
app/code/local/Custom/Orderinfo/Model/Observer.php
<?php
class Custom_Orderinfo_Model_Observer
{
public function sendOrderInfo($observer)
{
$event = $observer->getEvent();
$orderIds = $event->getOrderIds();
foreach($orderIds as $orderId)
{
$order = Mage::getModel('sales/order')->load($orderId);
$items=$order->getAllItems();
Mage::log($orderId,null,"order_success.log");
/**
* do whatever you want to do here
*/
}
}
}
app/code/local/Custom/Orderinfo/Helper/Data.php
<?php
class Custom_Orderinfo_Helper_Data extends Mage_Core_Helper_Abstract
{
}
Best of luck !
</div>