1

i want to get products ids in Order by using order id,

i tried few methdods for it but none of them seems working

$objectManager =  \Magento\Framework\App\ObjectManager::getInstance();
$orderDatamodel = $objectManager->get('Magento\Sales\Model\Order')->getCollection();
foreach($orderDatamodel as $orderDatamodel1){
print_r($orderDatamodel1->getData());

}

can you tell what i am missing or how to get it

3
  • where is your order_id in code ?
    – Pawan
    Commented Oct 14, 2018 at 2:57
  • order_id is value like 00000002 Commented Oct 14, 2018 at 3:02
  • Please see my answer
    – Pawan
    Commented Oct 14, 2018 at 3:02

1 Answer 1

0

You can get Product Id by:

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

    foreach ($orderItems as $item) {
        echo $item->getId();echo $item->getProductId();

     }

Answer Source

4
  • getId -> is it product id ? as it seems something else Commented Oct 14, 2018 at 4:15
  • yes, its product id.
    – Pawan
    Commented Oct 14, 2018 at 4:24
  • i just checked it should be getProductId for product id Commented Oct 14, 2018 at 4:26
  • You are right, edit accepted as well :)
    – Pawan
    Commented Oct 14, 2018 at 4:30

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.