安全变量@ shopify主题

时间:2017-10-27 14:35:20

标签: themes shopify

如您所见,在代码的最后一行中,我计算了该产品每米的基本价格。不幸的是,这个价格只针对所有变体计算一次。为每个产品变体输出特殊的基本价格。你能帮我解决这个问题吗?

  <p class="product-single__price product-single__price-{{ section.id }}{% unless current_variant.available %} product-price--sold-out{% endunless %}">
        {% if current_variant.compare_at_price > current_variant.price %}
            <span class="visually-hidden">{{ 'products.product.regular_price' | t }}</span>
            <s id="ComparePrice-{{ section.id }}">{{ current_variant.compare_at_price | money }}</s>
            <span class="product-price__price product-price__price-{{ section.id }} product-price__sale product-price__sale--single">
              <span id="ProductPrice-{{ section.id }}"    
                itemprop="price" content="{{ current_variant.price | divided_by: 100.00 }}">
                {{ current_variant.price | money }}
              </span>
              <span class="product-price__sale-label product-price__sale-label-{{ section.id }}">{{ 'products.product.on_sale' | t }}</span>
            </span>                  
        {% else %}
          <span class="visually-hidden">{{ 'products.product.regular_price' | t }}</span>
          <s id="ComparePrice-{{ section.id }}" class="hide">{{ current_variant.compare_at_price | money }}</s>
          <span class="product-price__price product-price__price-{{ section.id }}">
            <span id="ProductPrice-{{ section.id }}"
              itemprop="price" content="{{ current_variant.price | divided_by: 100.00 }}">
              {{ current_variant.price | money }}
            </span>
            <span class="product-price__sale-label product-price__sale-label-{{ section.id }} hide">{{ 'products.product.on_sale' | t }}</span>
          </span>
        {% endif %}  
        <p class="hint">Grundpreis: {{ product.price | times:current_variant1.title | divided_by:1000 | money}}/Meter</p> 
      </p>

1 个答案:

答案 0 :(得分:0)

如果您想为每个变体显示Grundpreis,那么您可以在循环中执行此操作:

{% for variant in product.variants %}
    <p class="hint">Grundpreis: {{ product.price | times:variant.title | divided_by:1000 | money}}/Meter</p> 
{% endfor %}