5

I am creating an extension on sales_order_place_after event observer & I want to get the Order & Customer Details with the following code, but I am not sure how to do this correctly.

config.xml

    <?xml version="1.0"?>
    <config>
        <modules>
            <Avyam_Sms>
                <version>0.0.1</version>
            </Avyam_Sms>
        </modules>
        <global>
            <models>
                <avyam_sms>
                    <class>Avyam_Sms_Model</class>
                </avyam_sms>
            </models>
        </global>
        <global>
            <events>
                <sales_order_place_after><!-- observe the event -->
                    <observers>
                        <avyam_sms>
                            <class>avyam_sms/observer</class>
                            <method>newFunction</method>
                        </avyam_sms>
                    </observers>
                </sales_order_place_after>
            </events>
        </global>
    </config>

Observer.php

    <?php 
    class Avyam_Sms_Model_Observer {
        public function newFunction($observer) {
            Mage::log('The Product has been save', null, 'mylogfile.log');    
        } 
    }?>

Please assist me, thanks in advance.

1
  • don't put to global tags in ur config.xml try to put <events></events> under first <global> tag after </model></model> and try Feb 3, 2015 at 13:17

1 Answer 1

17
$order = $observer->getEvent()->getOrder();
echo "<pre>"; print_r($order->getData());   // order details

$customer_id = $order->getCustomerId();
$customerData = Mage::getModel('customer/customer')->load($customer_id); // then load customer by customer id
echo "<pre>"; print_r($customerData->getData());    // ; add after echo "<pre>";  

In The $order->getData() you will get all order related data and in the $customerData->getData() you will get Customer data

add above code in your observer

3
  • thanks for help,how to print this info in log file, i am using this code Mage::log(print_r($order->getData()), null, 'mylogfile.log'); but not getting details in log file
    – Dinesh
    Feb 2, 2015 at 8:49
  • Mage::log($order->getData(),null,'mylog.log'); Feb 2, 2015 at 9:13
  • i used this,but it not working checkout page not redirect to success page show 500 internal error in browser console & nothing is printed in mylog.log file
    – Dinesh
    Feb 3, 2015 at 6:22

Not the answer you're looking for? Browse other questions tagged or ask your own question.