skip to Main Content

I need the ORDER ITEM ID in order to consume the service RefundInvoice at Magento 2 to create a credit memo with a refund (http://devdocs.magento.com/guides/v2.1/mrg/ce/Sales/services.html).

Order item ID is I definitely something else than the order ID, since I tried that one.

So anyone an idea how I can retrieve the order item id?

2

Answers


  1. //Try with below code.

    $orderId = 1234; //put your order id.
    $order = $this->_objectManager->create('MagentoSalesModelOrder')->load($orderId);
    $orderItems = $order->getAllItems();
    foreach($orderItems as $item)
    {
      echo "Order Item ID :".$item->getItemId(); //
    }
    
    Login or Signup to reply.
  2. The item_id is actually the entity_id for sales_order_item. It is NULL until the record is saved to the database, upon when it is populated with the row ID. In order to access it and find its value, the salesOrderItem object must call ->save() first. If you are looking for the actual “item id” (the product), use product_id. If you need to record the record ID, then call $object->save(), and then you can read $object->getItemId()

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search