只显示可用的选项Shopify上

问题描述:

Snippets/product-form.liquid有一个代码块:只显示可用的选项Shopify上

<div class="swatch_options"> 
    {% for option in product.options %} 
    {% include 'product-swatch' with option %} 
    {% endfor %} 
</div> 

这显示选项产品X的在不可用的色板:

<div data-value="option name" class="swatch-element color optionName-swatch available soldout"> 
    <div class="tooltip">Option Name</div> 
    <label for="optionName"> 
    <span class="crossed-out"></span> 
    </label> 
</div> 

当这些不兼容的变种被点击,显示一个大的“不可用”消息:

<p class="modal_price" itemprop="offers" itemscope="" itemtype="http://schema.org/Offer"> 
    <meta itemprop="priceCurrency" content="USD"> 
    <meta itemprop="seller" content="site"> 
    <link itemprop="availability" href="http://schema.org/InStock"> 
    <meta itemprop="itemCondition" content="New"> 
    <span class="sold_out">Unavailable</span> 
    <span itemprop="price" content="10.00" class=""> 
    <span class="current_price "></span> 
    </span> 
    <span class="was_price"></span> 
    <span class="sale savings"></span> 
</p> 

我试过在{% include 'product-swatch' with option %}之前检查variant.availableproduct.variants.first.availablevariant.inventory_quantity > 0,但没有成功。

如何隐藏不兼容的变体?

编辑:这是目前什么的product-swatch.liquid内:

{% comment %} 
    Set the extension of your color files below. Use 'png', 'jpeg', 'jpg' or 'gif'. 
{% endcomment %} 

{% assign file_extension = 'png' %} 

{% assign swatch = product-swatch %} 
{% assign found_option = false %} 
{% assign is_color = false %} 
{% assign option_index = 0 %} 

{% for option in product.options %} 
    {% if option == swatch %} 
    {% assign found_option = true %} 
    {% assign option_index = forloop.index0 %} 
    {% assign downcased_option = swatch | downcase %} 
    {% if downcased_option contains 'color' or downcased_option contains 'colour' %} 
     {% assign is_color = true %} 
    {% endif %} 
    {% endif %} 
{% endfor %} 

<div class="swatch clearfix" data-option-index="{{ option_index }}"> 
    <div class="option_title">{{ swatch }}</div> 
    {% assign values = '' %} 
    {% for variant in product.variants %} 
    {% if variant.available %} 
    {% assign value = variant.options[option_index] %} 
    {% unless values contains value %} 
     {% assign values = values | join: ',' %} 
     {% assign values = values | append: ',' | append: value %} 
     {% assign values = values | split: ',' %} 
     <input id="swatch-{{ option_index }}-{{ value | handle }}-{{ product.id }}" type="radio" name="option-{{ option_index }}" value="{{ value | escape }}"{% if forloop.first %} checked{% endif %} /> 
     <div data-value="{{ value | escape }}" class="swatch-element {% if is_color %}color {% endif %}{{ value | handle }}-swatch {% if variant.available %}available{% else %}soldout{% endif %}"> 
     {% if is_color %} 
      <div class="tooltip">{{ value }}</div> 
     {% endif %} 
     {% if is_color %} 
      <label for="swatch-{{ option_index }}-{{ value | handle }}-{{ product.id }}" style="background-image: url({{ value | handle | append: '.' | append: file_extension | asset_img_url: '50x' }}); background-color: {{ value | split: ' ' | last | handle }};"> 
      <span class="crossed-out"></span> 
      </label> 
     {% else %} 
      <label for="swatch-{{ option_index }}-{{ value | handle }}-{{ product.id }}"> 
      {{ value }} 
      <span class="crossed-out"></span> 
      </label> 
     {% endif %} 
     </div> 
    {% endunless %} 
    {% endif %} 
    {% endfor %} 
</div> 

看来您在寻找Linked Options的功能。

看一看这个文档: https://help.shopify.com/themes/customization/navigation/link-product-options-in-menus

的代码托管在GitHub上: https://gist.github.com/carolineschnapp/1083007

它调整与色板工作,以及(我假设你正在使用的default implementation)。

+1

他的色板正在工作。他只是想隐藏不可用的变体。 –

编辑您的产品swatch.liquid文件下的 “片段” 文件夹中。

查找{% for variant in product.variants %}并将其放在{% if variant.available %}之后。

找到{% endfor %}并把它放在{% endif %}之前。

如果不能正常工作,请与我们分享product-swatch.liquid的代码。

+0

这是我的第一个想法,但'variant.available'似乎会为每个变体返回'true'。它看起来像'product-swatch.liquid'可能是一个更好的地方来编辑它。这不是一个库存问题,而是选项的组合不可用于购买。 – arby

+0

嗨, 你说过,'我试过在{%包括'product-swatch'选项%}之前检查variant.available,product.variants.first.available和variant.inventory_quantity> 0,但没有成功。 我在问你编辑product-swatch.liquid并进行我上面建议的更改。 如果不工作,请分享产品swatch.liquid的完整代码。 –

+0

@arby,那么您在更新中发布的代码不起作用?你的意思是不兼容的变体?缺货变体或其他东西? –