Shopify 一直在擦除 applied_discount

Shopify keeps erasing applied_discount

我正在使用 REST API 尝试创建一个草稿订单,其中包含一个 100% 折扣的订单项。

{
  draft_order: {
    customer: customer,
    note: "this is my note",
    line_items: [
      {
        variant_id: 8935893599248,
        quantity: 1,
        applied_discount: {
          title: 'FREE',
          description: 'FREE Item',
          value_type: 'percentage',
          value: '0.00',
          amount: '0.00',
        }
      }
    ],
    shipping_address: {
      address1: data[:address_1],
      address2: data[:address_2],
      city: data[:city],
      province: data[:state],
      zip: data[:zip_code],
      country_code: data[:country],
      phone: data[:phone]
    }.compact
  }
}

它创建了草稿订单,但在响应中它不断删除折扣并将其设置为 nil...这让我抓狂。我已经尝试了所有我能想到的组合。太令人沮丧了

如果您想创建 100% 折扣的草稿订单,您只需要更新 json 格式,您只需将值指定为 100,金额应该是您要购买的产品的价格打折

这里的 123456789 是我的产品的变体 ID 我的产品价格是 99.00, 有些数据与您的数据不符,所以只更改数据,但格式必须相同

这里我提到了客户 ID,如果你想为所有客户申请折扣,你可以跳过这个索引,订单指定任何特定客户的 ID 或电子邮件,但格式必须相同。

{
  "draft_order": {
    "note":"this is my note",
    "line_items": [
      {
        "variant_id": 123456789,
        "quantity": 1
      }
    ],
    "applied_discount": {
      "title": "FREE",
      "description": "FREE Item",
      "value": "100",
      "value_type": "percentage",
      "amount": "99"
    },
    "customer": {
      "id": 987456321
    },
    "shipping_address": {
      "address1": "123 Amoebobacterieae St",
      "address2": "",
      "city": "Ottawa",
      "company": null,
      "country": "Canada",
      "first_name": "Bob",
      "last_name": "Bobsen",
      "latitude": "45.41634",
      "longitude": "-75.6868",
      "phone": "555-625-1199",
      "province": "Ontario",
      "zip": "K2P0V6",
      "name": "Bob Bobsen",
      "country_code": "CA",
      "province_code": "ON"
    }
  }
}

可以参考这里https://help.shopify.com/en/api/reference/orders/draftorder#create-2019-07