3

I'm using an event observer which fires when user clicks on the 'Place Order' button in checkout flow. I want to capture the product details which are in the cart. Actually this moment order object has already created. If I can access order object it is more than enough.

I have tried the followings, but no luck.

I'm using the event checkout_submit_all_after. And that event executes the following function in the observer.

public function galileo_booking_request(Varien_Event_Observer $observer)
    {
       // $product = $observer->getData('product');// returns null object
      //   $order = $observer->getEvent()->getOrder();// returns null object
           $request = $observer->getEvent()->getRequest()->getParams();// returns null object
           Mage::log($request['product'],null,'eventoberver.log',true);
    }

2 Answers 2

6

The observer receives as a parameter the order (or orders for multishipping) and the quote. Here is how you can get them

public function galileo_booking_request(Varien_Event_Observer $observer) {
    $order = $observer->getEvent()->getOrder(); //I don't know why this returns null for you. It shouldn't
    //or for multishipping
    //$order = $observer->getEvent()->getOrders(); //you should get an array of orders
    //for the quote
    $quote = $observer->getEvent()->getQuote();
}

If it doesn't work for you for the order, try with the quote. After getting the quote object your can loop through the items.

foreach ($quote->getAllItems() as $item) {
    $product = $item->getProduct();//if you need it
    //your magic here.
}
1
  • Thank you so much for the quick response. I also didn't know why the order object returned null. But now it getting values (I don't know why either). Quote object is also working as you mentioned. Thank you again and +1
    – Sukeshini
    Sep 24, 2014 at 9:28
5

When using one-page checkout your should be able to get the order, quote and recurring profiles.

Mage::dispatchEvent(
    'checkout_submit_all_after',
    array('order' => $order, 'quote' => $this->getQuote(), 'recurring_profiles' => $profiles)
);

In your observer you can use the $observer->getEvent()->getOrder() and $observer->getEvent()->getQuote() to get the information you need.

3
  • Thank you for the detailed answer. I didn't check the core files until you pointed it out. After all it's knowledge :) and +1 for the response
    – Sukeshini
    Sep 24, 2014 at 9:30
  • @Sukeshini glad it helped, I normally always start in the core files to see how things are done. Sep 24, 2014 at 9:32
  • Thanks again. I think I have lot more to learn from this community :) I'll keep in mind your way of resolving errors. Really appreciate that concept.
    – Sukeshini
    Sep 24, 2014 at 9:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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