Magento 2 Create order using Rest API

Magento 2 is robust, scalable and multi feature enable eCommerce platform. You can create Sales Order Using a third party software to Magento 2 backend.
Using below payload you can create sales order using any third party platform to Magento 2. you Just need to pass below payload in your request with PUT data. I have pass data like shipping method with flatrate shipping, Added Custom discount Shopping cart Rule and COD as a payment method in payload request.

Once Order Create using API,

Check Create Invoice Using Magento 2 REST API
Check Create Shipment Using Magento 2 REST API

 

We have taken reference for “Push It Messenger Bag” simple product in Magento 2 from Sample data.

Request: {YOUR_URL}/rest/V1/orders/create

Type: PUT

Body:

 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
{
   "entity" : {
         "base_currency_code" : "USD" ,
         "base_discount_amount" : - 4.5 ,
         "base_grand_total" : 45.5 ,
         "base_shipping_amount" : 5 ,
         "base_subtotal" : 45 ,
         "base_tax_amount" : 0 ,
         "customer_email" : "rakesh@rakeshjesadiya.com" ,
         "customer_firstname" : "rakesh" ,
         "customer_group_id" : 1 ,
         "customer_id" : 2 ,
         "customer_is_guest" : 0 ,
         "customer_lastname" : "jesadiya" ,
         "customer_note_notify" : 1 ,
         "discount_amount" : - 4.5 ,
         "email_sent" : 1 ,
         "coupon_code" : "Test1" ,
         "discount_description" : "Test1" ,
         "grand_total" : 45.5 ,
         "is_virtual" : 0 ,
         "order_currency_code" : "USD" ,
         "shipping_amount" : 5 ,
         "shipping_description" : "Flat Rate - Fixed" ,
         "state" : "new" ,
         "status" : "pending" ,
         "store_currency_code" : "USD" ,
         "store_id" : 1 ,
         "store_name" : "Main Website\nMain Website Store\n" ,
         "subtotal" : 45 ,
         "subtotal_incl_tax" : 45 ,
         "tax_amount" : 0 ,
         "total_item_count" : 1 ,
         "total_qty_ordered" : 1 ,
         "weight" : 1 ,
         "items" : [
         {
             "base_discount_amount" : 4.5 ,
             "base_original_price" : 45 ,
             "base_price" : 45 ,
             "base_price_incl_tax" : 45 ,
             "base_row_invoiced" : 0 ,
             "base_row_total" : 45 ,
             "base_tax_amount" : 0 ,
             "base_tax_invoiced" : 0 ,
             "discount_amount" : 4.5 ,
             "discount_percent" : 10 ,
             "free_shipping" : 0 ,
             "is_virtual" : 0 ,
             "name" : "Push It Messenger Bag" ,
             "original_price" : 45 ,
             "price" : 45 ,
             "price_incl_tax" : 45 ,
             "product_id" : 14 ,
             "product_type" : "simple" ,
             "qty_ordered" : 1 ,
             "row_total" : 45 ,
             "row_total_incl_tax" : 45 ,
             "sku" : "24-WB04" ,
             "store_id" : 1
         }
         ] ,
         "billing_address" : {
             "address_type" : "billing" ,
             "city" : "Ahmedabad" ,
             "company" : "Rbj" ,
             "country_id" : "US" ,
             "email" : "rakesh@rakeshjesadiya.com" ,
             "firstname" : "rakesh" ,
             "lastname" : "jesadiya" ,
             "postcode" : "30332" ,
             "region" : "Georgia" ,
             "region_code" : "GA" ,
             "region_id" : 19 ,
             "street" : [
                 "Street 1" ,
                 "Street 2"
             ] ,
             "telephone" : "123456"
         } ,
         "payment" : {
             "method" : "cashondelivery"
         } ,
         "extension_attributes" : {
             "shipping_assignments" : [
                 {
                     "shipping" : {
                         "address" : {
                             "address_type" : "shipping" ,
                             "city" : "Ahmedabad" ,
                             "company" : "Rbj" ,
                             "country_id" : "US" ,
                             "customer_address_id" : 2 ,
                             "email" : "rakesh@rakeshjesadiya.com" ,
                             "firstname" : "rakesh" ,
                             "lastname" : "jesadiya" ,
                             "postcode" : "30332" ,
                             "region" : "Georgia" ,
                             "region_code" : "GA" ,
                             "region_id" : 19 ,
                             "street" : [
                                 "Street 1" ,
                                 "Street 2"
                             ] ,
                             "telephone" : "123456"
                         } ,
                         "method" : "flatrate_flatrate"
                     }
                 }
             ]
         }
     }
}

When you run API using above payload,
You got the response from success order data with order_increment id as below format.

 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
{
     "base_currency_code" : "USD" ,
     "base_discount_amount" : - 4.5 ,
     "base_grand_total" : 45.5 ,
     "base_shipping_amount" : 5 ,
     "base_subtotal" : 45 ,
     "base_tax_amount" : 0 ,
     "base_total_due" : 45.5 ,
     "billing_address_id" : 204 ,
     "coupon_code" : "Test1" ,
     "created_at" : "2018-09-16 18:12:42" ,
     "customer_email" : "rakesh@rakeshjesadiya.com" ,
     "customer_firstname" : "rakesh" ,
     "customer_group_id" : 1 ,
     "customer_id" : 2 ,
     "customer_is_guest" : 0 ,
     "customer_lastname" : "jesadiya" ,
     "customer_note_notify" : 1 ,
     "discount_amount" : - 4.5 ,
     "discount_description" : "Test1" ,
     "email_sent" : 1 ,
     "entity_id" : 103 ,
     "grand_total" : 45.5 ,
     "increment_id" : "000000107" ,
     "is_virtual" : 0 ,
     "order_currency_code" : "USD" ,
     "protect_code" : "a0c46ced9e5dfca13a9f4af86a237aeb" ,
     "shipping_amount" : 5 ,
     "shipping_description" : "Flat Rate - Fixed" ,
     "state" : "new" ,
     "status" : "pending" ,
     "store_currency_code" : "USD" ,
     "store_id" : 1 ,
     "store_name" : "Main Website\nMain Website Store\nDefault Store View" ,
     "subtotal" : 45 ,
     "subtotal_incl_tax" : 45 ,
     "tax_amount" : 0 ,
     "total_due" : 45.5 ,
     "total_item_count" : 1 ,
     "total_qty_ordered" : 1 ,
     "updated_at" : "2018-09-16 18:12:42" ,
     "weight" : 1 ,
     "items" : [
         {
             "base_discount_amount" : 4.5 ,
             "base_original_price" : 45 ,
             "base_price" : 45 ,
             "base_price_incl_tax" : 45 ,
             "base_row_invoiced" : 0 ,
             "base_row_total" : 45 ,
             "base_tax_amount" : 0 ,
             "base_tax_invoiced" : 0 ,
             "created_at" : "2018-09-16 18:12:42" ,
             "discount_amount" : 4.5 ,
             "discount_percent" : 10 ,
             "free_shipping" : 0 ,
             "is_virtual" : 0 ,
             "item_id" : 124 ,
             "name" : "Push It Messenger Bag" ,
             "order_id" : 103 ,
             "original_price" : 45 ,
             "price" : 45 ,
             "price_incl_tax" : 45 ,
             "product_id" : 14 ,
             "product_type" : "simple" ,
             "qty_ordered" : 1 ,
             "row_total" : 45 ,
             "row_total_incl_tax" : 45 ,
             "sku" : "24-WB04" ,
             "store_id" : 1 ,
             "updated_at" : "2018-09-16 18:12:42"
         }
     ] ,
     "billing_address" : {
         "address_type" : "billing" ,
         "city" : "Ahmedabad" ,
         "company" : "Rbj" ,
         "country_id" : "US" ,
         "email" : "rakesh@rakeshjesadiya.com" ,
         "entity_id" : 204 ,
         "firstname" : "rakesh" ,
         "lastname" : "jesadiya" ,
         "parent_id" : 103 ,
         "postcode" : "30332" ,
         "region" : "Georgia" ,
         "region_code" : "GA" ,
         "region_id" : 19 ,
         "street" : [
             "Street 1" ,
             "Street 2"
         ] ,
         "telephone" : "123456"
     } ,
     "payment" : {
         "account_status" : null ,
         "additional_information" : [
             ""
         ] ,
         "cc_last4" : null ,
         "entity_id" : 103 ,
         "method" : "cashondelivery" ,
         "parent_id" : 103
     } ,
     "status_histories" : [ ] ,
     "extension_attributes" : {
         "shipping_assignments" : [
             {
                 "shipping" : {
                     "address" : {
                         "address_type" : "shipping" ,
                         "city" : "Ahmedabad" ,
                         "company" : "Rbj" ,
                         "country_id" : "US" ,
                         "customer_address_id" : 2 ,
                         "email" : "rakesh@rakeshjesadiya.com" ,
                         "entity_id" : 205 ,
                         "firstname" : "rakesh" ,
                         "lastname" : "jesadiya" ,
                         "parent_id" : 103 ,
                         "postcode" : "30332" ,
                         "region" : "Georgia" ,
                         "region_code" : "GA" ,
                         "region_id" : 19 ,
                         "street" : [
                             "Street 1" ,
                             "Street 2"
                         ] ,
                         "telephone" : "123456"
                     } ,
                     "method" : "flatrate_flatrate"
                 } ,
                 "items" : null
             }
         ]
     }
}
 

New order email

$orderid = '10000000';
$order = $this->_objectManager->get('Magento\Sales\Model\Order')->loadByIncrementId($orderid);
$this->_objectManager->get('Magento\Sales\Model\Order\Email\Sender\OrderSender')->send($order);
 

转载于:https://my.oschina.net/ganfanghua/blog/3084979

阅读终点,创作起航,您可以撰写心得或摘录文章要点写篇博文。去创作
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要在Magento 2中查看日志输出,您可以按照以下步骤进行操作: 1. 打开您的终端或命令行界面并导航到Magento的安装目录。 2. 运行以下命令以查看最新的日志文件: ```shell $ tail -f var/log/system.log ``` 这将实时显示系统日志文件的内容,您可以从中查看Magento的日志记录。 3. 如果您想查看指定的日志文件,例如异常日志或调试日志,可以运行以下命令: ```shell $ tail -f var/log/exception.log $ tail -f var/log/debug.log ``` 这将分别显示异常日志和调试日志的内容。 请注意,日志文件的位置可能因您的Magento安装和配置而有所不同。因此,在查看日志之前,您可能需要根据您的实际情况调整路径。 引用:$ composer require aune-io/magento2-b2butils 启用模块 $ bin/magento module:enable Aune_B2bUtils $ bin/magento setup:upgrade 特征 登记批准 允许商店所有者手动批准新客户,然后他们才能成功登录。 要启用... 引用:PhpStorm Magento 2插件安装在PhpStorm IDE中转到Settings > Preferences 导航到Plugins 单击Browse repositories...按钮,然后搜索“ Magento PhpStorm” 安装插件并重新启动PhpStorm 在PhpStorm IDE中转到Settings...。 引用:Thai的Magento 2的S3扩展 是一种流行的文件存储解决方案,允许Web应用程序在云中托管图像。将您的Web应用程序设置为使用云存储即可消除使用本地文件系统存储图像的需要。反过来,这又使公司可以启动更多服务器来...。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [magento2-b2butils:Magento 2的B2B实用程序](https://download.csdn.net/download/weixin_42116672/18285765)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] - *2* [magento2-phpstorm-plugin:适用于Magento 2PHPStorm插件](https://download.csdn.net/download/weixin_42157567/16594407)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] - *3* [magento2-s3:将Amazon S3用作Magento 2应用程序的文件存储解决方案](https://download.csdn.net/download/weixin_42099815/18466439)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值