api - 如何使用Magento2 API下订单?

标签 api rest magento2

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

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

  2. 登录(创建 token ):[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. ...

我还需要做什么才能下订单?

最佳答案

  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"
    }
    }
    

回复:付款方式和购物车详细信息

  • 订购地点 网址: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/

    相关文章:

    python - 用 django rest 散列 token

    python - 如何使 rest_framework 序列化程序不允许多余的字段?

    php - Magento 2 定制运输承运人模块

    javascript - 最新版本的 Firefox 没有 svgElm.offsetHeight 属性

    api - UDP 使用套接字 API

    javascript - 如何从此 api 获取 jsonp 链接?

    api - Google place Api PlaceDetails图片引用

    java - Spring 休息 : when pathVariable matches multiple entities should spring return a list or throw error

    magento - 免费送货代码不适用于 magento 2 的 UPS

    javascript - Knockout 'data-bind' 中的 'scope' 关键字