简体   繁体   English

如何确定出现在 Stripe 结帐中的产品的顺序/顺序

[英]How to determine order/sequence in which products appear in Stripe checkout

In stripe.redirectToCheckout() we use lineItems to list which Products to render;stripe.redirectToCheckout()我们使用lineItems列出要渲染的产品; those Products are items configured in Stripe Dashboard (in either Test mode or Production mode).这些产品是在 Stripe Dashboard 中配置的项目(在测试模式或生产模式下)。

I can't seem to find a way to control the order in which products are rendered:我似乎找不到控制产品呈现顺序的方法:

  • No change observed if I change the order of array elements in lineItems (see screenshot).如果我更改lineItems中数组元素的顺序,则没有观察到任何变化(请参见屏幕截图)。
  • No obvious tool within Stripe Dashboard , to re-order products eg via a "Move up/down" or draggable card. Stripe Dashboard 中没有明显的工具来重新订购产品,例如通过“上移/下移”或可拖动卡片。

I thought about trying to change the order by archiving and re-creating Products, but this seems like a hack and would be unsustainable even for 2-3 Products.我曾考虑尝试通过归档和重新创建产品来更改订单,但这似乎是一种 hack,即使对于 2-3 个产品也是不可持续的。 What do stores do when wanting to A/B test the ordering of Products, or when they have a large number of Products?当想要对产品的订购进行 A/B 测试时,或者当他们有大量产品时,商店会怎么做?

It's an awkward one to troubleshoot because "order/ordering", "arrange", "sequence" all have ambiguous meanings...!排错很麻烦,因为“order/ordering”、“arrange”、“sequence”都有不明确的含义……!

checkout.js 数组和生成的浏览器视图

The ordering/sequencing of products using lineItems array does work (see comment by @v3nkman on OP) but in my case the specific rendered page is not connected to that array on checkout.js ;使用lineItems数组对产品进行排序/排序确实有效(请参阅@v3nkman 在 OP 上的评论),但在我的情况下,特定呈现的页面未连接到checkout.js上的该数组; it is instead governed by a GraphQL string on Products.js and I solved the issue by adding a sort field into that as follows:相反,它由Products.js上的 GraphQL 字符串控制,我通过在其中添加一个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>
        )
      }}
    />
  )
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM