2

我正在为我的 Shopify 商店创建一个自定义结帐页面,以便处理与 stripe 和我自己的 API 的自定义集成。我可以通过查询参数将数据从 Shopify cart.js API 发送到我的自定义结帐,但是这个字符串相当丑陋而且很长。有人担心这是否会导致问题,或者是否有更好的方法。

作为参考,这是编码为查询字符串的默认购物车 json。约扎!

/?cart=%7B%22token%22%3A%22f57b4a11a31e5daaa3fae1c4cfcb0676%22%2C%22note%22%3Anull%2C%22attributes%22%3A%7B%7D%2C%22original_total_price%22%3A119495%2C%22total_price%22%3A119495%2C%22total_discount%22%3A0%2C%22total_weight%22%3A9072%2C%22item_count%22%3A3%2C%22items%22%3A%5B%7B%22id%22%3A22480473539%2C%22properties%22%3Anull%2C%22quantity%22%3A2%2C%22variant_id%22%3A22480473539%2C%22key%22%3A%2222480473539%3Adf55503d6a89267ddc2b2d67afcc9bac%22%2C%22title%22%3A%22White%22%2C%22price%22%3A59500%2C%22original_price%22%3A59500%2C%22discounted_price%22%3A59500%2C%22line_price%22%3A119000%2C%22original_line_price%22%3A119000%2C%22total_discount%22%3A0%2C%22discounts%22%3A%5B%5D%2C%22sku%22%3A%220002%22%2C%22grams%22%3A4536%2C%22vendor%22%3A%22Meural%22%2C%22product_id%22%3A7214792579%2C%22gift_card%22%3Afalse%2C%22url%22%3A%22%2Fproducts%2Fwhite%3Fvariant%3D22480473539%22%2C%22image%22%3A%22https%3A%2F%2Fcdn.shopify.com%2Fs%2Ffiles%2F1%2F1348%2F6411%2Fproducts%2Fwhite-front.png%3Fv%3D1468709138%22%2C%22handle%22%3A%22white%22%2C%22requires_shipping%22%3Atrue%2C%22product_type%22%3A%22%22%2C%22product_title%22%3A%22White%22%2C%22product_description%22%3A%22%5CnIncludes%20free%20white%C2%A0power%20cable.%C2%A0%5CnDimensions%3A%2032in%20x%2021in%20x%201.5in%22%2C%22variant_title%22%3Anull%2C%22variant_options%22%3A%5B%22Default%20Title%22%5D%7D%2C%7B%22id%22%3A284391014424%2C%22properties%22%3Anull%2C%22quantity%22%3A1%2C%22variant_id%22%3A284391014424%2C%22key%22%3A%22284391014424%3A0d9cdd833041859ad41f895bf59cb17a%22%2C%22title%22%3A%22Meural%20Membership%22%2C%22price%22%3A%22%244.95%2Fmo%22%2C%22original_price%22%3A495%2C%22discounted_price%22%3A495%2C%22line_price%22%3A495%2C%22original_line_price%22%3A495%2C%22total_discount%22%3A0%2C%22discounts%22%3A%5B%5D%2C%22sku%22%3A%22%22%2C%22grams%22%3A0%2C%22vendor%22%3A%22Meural%22%2C%22product_id%22%3A52034633752%2C%22gift_card%22%3Afalse%2C%22url%22%3A%22%2Fproducts%2Fsubscription%3Fvariant%3D284391014424%22%2C%22image%22%3A%22https%3A%2F%2Fcdn.shopify.com%2Fs%2Ffiles%2F1%2F1348%2F6411%2Fproducts%2Fcollage.jpg%3Fv%3D1503795405%22%2C%22handle%22%3A%22subscription%22%2C%22requires_shipping%22%3Afalse%2C%22product_type%22%3A%22subscription%22%2C%22product_title%22%3A%22Meural%20Membership%22%2C%22product_description%22%3A%22%22%2C%22variant_title%22%3Anull%2C%22variant_options%22%3A%5B%22Default%20Title%22%5D%7D%5D%2C%22requires_shipping%22%3Atrue%7D

如有必要,我显然会尝试减少它,但这并不理想。据我了解,没有办法通过外部网站的 API 获取 Shopify 购物车(这看起来有点傻,但是很好)。有谁知道更好的方法?

4

2 回答 2

1

我认为这应该是您将购物车数据访问到自定义结帐页面的流程。

  1. 维护购物车 webhook。将商店购物车的数据保存在某个数据库中。
  2. 您需要使用购物车令牌和会话作为 shopify 和您的自定义结帐之间的通信和身份验证点。
  3. 在 shopify 购物车页面上放置一个自定义按钮(例如我的结帐)以继续您的自定义结帐选项。
  4. 单击您的自定义按钮将购物车令牌获取到您的自定义结帐页面并使用它检索购物车数据。您可以使用会话进行身份验证。
  5. 检索微粒购物车数据后,您可以在结帐页面中进行必要的操作。
于 2017-09-04T05:35:35.717 回答
1

我发现您可以使用与内部相同的 ajax 请求轻松地从外部站点提取购物车数据。以下是如何使用它。如果用户不允许使用 cookie,则它不起作用,因此并不完美,但目前运行良好。

于 2017-09-10T01:29:18.243 回答