1

I want to get all the ordered items by order id. But if configurable product then I want to get only parent item id not it's child product.

For this I am using following code:

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$orderId = $this->getOrderId();
$order = $objectManager->create('Magento\Sales\Model\Order')->loadByIncrementId($orderId);
$orderItems = $order->getAllItems();`

So, How can I skip child products of configurable products?

  • Please do not use the object manager – Alex Sep 25 '18 at 12:56
-1
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$orderId = $this->getOrderId();
$order = $objectManager->create('Magento\Sales\Model\Order')->loadByIncrementId($orderId);
$orderItems = $order->getAllItems();
foreach($orderItems as $order){ 
    if($order->getProductType() == 'simple'){
        continue;
    }
}

You can skip using above condition.

  • Please do not not use the objectmanager – Alex Sep 25 '18 at 12:55

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.