javascript - 如何确定出现在 Stripe 结帐中的产品的顺序/顺序
问题描述
我们stripe.redirectToCheckout()
用来lineItems
列出要呈现的产品;这些产品是在 Stripe Dashboard 中配置的项目(在测试模式或生产模式下)。
我似乎找不到控制产品呈现顺序的方法:
- 如果我更改数组元素的顺序(
lineItems
请参见屏幕截图),则没有观察到任何变化。 - Stripe Dashboard中没有明显的工具来重新订购产品,例如通过“上移/下移”或可拖动卡片。
我曾考虑尝试通过归档和重新创建产品来更改订单,但这似乎是一种 hack,即使对于 2-3 个产品也是不可持续的。当想要对产品的订购进行 A/B 测试时,或者当他们有大量产品时,商店会怎么做?
排错很麻烦,因为“order/ordering”、“arrange”、“sequence”都有不明确的含义……!
解决方案
使用lineItems
数组对产品进行排序/排序确实有效(请参阅@v3nkman 对 OP 的评论),但在我的情况下,特定呈现的页面未连接到该数组checkout.js
;相反,它由一个 GraphQL 字符串控制Products.js
,我通过在其中添加一个sort
字段解决了这个问题,如下所示:
const Products = () => {
return (
<StaticQuery
query={graphql`
query ProductPrices {
prices: allStripePrice(
filter: { active: { eq: true } }
sort: { fields: [created], order: ASC } // new line
) {
edges {
node {
id
active
currency
unit_amount
product {
id
name
images
description
}
}
}
}
}
`}
render={({ prices }) => {
// Group prices by product
const products = {}
for (const { node: price } of prices.edges) {
const product = price.product
if (!products[product.id]) {
products[product.id] = product
products[product.id].prices = []
}
products[product.id].prices.push(price)
}
return (
<div style={containerStyles}>
{Object.keys(products).map(key => (
<ProductCard key={products[key].id} product={products[key]} />
))}
</div>
)
}}
/>
)
}
推荐阅读
- reactjs - 如何在不改变其他卡位置的情况下交换两张卡
- javascript - 我如何获得一个元素来检测鼠标悬停
- python-3.x - 调用多进程时docker服务器挂起并给出此错误
- java - ArrayList 的烦恼
- javascript - Bootstrap v3.3.6 下拉菜单不适用于动态元素
- c++ - 在继承 C++ 中调用 main 中的参数化构造函数
- javascript - firebase onAuthStateChanged 用户不应为空
- stack - AppleScript 在更改文件扩展名时抛出堆栈溢出错误
- azure - 将 SAS 令牌重写(附加)到 azure cdn 中的 url
- python - 使用 Galaxy Zoo 数据集、TensorFlow 和 Keras 训练 GAN