Magento2
quote id

In Magento 2 you can create order and quote programmatically. You can create this function in helper, controller and in Model. It depands upon you where you want to create. In my example, i am creating this in a controller. See the Below example:

1) First you need to create an array of customer billing address and shipping address.

you can get address details from customer address.

$OrderDetails= [
    'currency_id' => 'USD',
    'email' => 'demo@gmail.com',
    'shipping_address' => [
            'customer_address_id'=>XXXX,
            'firstname'=> 'Test',
            'lastname'=>'Customer',
            'company'=>'Test Pvt. Ltd.',
            'street'=>'601,test street',
            'city'=>'srdr',
            'country_id'=>'US',
            'region'=>'CA',
            'region_id'=>5,
            'postcode'=>123456,
            'telephone'=>1234567890,
            'fax'=>XXXXXX,
            'same_as_billing'=>1,
            'save_in_address_book'=>1],
    'billing_address' => [
            'customer_address_id'=>XXXX,
            'firstname'=> 'Test',
            'lastname'=>'Customer',
            'company'=>'Test Pvt. Ltd.',
            'street'=>'601,test street',
            'city'=>'srdr',
            'country_id'=>'US',
            'region'=>'CA',
            'region_id'=>5,
            'postcode'=>123456,
            'telephone'=>1234567890,
            'fax'=>XXXXXX,
            'same_as_billing'=>0,
            'save_in_address_book'=>1],
    'items' => [
        ['product_id' => '1', 'qty' => 1],
    ];

2) Now create a controller and paste below code in your controller. And change module namespace according to your module.


Run php bin/magento setup:di:compile when you add any dependency injection.Because without php bin/magento setup:di:compile it throws error in code.

Hope this will helps you!

Leave a Reply

Your email address will not be published. Required fields are marked *