单击集合页面中的变体产品时,应在产品页面 Shopify 中打开相同的变体

发布于 2025-01-09 10:44:17 字数 1782 浏览 3 评论 0原文

我正在 Shopify 网站上工作,我所做的是将产品的所有变体显示为产品系列页面上的单个产品,但我需要帮助的是,当有人单击产品系列页面上的变体图像时,它应该在产品页面中打开相同的变体

 <div class="col-6 col-md-4 custom-variant" data-tag="{{test}}">
          <div class="hover-grid-wrapper">
          <a href="{{product.url}}">
            {%if variant.image.src != blank %}
            <img src="{{ variant.image.src | img_url: 'master' }}" alt="" class="img-responsive" />
            {% else %}
            <div class="product-image pr oh lazyload" data-include="{{pr_url}}/?view=img{{sett_equal}}"><div class="nt_bg_lz nt_fk_lz"{% unless sett_equal %} style="padding-top:{{ 1 | divided_by: images_0.aspect_ratio | times: 100}}%;"{% endunless %}></div></div>
            <img src="{{ product.featured_image.src | crop:center | img_url: 'master' }}" class="featured-image" alt="{{ product.featured_image.alt | escape }}">
            {% endif %}
            
            {% assign vTitle = variant.title | split: ' / ' %}
            {% assign title = words[0] | capitalize  %}
            
            <span class="color-text color-{{color | handle }} {{variant.id}}">{{title}}</span>
          </a>
          {%- if variant.inventory_quantity <= 0  and variant.inventory_management == 'shopify' -%}{%- assign txt = 'products.product.pre_orders' | t -%}{%- else -%}{%- assign txt = 'products.product.add_to_cart' | t -%}{%- endif -%}
          <a href="{{ url_last }}" class="add-to-cart-btn pr_atc_ tc dib js_addtc {{tooltip}} truncate" data-id="{{ variant.id }}" rel="nofollow"><span>+ Quick Add</span></a>
        </div>
        </div>

这是我的代码

I am working on a Shopify website, what I have done is, show all the variants of a product as the individual product on the collection page, but what I want help with is, when someone click on the variant image on the collection page, it should open the same variant in the product page

 <div class="col-6 col-md-4 custom-variant" data-tag="{{test}}">
          <div class="hover-grid-wrapper">
          <a href="{{product.url}}">
            {%if variant.image.src != blank %}
            <img src="{{ variant.image.src | img_url: 'master' }}" alt="" class="img-responsive" />
            {% else %}
            <div class="product-image pr oh lazyload" data-include="{{pr_url}}/?view=img{{sett_equal}}"><div class="nt_bg_lz nt_fk_lz"{% unless sett_equal %} style="padding-top:{{ 1 | divided_by: images_0.aspect_ratio | times: 100}}%;"{% endunless %}></div></div>
            <img src="{{ product.featured_image.src | crop:center | img_url: 'master' }}" class="featured-image" alt="{{ product.featured_image.alt | escape }}">
            {% endif %}
            
            {% assign vTitle = variant.title | split: ' / ' %}
            {% assign title = words[0] | capitalize  %}
            
            <span class="color-text color-{{color | handle }} {{variant.id}}">{{title}}</span>
          </a>
          {%- if variant.inventory_quantity <= 0  and variant.inventory_management == 'shopify' -%}{%- assign txt = 'products.product.pre_orders' | t -%}{%- else -%}{%- assign txt = 'products.product.add_to_cart' | t -%}{%- endif -%}
          <a href="{{ url_last }}" class="add-to-cart-btn pr_atc_ tc dib js_addtc {{tooltip}} truncate" data-id="{{ variant.id }}" rel="nofollow"><span>+ Quick Add</span></a>
        </div>
        </div>

This is my code

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

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

发布评论

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

评论(1

笨死的猪 2025-01-16 10:44:17

简单:)

您应该使用变体 深层链接

在产品的链接上,您应该添加 ?variant=[variant-id]

<a href="{{product.url}}">

在您的代码中替换

<a href="{{ product.url }}?variant={{ variant.id }}">

Easy :)

You should use variant deep link

On the link of the product, you should add ?variant=[variant-id]

On your code replace:

<a href="{{product.url}}">

by

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