我正在寻找使用 Magento2 的 REST API 下订单的完整“快乐路径”。到目前为止,这些是我遵循的所有步骤。我还缺少什么?
创建用户:
[POST]/rest/V1/customers
登录(创建 token ):
[POST]/rest/V1/integration/customer/token
获取用于导航的产品类别:
[GET]/rest/V1/categories
获取产品:
4.1 获取类别产品:
[GET]/rest/V1/categories/{category_id}/products
4.2 或搜索产品:
[GET]/rest/V1/products
创建购物车:
[POST]/rest/V1/carts/mine
将商品添加到购物车:
[POST]/rest/V1/carts/mine/items
获取购物车付款信息
[GET]/rest/V1/carts/mine/payment-information
...
我还需要做什么才能下订单?
最佳答案
创建空购物车 网址:http://www.xxxxxx.com/rest/V1/carts/mine 调用: 邮寄 响应:cartID 例如:4290
将商品添加到购物车 网址:http://www.xxxxxx.com/rest/V1/carts/mine/items 正文:
{"cartItem":{ "sku":"JFCO00017","qty":1,"name":"Devil May Cry III 3 Dante Cosplay Costume","price":81.55,"product_type":"simple","quote_id":"4290","product_option":{"extension_attributes":{"custom_options":[{"option_id":"thumbnail","option_value":"\/d\/e\/devilmaycryiii3dantecosplay_1_.jpg"},{"option_id":"color_2","option_value":"Red"},{"option_id":"google_size","option_value":"xxs"}]}}} }
添加账单信息 网址:http://www.xxxxxx.com/rest/V1/carts/mine/billing-address 正文:
{ "address": { "city": "noida", "company": "iprag", "countryId": "IN", "email": "manish+2@gmail.com", "firstname": "Manish", "lastname": "Kumar", "postcode": "201301", "region": "UP", "saveInAddressBook": 1, "street": ["D-84"], "telephone": "8802xxxx90" }, "useForShipping": true }
获取运输方式 网址:http://www.xxxxxx.com/rest/V1/carts/mine/shipping-methods
{ "carrier_code": "flatrate", "method_code": "flatrate", "carrier_title": "Flat Rate", "method_title": "Fixed", "amount": 10, "base_amount": 10, "available": true, "error_message": "", "price_excl_tax": 10, "price_incl_tax": 10
}
添加送货信息 网址:http://www.xxxxxx.com/rest/V1/carts/mine/shipping-information 正文:
{ "addressInformation": { "billingAddress": { "city": "noida", "company": "iprag", "email": "nkn@gmail.com", "firstname": "Manish", "lastname": "Kumar", "postcode": "335001", "region": "UP", "street": ["D-84"], "telephone": "9413433217" }, "shippingAddress": { "city": "noida", "company": "iprag", "email": "nkn@gmail.com", "firstname": "Manish", "lastname": "Kumar", "postcode": "335001", "region": "UP", "street": ["D-84"], "telephone": "9413433217" }, "shippingCarrierCode": "flatrate", "shippingMethodCode": "flatrate" } }
回复:付款方式和购物车详细信息
订购地点 网址:http://www.xxxxxx.com/rest/V1/carts/mine/order 正文:
{ "paymentMethod":{"method":"checkmo"}, "shippingMethod": { "method_code":"flatrate", "carrier_code":"flatrate", "additionalProperties":{} } }
响应:订单ID
关于api - 如何使用Magento2 API下订单?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33770986/