Magento – How to get Order details in the model of custom module

magento-1.9sales-order

Im creating a module to send the order details to another server's database when a order is placed in my magento server. Im using event to point to the model class but Im not able to get the order details like product name, quantity, price etc which are all needed to write in the other database. How can I make my model to get the values and write it to the database?

This is the config.xml file Im using

       <events>
            <sales_order_invoice_pay>
                <observers>
                    <sendorder>
                        <type>singleton</type>
                        <class>xxxx_SendOrder_Model_Observer</class>
                        <method>salesOrderInvoicePay</method>
                    </sendorder>
                </observers>
            </sales_order_invoice_pay>
        </events>

and this is the code Im using to get the order details

        $event = $observer->getEvent();
        $invoice=$event->getInvoice();
        $order =$invoice->getOrder();   
        $orderno=$order->getIncrementId();

I need to get the details of the order placed by customer and then push those details to another server's dd

Best Answer

If you have the order object you can get the order items like this:

foreach ($order->getAllItems() as $item) { //or $order->getAllVisibleItems()

   $price = $item->getPrice();
   $name = $item->getName();
   $qty = $item->getOrderedQty();
   ...
}
Related Topic