Snipcart 中出现“购物车确认”错误

时间:2021-05-18 14:05:26

标签: javascript next.js e-commerce checkout snipcart

对于我的 nextjs 应用程序,我想使用 snipcart 结帐。当我尝试验证付款时,我收到一个错误:

A 'cart-confirmation' error occured in Snipcart.

Reason: 'product-crawling-failed'

--- Item 1 ---  [Item ID] 8  [Item Unique ID] 9e63189a-5a3b-4a25-bf57-ceb4574cad45  [Item Name] SEFLESS  [Url] https://cmeditions.fr/books/SEFLESS  [Status] NotFound  [Price in cart] 15  [ Crawled prices] []  [Details] We have not been able to find item with id '8' at 'https://cmeditions.fr/books/SEFLESS'. Please make sure the product is correctly defined.

这是我的截图按钮:

<div className="colophon">
            {product.status === true ? (
              <button
                className="snipcart-add-item buy-button "
                variant="dark"
                onMouseEnter={(e) => handleEnter(e)}
                onMouseOut={(e) => handleExit(e)}
                data-item-id={product.id}
                data-item-price={product.price}
                data-item-url={router.asPath}
                data-item-image={getStrapiMedia(product.grid_pic.url)}
                data-item-name={product.name}
                data-item-description={product.author}
                v-bind="customFields"
              >
                BUY ME!
              </button>

如果我点击错误中打印的产品 URL,我会进入目录而不是产品。我认为问题可能来自 nextjs 路由问题......?

1 个答案:

答案 0 :(得分:0)

您收到此错误是因为 order validation 失败。您将在 de developer logs 中找到有关导致错误的产品的更多信息。

首先,如果您使用的是 HTML 爬虫,请确保 data-item-url 指向带有 Snipcart 按钮的页面,或者如果您使用的是 JSON 爬虫,请确保指向产品定义。

如果您使用的是相对 URL,请确保设置了 default domain。此 URL 需要可公开访问。如果要在本地开发中进行测试,可以使用 ngrok 之类的工具。

另一个重要方面是不能动态添加 Snipcart 按钮(即,通过 javascript 或前端框架,如 Vue)。如果这是您的情况,那么 JSON crawler 会更适合您。