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.

  • where you want all order, i mean for what purpose? – user4536 Jul 5 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. – sarvesh Dineshkumar Patel Jul 5 at 6:38
  • i have posted the answer as per your explanation. – user4536 Jul 5 at 6:49
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, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.