大数跨境

Storefront API 购物车类型中的新折扣字段

Storefront API 购物车类型中的新折扣字段 Shopify电商独立站
2026-04-10
1
导读:截至 API 版本 2026-07,Storefront API 中的折扣字段和金额已引入多项变更。

截至 API 版本 2026-07,Storefront API 中的折扣字段和金额已引入多项变更。

变更内容

已弃用的字段:

  • cart.discountAllocations 字段已弃用,请改用 cart.lines[].discountAllocations(lineLevelOnly: false) 和 cart.deliveryGroups[].discountAllocations。
  • cartDiscountAllocation.discountApplication 字段已弃用,请改用 sourceDiscountApplication。注意:discountApplication 上的 value 字段错误地返回了按行分配的金额,而非配置的折扣金额(例如,$10 的固定折扣分配给某一行 $4 时,会显示 value: $4)。新的 sourceDiscountApplication 字段将返回正确的值。

新增字段:

  • cart.discountApplications: 列出当前应用于购物车的所有折扣(例如,商品折扣、运费折扣和订单折扣)。
  • cartDiscountAllocation.sourceDiscountApplication:返回具有正确配置折扣值和具体类型信息的折扣应用。例如,无论 $10 的固定折扣如何跨行分配,都会显示 value: $10。使用 GraphQL 片段访问特定类型的字段,例如 sourceDiscountApplication { … on CartCodeDiscountApplication { code } }。
  • baseCartDiscountApplication.totalAllocatedAmount:显示整个购物车中分配的总折扣金额。例如,如果 10% 的折扣在 A 行分配 $4、在 B 行分配 $6,则两行均会显示 totalAllocatedAmount: $10。
  • cart.deliveryGroups[].discountAllocations: 显示分配给配送组的折扣。

新增参数:

  • cart.lines[].discountAllocations(lineLevelOnly: Boolean):lineLevelOnly 参数允许您仅请求产品级折扣或分配至购物车行的所有折扣。为保持向后兼容性,其默认值为 true。

您需要执行的操作

  • 更新查询以使用 cart.discountApplications 代替 cart.discountAllocations,从而读取购物车上的所有折扣应用。
  • 将 cartDiscountAllocation.discountApplication 替换为 sourceDiscountApplication,以获取准确的折扣值和特定类型的字段。
  • 将产品分配查询移至 cart.lines[].discountAllocations(lineLevelOnly: false)。
  • 将配送分配查询移至 cart.deliveryGroups[].discountAllocations。
  • 使用百分比折扣、固定金额折扣和免运费折扣测试您的折扣计算。
【声明】内容源于网络
0
0
Shopify电商独立站
1234
内容 7146
粉丝 0
Shopify电商独立站 1234
总阅读87.4k
粉丝0
内容7.1k