使用Shopify产品页面URL参数来控制页面加载上的默认大小(此 /可能类似吗?)

发布于 2025-02-04 04:09:12 字数 252 浏览 1 评论 0原文

是否感兴趣,如果可能的话?

即使有人知道一个描述此过程的支持页面,那真是太神奇了!

一直在搜索一堆,但没有运气。

这里的目标是我们有类别(集合)页面,可能是“ King大小的床单”,但是页面上的产品包含多种尺寸变体。

我们想使用一个URL参数(或真正完成同一件事的任何东西),以便使用“集合”页面中的这些链接>>产品页面,以便从“大尺寸床单”页面点击时,产品将在“ King”大小上加载。

任何帮助都会很棒!

Interested in if this is possible?

Even if someone knows of a support page where it describes this process, that would be amazing!

Have been searching a bunch, but no luck.

The goal here is that we have category (collection) pages that might be something like “king sized sheets” – but the products featured on the page contain multiple size variants.

We would like to use a URL parameter (or anything really that accomplishes the same thing) in order to use those links from the collection page >> product page so that the products will load on “king” size when clicked from the “king sized sheets” page.

Any help would be amazing!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

蓝眼泪 2025-02-11 04:09:12

您需要在这些收集页面上的各个大小查询各个大小的变体,以便您可以链接到它们。这是您的收集模板目前可能的样子:

{%- for product in collection.products -%}
  {%- render 'product-item', product: product -%}
{%- endfor -%}

product-item sippet链接到

https://myshop.com/products/mymy -product?variant = 123

默认情况下将选择具有ID“ 123”的产品变体。

现在的“挑战”是更改您的product-perem的链接,以便它链接到特定变体。一个基本示例看起来像这样:

{%- for product in collection.products -%}
  {%- assign variant = product.variants | where: 'option1', 'king-size' -%}

  {%- render 'product-item', product: product, variant: variant[0] -%}
{%- endfor -%}

option1更改为您的大小选项的任何位置(还将king-size更改为要过滤的值的确切名称)。

然后确保用product.url链接variant.url

You'd need to query the variant with the respective size on those collection pages so you can link to them. This is what your collection template probably looks like at the moment:

{%- for product in collection.products -%}
  {%- render 'product-item', product: product -%}
{%- endfor -%}

The product-item snippet links to product.url. Which variant is selected on page load is then determined by your product template. In most cases this is done via product.selected_or_first_available_variant. The selected variant is based on the URL parameter variant. So, for example, if you navigate to

https://myshop.com/products/my-product?variant=123

the product variant with the ID "123" will be selected by default.

The "challenge" now is to change the link of your product-item so it links to a specific variant. An basic example would look like this:

{%- for product in collection.products -%}
  {%- assign variant = product.variants | where: 'option1', 'king-size' -%}

  {%- render 'product-item', product: product, variant: variant[0] -%}
{%- endfor -%}

Change option1 to whatever position your size option has (also change king-size to the exact name of the value you want to filter).

Then make sure to replace the product.url link with variant.url.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文