0

I want to display all the shipping details on system.log when user clicks Place Order button. I used event handler to display Customer Id and Customer name, but I am unable to display other details like Product name, Order Id, Address, Price, Quantity etc. How can I display all the shipping details by using event handler? Thanks..

The given below is my xml code:

<global>
       <models>
           <User_Tracker>
               <class>User_Tracker_Model</class>
           </User_Tracker>
       </models>
       <events>
           <sales_order_place_after>
               <observers>
                   <User_Tracker>
                       <type>singleton</type>
                       <class>User_Tracker/observer</class>
                       <method>customOrderSave</method>
                   </User_Tracker>
               </observers>
           </sales_order_place_after>
       </events>
   </global>

and the given below is my observer code:

class User_Tracker_Model_Observer extends Mage_Core_Model_Abstract
 {
    public function _construct()
    {
        parent::_construct();
        $this->_init('tracker/observer');
    }
    public function customOrderSave($observer)
     {
      $order = $observer->getEvent()->getOrder();
      $customer_name = $order->getCustomerName();
      $customer_id = $order->getCustomerId();
      Mage::log($customer_id);
      Mage::log($customer_name);
    }
}
2

You can get all details from the order id.

public function customOrderSave($observer){
   $order = $observer->getEvent()->getOrder();
   $ordered_items = $order->getAllItems();

   $customer_id = $order->getCustomerId();          
   $customer_name = $order->getCustomerName();
   $customer_email = $order->getCustomerEmail();

   $shippingAddress = Mage::getModel('sales/order_address')->load($order->getShippingAddress()->getId());

   $company= $shippingAddress->getCompany(); 
   $street = $shippingAddress->getStreet();
   $phone  = $shippingAddress->getTelephone();
   $city   = $shippingAddress->getCity();
   $zip    = $shippingAddress->getPostcode();
   $region = $shippingAddress->getRegion();

   foreach ($ordered_items as $item) {

    $product_id  = $item->getProductId();
    $orderedQty = $item->getQtyOrdered();
    $product_name  =$item->getName(); //to get the name
   }
}//END FUNCTION

Like this you can get all details related to ur order and Create your own log to see this value like below

Mage::log("Your Variables",true,'Yourownlog.log');
  • 1
    glad to help :) – Mujahidh Mar 9 '17 at 11:53
  • @Muajadh Can you help me more please. I want to access Product Name and Total Price as well. How can I get Product Name and Total Price? – Birju Mar 10 '17 at 6:18
  • 1
    upated the answer for getting the product name, Google for to get the order amount – Mujahidh Mar 10 '17 at 6:30
  • @Muajadh and for total price? What should I do? I used getPrice(), but it outputs for only 1 quantity, if I choose 3 quantities, it gives price of only a single quantity. – Birju Mar 10 '17 at 6:34
  • I mean I want to get the shipping amount. – Birju Mar 10 '17 at 6:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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