0

I can catch the event sales_order_place_after with no problems, but now I have a problem because I can't get Mage::log(var_export($observer->getEvent()->getOrder())); to work because the output is too big. I need sku, quantity and price for each of the items that are in that particular order. How can I do this? I guess if I knew which class ->getOrder() returns this would not be a problem, but I don't. Which class does this method return?

3 Answers 3

2

You can use

$order = $observer -> getEvent() -> getOrder();
$items = $order->getAllVisibleItems();
foreach($items as $item){
    $sku = $item->getSku();
    $price = $item->getPrice();
     $quantity = $item->getQtyOrdered();
}
3
  • In order to fully answer the question, can you also write how to get price and quantity, and maybe configurable option, if that item is from a configurable product? Dec 2, 2016 at 15:11
  • 1
    Please update your code so that i can understand your requirement.
    – rajat kara
    Dec 5, 2016 at 8:16
  • You already answered. Dec 5, 2016 at 10:09
0
$order = $observer->getEvent()->getOrder();
$items = $order->getAllVisibleItems();
foreach($items as $item){
    echo $item->getSku();
    echo $item->getPrice();
    echo $item->getQtyOrdered();
}
1
0

You can use the following code:

$order = $observer->getEvent()->getOrder();
$items = $order->getAllItems();
foreach($items as $item){
    $sku = $item->getSku();
    $qty = $item->getQtyOrdered();
    $price = $item->getPrice();
}

Your Answer

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

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