【问题标题】:How to place an order using Magento2 API?如何使用 Magento2 API 下订单?
【发布时间】:2016-02-19 15:40:36
【问题描述】:

我正在寻找使用 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. ...

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

【问题讨论】:

  • 您是否更进一步并为订单创建装运?我似乎无法弄清楚如何发布正确的参数来创建货件。我可以编辑现有的,但不能创建新的。很想知道你是否已经弄明白了。
  • 对不起,我没有。我只卖虚拟产品。

标签: api rest magento2


【解决方案1】:
  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"
    }
    }
    

回复:付款方式和购物车详情

  1. 下单地点 网址:http://www.xxxxxx.com/rest/V1/carts/mine/order 正文:

    {
     "paymentMethod":{"method":"checkmo"},
     "shippingMethod":
        {
          "method_code":"flatrate",
    
          "carrier_code":"flatrate",
          "additionalProperties":{}
    
        }
    
    }
    

响应:orderid

【讨论】:

  • 你能回答这个问题吗?stackoverflow.com/questions/41158020/…
  • 当然,我也有同样的问题。
  • 第 4 步:获取运输方式。当执行 magento 2 rest API docs(quoteShippingMethodManagementV1: /V1/carts/mine/shipping-methods) 中提到的 GET 请求时,它给出 {"message":"%fieldName is a required field.","parameters":{" fieldName":"cartId"}} 作为响应。文档中没有提到必需的参数。请帮忙!!
  • 我需要在每个 URL 中传递 'cartId' 来代替 'mine' 吗??
  • 当我执行最后一步时,我们在 /V1/carts/mine/order(/V1/carts/{cartId}/order 下订单,我用 cartId 替换了 'mine' 否则它说 cartId 是必填字段)它会回复 '{"message":"Please enter a customer email."}'
【解决方案2】:

好吧,我终于猜对了。

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

【讨论】:

  • 您能在此处提供有关有效负载的更多信息吗?比如,如何设置收货地址?
  • 如何使用api设置收货地址报价?
  • 我相信有前一步(在 8 之前),但我还没有尝试过,因为我只销售虚拟产品。当你找到它时,请修复我的答案,以便它可以帮助其他人。
  • 是的,有两种通过rest api下订单的方式 1.[POST] /rest/V1/carts/mine/payment-information 2. [POST] /rest/V1/carts/mine /订单
  • 如果我发布那个,那我需要先设置付款信息吗?
猜你喜欢
  • 1970-01-01
  • 2019-02-22
  • 1970-01-01
  • 2016-10-18
  • 1970-01-01
  • 2023-03-23
  • 2022-11-02
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多