价格规则
您可以使用PriceRule资源使用条件创建折扣。然后,您可以使用DiscountCode资源将条件与折扣代码关联。商家可以将折扣代码分发给他们的客户。
使用PriceRule资源,您可以创建将折扣指定为百分比,固定金额或免费送货的折扣。您使用权利和前提条件来动态构建这些折扣。
要了解如何将价格规则与折扣代码相关联,请参见DiscountCode资源。
创建价格规则
您可以创建包含权利和前提条件的价格规则。权利描述折扣适用的指定资源,例如特定产品,变体或收藏。前提条件描述了为了使折扣适用于授权资源必须满足的要求。例如,您可能希望折扣仅适用于特定的运输价格范围或特定的小计范围。
您可以使用权利,先决条件和其他条件来创建折扣,例如以下示例:
- 如果总金额超过40美元,则可从买方订单中扣除10美元
- 某些收藏可享受15%的折扣
- 超过$ 100.00的加拿大买家免运费,最多可兑换20次
有关如何创建价格规则的示例,请参见POST方法。
PriceRule可以做什么
Shopify API使您可以使用PriceRule资源执行以下操作。这些常规操作的更详细的版本可能可用:
- POST /admin/api/2021-01/price_rules.json创建价格规则
- PUT /admin/api/2021-01/price_rules/{price_rule_id}.json更新现有的价格规则
- GET /admin/api/2021-01/price_rules.json检索价格规则列表
- GET /admin/api/2021-01/price_rules/{price_rule_id}.json检索单个价格规则
- GET /admin/api/2021-01/price_rules/count.json检索所有价格规则的计数
- 删除/admin/api/2021-01/price_rules/{price_rule_id}.json删除现有的PriceRule
PriceRule属性
分配方法 | plain "allocation_method": "each" 价格规则的分配方法。有效值:+ 每个:折扣适用于每个有资格的项目。例如,对于采用15美元折扣的价格规则,结帐中的每个有资格的订单项都将折扣15美元。 + 跨越:计算得出的折扣金额将应用于所有有资格的项目。例如,对于享受15美元折扣的价格规则,折扣将应用于所有有资格的商品。 当值 target_type 的shipping_line ,那么这个值必须是each 。 |
---|---|
created_at 只读 | plain "created_at": "2017-03-13T16:09:54-04:00" 创建价格规则的日期和时间(ISO 8601格式)。 |
Updated_at 只读 | plain "updated_at": "2017-03-14T16:09:54-04:00" 价格规则更新的日期和时间(ISO 8601格式)。 |
客户选择 | plain "customer_selection": "prerequisite" 价格规则的客户选择。有效值:+ 全部:价格规则对所有客户均有效。 + 前提:客户必须属于所指定的客户保存的搜索 prerequisite_saved_search_ids 之一,或者是所指定的客户之一prerequisite_customer_ids 。 |
ends_at | plain "ends_at": "2017-04-19T17:59:10Z" 价格规则结束的日期和时间(ISO 8601格式)。必须在之后starts_at 。 |
titled_collection_ids | plain "entitled_collection_ids": [ 4564654869, 8979761006 ] 其产品有资格享受折扣的馆藏ID列表。只能将 target_type 设置为line_item 并将其target_selection 设置为使用entitled 。不能与entitled_product_ids 或结合使用entitled_variant_ids 。 |
titled_country_ids | plain " entitled_country_ids": [ 7897987023, 3569053679 ] 有权享受折扣的运输国家的ID列表。只能将target_type 设置为shipping_line 并将其target_selection 设置为使用entitled 。 |
titled_product_ids | plain "entitled_product_ids": [ 7897397755, 42382368242 ] 有权享受折扣的产品ID列表。只能将target_type 设置为line_item 并将其target_selection 设置为使用entitled 。如果中包含产品变体 entitled_variant_ids ,则entitled_product_ids 不能包含与该变体相关联的产品的ID。 |
titled_variant_ids | plain "entitled_variant_ids": [ 6798798798, 5675765905 ] 有权享受折扣的产品变体ID列表。只能将target_type 设置为line_item 并将其target_selection 设置为使用entitled 。如果产品包含在中 entitled_product_ids ,则entitled_variant_ids 不能包含与该产品相关联的任何变体的ID。 |
ID 只读 | plain "id": 9808080986 价格规则的ID。 |
every_per_customer | plain "once_per_customer": true 生成的折扣代码是否仅对每个客户一次使用有效。使用客户ID进行跟踪。 |
prerequisite_customer_ids | plain "prerequisite_customer_ids": [ 384028349005, 3492039843 ] 客户ID列表。为了使价格规则适用,客户必须与指定的客户之一匹配。如果 prerequisite_customer_ids 已填充,则prerequisite_saved_search_ids 必须为空。 |
prerequisite_quantity_range | plain "prerequisite_quantity_range": { "greater_than_or_equal_to": 2 } 适用价格规则的最小项目数。它具有以下属性:+ Greater_than_or_equal_to:授权购物车商品的数量必须大于或等于此值。 |
prerequisite_saved_search_ids | plain "prerequisite_saved_search_ids": [ 1123452345, 43535363636 ] 客户保存的搜索ID列表。为了使价格规则适用,客户必须在与客户保存的搜索匹配的客户组中。如果 prerequisite_saved_search_ids 已填充,则prerequisite_customer_ids 必须为空。 |
prerequisite_shipping_price_range | plain "prerequisite_shipping_price_range": { "less_than_or_equal_to": "10.0" } 适用价格规则的最高运费。它具有以下属性:+ less_than_or_equal_to:运费必须小于或等于此值。 |
prerequisite_subtotal_range | plain "prerequisite_subtotal_range": { "greater_than_or_equal_to": "40.0" } 适用价格规则的最小小计。它具有以下属性:+ Greater_than_or_equal_to:有资格购物车的小计必须大于或等于此值才能应用折扣。 |
prerequisite_to_entitlement_purchase | plain "prerequisite_to_entitlement_purchase": { "prerequisite_amount": "80.00" } 买X送Y折扣的前提条件。它具有以下属性:+ prerequisite_amount:有权享受折扣的最低购买金额。 |
开始于 | plain "starts_at": "2017-01-19T17:59:10Z" 价格规则开始的日期和时间(ISO 8601格式)。 |
target_selection | plain "target_selection": "entitled" 价格规则的目标选择方法。有效值:+ 全部:价格规则将折扣应用于结帐中的所有订单项。 + titled:价格规则仅将折扣应用于选定的权利。 |
target_type | plain "target_type": "line_item" 价格规则适用的目标类型。有效值:+ line_item:价格规则适用于购物车的订单项。 + shipping_line:价格规则适用于购物车的运输路线。 |
标题 | plain "title": "SUMMERSALE10OFF" 价格规则的标题。Shopify管理员搜索使用它来检索折扣。它还显示在Shopify管理员的“折扣”页面上,以获取批量折扣。对于非批量折扣,折扣代码显示在管理员上。 为了获得一致的搜索体验,请使用与关联的折扣代码 title 的code 属性相同的值。 |
usage_limit | plain "usage_limit": 10 每个折扣代码可以使用价格规则的最大次数。 |
prerequisite_product_ids | plain "prerequisite_product_ids": [ 7897397755, 42382368242 ] 产品ID的列表,这些ID将成为“购买X获得Y”类型折扣的前提条件。将prerequisite_product_ids 只能用于有:+ target_type 设置为line_item ,+ target_selection 设置为entitled ,+ allocation_method 设置为each 和+ prerequisite_to_entitlement_quantity_ratio 定义。警告 如果中包含产品变体 prerequisite_variant_ids ,则prerequisite_product_ids 不能包含与该变体相关联的产品的ID。 |
prerequisite_variant_ids | plain "prerequisite_variant_ids": [ 6798798798, 5675765905 ] 变体ID的列表,这些ID将成为“购买X获得Y”类型折扣的先决条件。将entitled_variant_ids 只能用于有:+ target_type 设置为line_item ,+ target_selection 设置为entitled ,+ allocation_method 设置为each 和+ prerequisite_to_entitlement_quantity_ratio 定义。警告 如果产品包含在中 prerequisite_product_ids ,则prerequisite_variant_ids 不能包含与该产品相关联的任何变体的ID。 |
prerequisite_collection_ids | plain "prerequisite_collection_ids": [ 4564654869, 8979761006 ] 集合ID的列表,这些ID将成为“买X得Y”折扣的先决条件。将entitled_collection_ids 只能用于有:+ target_type 设置为line_item ,+ target_selection 设置为entitled ,+ allocation_method 设置为each 和+ prerequisite_to_entitlement_quantity_ratio 定义。不能与 prerequisite_product_ids 或结合使用 prerequisite_variant_ids 。 |
价值 | plain "value": -35 价格规则的值。如果如果值target_type 是shipping_line ,那么只有-100 被接受。该值必须为负。 |
值类型 | plain "value_type": "fixed_amount" 价格规则的值类型。有效值:+ fixed_amount:应用折扣, value 以商店货币为单位。例如,如果value 为-30,商店的货币为USD,则在应用折扣时会扣除$ 30 USD。+ 百分比:应用百分比折扣 value 。例如,如果value 为-30,则在应用折扣时将扣除30%。如果 target_type 是shipping_line ,则仅percentage 被接受。 |
prerequisite_to_entitlement_quantity_ratio | plain "prerequisite_to_entitlement_quantity_ratio": { "prerequisite_quantity": 2, "entitled_quantity": 1 } 买/买比例获得买X买Y的折扣。prerequisite_quantity 定义必要的“购买”数量和entitled_quantity 提供的“获取”数量。将 prerequisite_to_entitlement_quantity_ratio 只能用于有:+ value_type 设置为percentage ,+ target_type 设置为line_item ,+ target_selection 设置为entitled ,+ allocation_method 设置为each ,+ prerequisite_product_ids 或prerequisite_variant_ids 或prerequisite_collection_ids 定义并+ entitled_product_ids 或entitled_variant_ids 或entitled_collection_ids 定义。警告 不能组合使用 prerequisite_subtotal_range ,prerequisite_quantity_range 或prerequisite_shipping_price_range 。 |
分配限制 | plain "allocation_limit": 3 折扣可在购物车上分配的次数(如果有)。例如,买1顶帽子可获得1顶帽子的免费折扣,可在具有6顶帽子的购物车上应用3次,其中最多3顶帽子被打折-如果allocation_limit 为3。空(null )allocation_limit 表示分配数量不受限制。警告 allocation_limit 仅适用于“买X得Y”折扣。创建时的默认值为null (无限)。 |
终点
邮政/admin/api/2021-01/price_rules.json 创建价格规则创建价格规则,为买方提供10美元的订单优惠
POST /admin/api/2021-01/price_rules.json
{
“ price_rule” : {
标题:“ SUMMERSALE10OFF”,
“ target_type” :“ line_item”,
“ target_selection” :“全部”,
“ allocation_method” :“跨”,
“ value_type” :“ fixed_amount”,
“值” :“ -10.0”,
“ customer_selection” :“全部”,
“ starts_at” :“ 2017-01-19T17:59:10Z”
}
}
创建一个价格规则,为购买者提供特定集合15%的折扣
POST /admin/api/2021-01/price_rules.json
{
“ price_rule” : {
“ title” :“ 15OFFCOLLECTION”,
“ target_type” :“ line_item”,
“ target_selection” :“已授权”,
“ allocation_method” :“跨”,
“ value_type” :“百分比”,
“值” :“ -15.0”,
“ customer_selection” :“全部”,
“ entitled_collection_ids” : [
841564295
],
“ starts_at” :“ 2017-01-19T17:59:10Z”
}
}
创建价格规则,为买方提供超过50.00美元的订单免费送货服务,最多可使用20次
POST /admin/api/2021-01/price_rules.json
{
“ price_rule” : {
“ title” :“ FREESHIPPING”,
“ target_type” :“ shipping_line”,
“ target_selection” :“全部”,
“ allocation_method” :“每个”,
“ value_type” :“百分比”,
“值” :“-100.0”,
“ usage_limit” :20,
“ customer_selection” :“全部”,
“ prerequisite_subtotal_range” : {
“ greater_than_or_equal_to” :“ 50.0”
},
“ starts_at” :“ 2017-01-19T17:59:10Z”
}
}
创建一个价格规则,使选定的一组客户的订单优惠5美元
POST /admin/api/2021-01/price_rules.json
{
“ price_rule” : {
“ title” :“ 5OFFCUSTOMERGROUP”,
“ target_type” :“ line_item”,
“ target_selection” :“全部”,
“ allocation_method” :“跨”,
“ value_type” :“ fixed_amount”,
“值” :“-5.0”,
“ customer_selection” :“先决条件”,
“ prerequisite_saved_search_ids” : [
789629109
],
“ starts_at” :“ 2017-01-19T17:59:10Z”
}
}
创建一个买入X买入Y的价格规则,如果客户购买2个iPod,则可以免费获得一个iPod touch
POST /admin/api/2021-01/price_rules.json
{
“ price_rule” : {
标题:“ Buy2iPodsGetiPodTouchForFree”,
“ value_type” :“百分比”,
“值” :“-100.0”,
“ customer_selection” :“全部”,
“ target_type” :“ line_item”,
“ target_selection” :“已授权”,
“ allocation_method” :“每个”,
“ starts_at” :“ 2018-03-22T00 :00:00-00:00”,
“ prerequisite_collection_ids” : [
841564295
],
“ entitled_product_ids” : [
921728736
],
“ prerequisite_to_entitlement_quantity_ratio” : {
“ prerequisite_quantity” :2,
“ entitled_quantity” :1
},
“ allocation_limit” :3
}
}
放/admin/api/2021-01/price_rules/{price_rule_id}.json 更新现有的价格规则更新价格规则的标题
PUT /admin/api/2021-01/price_rules/507328175.json
{
“ price_rule” : {
“ id” :507328175,
“ title” :“冬季特卖”
}
}
GET/admin/api/2021-01/price_rules.json Retrieves a list of price rules. Note: As of version 2019-10, this endpoint implements pagination by using links that are provided in the response header. Sending the<font style="background-color:#F4F6F8;">page</font>
parameter will return an error. To learn more, see Making requests to paginated REST Admin API endpoints.
limit | The maximum number of results to retrieve. (default: 50 , maximum: 250 ) |
---|---|
since_id | 将结果限制为指定的ID之后。 |
created_at_min | 显示在日期之后创建的价格规则(格式为2017-03-25T16:15:47-04:00)。 |
created_at_max | 显示在日期之前创建的价格规则(格式2017-03-25T16:15:47-04:00)。 |
Updated_at_min | 显示价格规则在日期之后最后更新(格式2017-03-25T16:15:47-04:00)。 |
Updated_at_max | 显示价格规则在日期之前最后更新(格式2017-03-25T16:15:47-04:00)。 |
starts_at_min | 显示自日期之后开始的价格规则(格式为2017-03-25T16:15:47-04:00)。 |
starts_at_max | 显示在日期之前开始的价格规则(格式为2017-03-25T16:15:47-04:00)。 |
Ends_at_min | 显示在日期之后结束的价格规则(格式为2017-03-25T16:15:47-04:00)。 |
Ends_at_max | 显示在日期之前结束的价格规则(格式2017-03-25T16:15:47-04:00)。 |
times_used | 显示使用时间的价格规则。 |
检索所有价格规则
GET /admin/api/2021-01/price_rules.json
得到/admin/api/2021-01/price_rules/{price_rule_id}.json 检索单个价格规则通过其ID检索单个价格规则
GET /admin/api/2021-01/price_rules/507328175.json
得到/admin/api/2021-01/price_rules/count.json 检索所有价格规则的计数。检索所有价格规则的计数
GET /admin/api/2021-01/price_rules/count.json
删除/admin/api/2021-01/price_rules/{price_rule_id}.json 删除价格规则删除价格规则
删除/admin/api/2021-01/price_rules/507328175.json