0

How to get sold product quantity in Orderplaced observer , Magento 2 ?

1
  • Can you explain in more detail exactly what & where u need sold product detial?
    – Bhavik
    Commented Feb 23, 2017 at 9:28

1 Answer 1

2

You need to create custom module add events.xml file at

app/code/Vendor/Modulename/etc/frontend/events.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
    <event name="checkout_onepage_controller_success_action">
        <observer name="mycustom_controller_success_action" instance="Vendor\Modulename\Observer\AfterPlaceOrder"  />
    </event>
</config>

Add observer at app/code/Vendor/Modulename/Observer/AfterPlaceOrder.php add below code to it

<?php

namespace Vendor\Modulename\Observer;

use Magento\Framework\Event\ObserverInterface;


class AfterPlaceOrder implements ObserverInterface
{

    public function execute(\Magento\Framework\Event\Observer $observer)
    {
        $orderId = $observer->getEvent()->getOrderIds();
        $order = $this->order->load($orderId);
        $itemCollection = $order->getItemsCollection();
        foreach($itemCollection as $item){
            $item->getQtyOrdered(); //item ordered qty
        }
    }

}
0

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.