0

below is code to get product id from order id, I did order configurable product but in below case it show 2 product ids where as I did purchased only one product (configurable products).

output of below code is two id one is main products and other configurable made from that one, I want to verify get instead one id

$order = $objectManager->create('Magento\Sales\Model\Order')->loadByIncrementId($_order->getRealOrderId());
                        $orderItems = $order->getAllItems();

                        foreach ($orderItems as $item) {
                            echo $item->getId();
                            echo "<br>";
                            echo "xxxx".$item->getProductId()."-->";

                         }
2

You have to change function . First know about function.

This is how the different methods to get items from an order work:

getItems(): returns array of items from loaded order item collection

getAllItems(): returns array of all items that are not marked as deleted

getAllVisibleItems(): returns array of all items that are not marked as deleted and do not have a parent item

$order = $objectManager->create('Magento\Sales\Model\Order')->loadByIncrementId($_order->getRealOrderId());
                        $orderItems = $order->getAllVisibleItems();

                        foreach ($orderItems as $item) {
                            echo $item->getId();
                            echo "<br>";
                            echo "xxxx".$item->getProductId()."-->";

                         }

Click here to show order items

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.