在Shopify上的Orders API中传递折扣代码

问题描述 投票:0回答:4

我一直在尝试开发一个在不同频道上接收Shopify订单的应用。我通过API成功下了订单,但我无法在订单中附上折扣代码。 POST数据的JSON对象如下:

{
  order: {
    email : request.params.order.email,    // string
    financial_status : 'pending',          // string
    send_receipt : true,                   // boolean 
    send_fulfillment_receipt : false,      // boolean
    note : request.params.order.note,      // string

    discount_codes : [], // supposed to be an array of Object| Problem here,

    line_items : request.params.order.line_items, // array
    customer : request.params.customer,    // JSON object 
    billing_address : request.params.order.billing_address,    // JSON object
    shipping_address : request.params.order.shipping_address   // JSON object
  }
}

根据文档,discount_codes是这样的 -

Applicable discount codes that can be applied to the order. If no codes exist the value will default to blank. A Discount code will include the following fields: 

amount: The amount of the discount.
code: The discount code.
type: The type of discount. Can be one of : "percentage", "shipping", "fixed_amount" (default).

我究竟做错了什么?我的discount_codes就是这个

[{amount: 100,code:'WELCOME10',type:'percentage'}]

有没有人这样做过?

rest post shopify
4个回答
0
投票

我成功创建了一直有折扣的订单,没有ShopifyPlus,因为这是无关紧要的。适合我的数据结构如下所示:

 [ { "code": "Shop By PizzleFuzzle 10%", amount: "10", "type": "percentage" } ]

0
投票

根据这个response from Shopify,你想要做的只有你通过total_discounts字段以及你想要应用的折扣总额才有可能。

正如您将在其他answer中看到的,您通过Shopify创建的任何代码都无法与API一起使用,因此不会记录它们的用法。

我试图使用这个API来测试我生成的不同优惠券代码的应用,但这似乎不可能。显然,该API旨在应用自定义的折扣,而不是Shopify中已存在的折扣。这对我来说是一个令人沮丧的限制。


-1
投票

折扣对象仅适用于Shopify Plus商家。

一旦您成为Shopify Plus商家,您就可以创建以下折扣代码:

POST /admin/discounts.json
{
  "discount": {
    "discount_type": "percentage",
    "value": "15.0",
    "code": "balderdash"
  }
}

请在Shopify API的折扣对象中查看更详细的文档:https://help.shopify.com/api/reference/discount


-1
投票

您应该使用value属性名称而不是amount属性名称。

EG

{value: 100,code:'WELCOME10',type:'percentage'}

并不是

{amount: 100,code:'WELCOME10',type:'percentage'}
© www.soinside.com 2019 - 2024. All rights reserved.