Get orders collection between a date range in magento 2.

We just need to pass start date and end date to get collection between Specific time in Magento 2. We need to filter created_at field using addAttributeToFilter(). Create Block file.
By default created_at field in  sales_order table represent the time of order creation in Magento 2.

Call Function from template file,

You can get Order collection by date range by the above tricks.

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’ )