Liquid、JavaScriptなどに関する質問
現在、バリエーション登録している商品を、商品一覧に表示されるように実装してあります。
※商品タグに「not to be displayed separately」を付けた場合は一覧表示されない。
この場合、オプションが1つのみであれば問題ないのですが、商品に複数のオプションがあると重複して表示されてしまいます。
例えば、Tシャツに「カラー(2色)」「サイズ(3サイズ)」あった場合
2×3+2×3=12 で12のバリエーションが一覧として表示されます。
そのため、オプションが複数ある商品は、1つのオプションのみ一覧表示させる、
などの条件を加えたいです。
{% for product in collection.products %}
{% assign variation = false %}
{% assign variationsItem = false %}
{% if product.tags contains 'not to be displayed separately' %}
{% assign variationsItem = true %}
{% endif %}
{% if product.variants.size > 1 and variationsItem == false %}
{% assign variation = true %}
{% for option in product.options %}
{% for variant in product.variants %}
{% render 'product-block-variant',mainproduct:product, product: variant, custom_aspect_ratio: chosen_aspect_ratio, animate: true %}
{% endfor %}
{% endfor %}
{% endif %}
{% if variation == false %}
{% render 'product-block', product: product, custom_aspect_ratio: chosen_aspect_ratio, animate: true %}
{% endif %}
{% endfor %}
</div>
{% endif %}
解決済! ベストソリューションを見る。
成功
汎用的な解決方法ではありませんが、
例で示されているように、
「カラー」と「サイズ」の2つのオプションがある場合にのみ回答いたします。
通常、「カラー」だけを表示されたいと思いますので、下記のようにされてはいかがでしょうか?
※動作確認はしておりません。
{% for product in collection.products %}
{% assign variation = false %}
{% assign variationsItem = false %}
{% if product.tags contains 'not to be displayed separately' %}
{% assign variationsItem = true %}
{% endif %}
{% if product.variants.size > 1 and variationsItem == false %}
{% assign variation = true %}
{% assign has_two_options = false %}
{% if product.options contains 'カラー' and product.options contains 'サイズ' %}
{% assign has_two_options = true %}
{% endif %}
{% if has_two_options %}
{% for option in product.options %}
{% if option.name == 'カラー' %}
{% assign variant_colors = '' %}
{% for variant in product.variants %}
{% unless variant_colors contains variant.option1 %}
{% render 'product-block-variant',mainproduct:product, product: variant, custom_aspect_ratio: chosen_aspect_ratio, animate: true %}
{% assign variant_colors = variant_colors | append: variant.option1 | append: ',' %}
{% endunless %}
{% endfor %}
{% endif %}
{% endfor %}
{% else %}
{% for variant in product.variants %}
{% render 'product-block-variant',mainproduct:product, product: variant, custom_aspect_ratio: chosen_aspect_ratio, animate: true %}
{% endfor %}
{% endif %}
{% endif %}
{% if variation == false %}
{% render 'product-block', product: product, custom_aspect_ratio: chosen_aspect_ratio, animate: true %}
{% endif %}
{% endfor %}
ご参考まで。
(キュー田辺)
成功
汎用的な解決方法ではありませんが、
例で示されているように、
「カラー」と「サイズ」の2つのオプションがある場合にのみ回答いたします。
通常、「カラー」だけを表示されたいと思いますので、下記のようにされてはいかがでしょうか?
※動作確認はしておりません。
{% for product in collection.products %}
{% assign variation = false %}
{% assign variationsItem = false %}
{% if product.tags contains 'not to be displayed separately' %}
{% assign variationsItem = true %}
{% endif %}
{% if product.variants.size > 1 and variationsItem == false %}
{% assign variation = true %}
{% assign has_two_options = false %}
{% if product.options contains 'カラー' and product.options contains 'サイズ' %}
{% assign has_two_options = true %}
{% endif %}
{% if has_two_options %}
{% for option in product.options %}
{% if option.name == 'カラー' %}
{% assign variant_colors = '' %}
{% for variant in product.variants %}
{% unless variant_colors contains variant.option1 %}
{% render 'product-block-variant',mainproduct:product, product: variant, custom_aspect_ratio: chosen_aspect_ratio, animate: true %}
{% assign variant_colors = variant_colors | append: variant.option1 | append: ',' %}
{% endunless %}
{% endfor %}
{% endif %}
{% endfor %}
{% else %}
{% for variant in product.variants %}
{% render 'product-block-variant',mainproduct:product, product: variant, custom_aspect_ratio: chosen_aspect_ratio, animate: true %}
{% endfor %}
{% endif %}
{% endif %}
{% if variation == false %}
{% render 'product-block', product: product, custom_aspect_ratio: chosen_aspect_ratio, animate: true %}
{% endif %}
{% endfor %}
ご参考まで。
(キュー田辺)
Shopifyペイメント決済サービスを利用していて、ストアの管理画面の通知セクションに突然「Shopifyペイメントの使用を継続するために必要な情報」というバナーメッセージが表示さ...
By Mirai Dec 3, 2023すべてのShopifyアカウントはデフォルトではmyshopify.comのURLと関連付けられており、これはアカウント設定時に使用したビジネス名に基づいて作成されます。しかし、オ...
By Nina_13 Nov 26, 2023このトピックは英語版コミュニティの投稿:Shopify Web Pixel Manager Sandbox FAQの日本翻訳です。
By Mirai Nov 19, 2023