如何使用Magento2 API下订单?

时间:2015-11-18 02:48:21

标签: api rest magento2

我正在寻找完整的"快乐的道路"使用Magento2的REST API下订单。到目前为止,这些都是我遵循的所有步骤。我还缺少什么?

  1. 创建用户:[POST] /rest/V1/customers

  2. 登录(创建令牌):[POST] /rest/V1/integration/customer/token

  3. 获取导航产品类别:[GET] /rest/V1/categories

  4. 获取产品:

    4.1获取类别产品:[GET] /rest/V1/categories/{category_id}/products

    4.2或搜索产品:[GET] /rest/V1/products

  5. 创建购物车:[POST] /rest/V1/carts/mine

  6. 将商品添加到购物车:[POST] /rest/V1/carts/mine/items

  7. 获取购物车付款信息[GET] /rest/V1/carts/mine/payment-information

  8. ...

  9. 下订单还需要做些什么?

2 个答案:

答案 0 :(得分:4)

  1. 创建空车 网址:http://www.xxxxxx.com/rest/V1/carts/mine 电话:发布 回复:cartID例如:4290

  2. 将商品添加到购物车 网址: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"}]}}}
    }
    
  3. 添加结算信息 网址: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
    }
    
  4. 获取送货方式 网址: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
    

    }

  5. 添加送货信息 网址: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"
    }
    }
    
  6. 回复:付款方式和购物车详情

    1. 订购地点 网址:http://www.xxxxxx.com/rest/V1/carts/mine/order 身体:

      {
       "paymentMethod":{"method":"checkmo"},
       "shippingMethod":
          {
            "method_code":"flatrate",
      
            "carrier_code":"flatrate",
            "additionalProperties":{}
      
          }
      
      }
      
    2. 回复:orderid

答案 1 :(得分:2)

好的,我终于做对了。

  1. 保存付款信息并创建订单[POST] /rest/V1/carts/mine/payment-information