Question

I have below code.

namespace Custom\Module\Observer;

use Magento\Framework\Event\ObserverInterface;
use Magento\Framework\App\RequestInterface;

class TestObserver implements ObserverInterface {

    protected $_logger;

    public function __construct(\Psr\Log\LoggerInterface $logger) {
        $this->_logger = $logger;
    }

    public function execute(\Magento\Framework\Event\Observer $observer) {
        $order = $observer->getEvent()->getOrder();

         foreach ($order->getAllItems() as $item) {
            $this->_logger->info('Item ID: ' . $item->getProductId());
        }
        exit;

        return $this;
    }
}

How to get product type? What are the all options for getAllItems?

Was it helpful?

Solution

Simply use:

  $item->getProductType();
  $item->getProductOptions();
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top