How to get order item collection by item id magento 2?

You can get item collection data by Item id in magento 2 by using below code snippet, Create Block file,

Call function from Template file,

 

How to create order programmatically in magento 2?

Magento 2 You can create order programmatically by simple coding.

You need to Create custom quote for order and based on that you can convert the quote to Order in Magento 2 by a simple code.

Create order information from the template file to helper file.

In above order info, We take customer basic details and Items info.
We have taken a simple and configurable product item. For configurable product, We need to pass super_attribute array value. For Test purpose, I have taken Magento Sample data configurable and simple product id.

For Configurable, 93 is Color attribute id where 52 is Gray option id.
142 is size attribute id where 167 is for XS size option id, you need to pass the dynamic value for a configurable product.

Create helper file,

Let’s say Data.php file location at, app/code/Rbj/Training/Helper/Data.php

You got a result as array for success order place,¬†Array ( [success] => ‘OrderId’ )

How to get order data by order increment id programmatically Magento 2?

You can get the Order data by order increment id in Magento 2.

Using Magento\Sales\Api\OrderRepositoryInterface interface, you need to use getList() function to fetch order data by order increment id.

Use below code snippet to fetch order data by order increment id in Magento 2

Call function with order Increment id

You got the Order object for the var_dump in the above output.