1

I want to get all order items by product_id not by order_id. So Please read carefully and give me a solution. Thanks in Advance.

3
  • where you want all order, i mean for what purpose?
    – Hiren
    Jul 5, 2019 at 6:33
  • Ok, let me explain you. If I did many orders such in one order there are 2 items means products then in other order other products. So I need to get all ordered product list by separate order. because I need to check which options were selected by buyer in separate orders. Jul 5, 2019 at 6:38
  • i have posted the answer as per your explanation.
    – Hiren
    Jul 5, 2019 at 6:49

1 Answer 1

1

Try below code with changes according to your needs, and do not use object manager in original implementation.

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$orderItemCollection = $objectManager->create('\Magento\Sales\Model\ResourceModel\Order\Item\Collection');
$orderItemCollection->addFieldToFilter('order_id', ORDER_ID);
$orderItemCollection->addFieldToFilter('product_id', PRODUCT_ID);

foreach ($orderItemCollection as $item) 
{
    $options = $item->getProductOptions();
}

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.