Liquid、JavaScriptなどに関する質問
https://themes.shopify.com/themes/mr-parker/styles/wardrobe/preview?locale=ja
上記テンプレートを用いて、サイトを構築しております。
トップページの商品一覧から遷移した場合には、商品ページにある「Recommended products」が表示されるのですが、
商品一覧(Collections)から遷移した場合に、同様の商品でも「Recommended products」が表示されない現象に見舞われています。
こちらの原因を究明・解決したいと思っています。
カスタマイズより、レコメンド表示はONにしております。
----
URLは下記のような形です。
■前者(レコメンドが表示される)
https://ドメイン/collections/frontpage/products/商品名
■後者(レコメンドが表示されない)
https://ドメイン/products/商品名
product.liquidは下記の形です。
{% section 'product-template' %}
{% section 'custom-fields-products' %}
{% section 'product-recommendations' %}
product-recommendations.liquidによって表示を行っていると思われるのですが、こちらは下記のようなコードです。
{% if section.settings.show_product_recommendations %}
{% assign limit = section.settings.recommended_product_limit %}
<div id="related" class="row">
<div class="product-recommendations" data-product-id="{{ product.id }}" data-base-url="{{ routes.product_recommendations_url }}" data-limit="{{ limit }}">
{%- if recommendations.performed -%}
{%- if recommendations.products_count > 0 -%}
<div class="span-12">
<div class="section-heading">
<h2>{{ section.settings.product_recommendations_heading }}</h2>
<span class="section-border">
{%- if settings.header_border_style == 'zigzag' -%}<div class="zigzag"></div>{% endif %}
</span>
</div>
</div>
<div class="clear"></div>
{% case section.settings.grid %}
{% when 2 %}
{%- assign grid_item_width = 'span-6 auto' -%}
{% when 3 %}
{%- assign grid_item_width = 'span-4 md-span-4 sm-span-6 auto' -%}
{% when 4 %}
{%- assign grid_item_width = 'span-3 md-span-4 sm-span-6 auto' -%}
{% endcase %}
<div class="collection__grid-loop grid__wrapper">
{%- for product in recommendations.products -%}
<div class="product-index {{ grid_item_width }} collection__grid-item" data-product-id="{{ product.id }}">
{% render 'product-listing', product: product, limit: limit %}
</div>
{%- endfor -%}
</div>
{%- endif -%}
{%- else -%}
<div data-product-id="{{ product.id }}" data-section-id="{{ section.id }}" data-section-type="product-recommendations"></div>
{%- endif -%}
</div>
</div>
{% endif %}
変数に問題があるのかと思い、if文の前で変数を表示してみたところ、両URLにて変数の内容は同じでした。
「product.id」は取得できており、「recommendations.performed」等のif文の判断に用いられている変数も同一(0やfalse等)でした。
しかし、if文のあとで「recommendations.products_count」変数を表示したところ、レコメンド有URLには「4」、レコメンド無URLにおいては「0」と表示されました。
レコメンド無URLにおいては、「recommendations.products_count」にassignを用いて数値を代入しても、常に「0」と表示されました。
対して、レコメンド有のURLにおいてはif文後に数値を代入しても「4」になりました。
---
上記のような形なのですが、原因や解決方法などはわかりそうでしょうか。
まだ経験が浅く、要領を得ない内容になっていた場合は申し訳ございません。
助力いただけますと非常に幸いです。
不足情報などありましたら、追記いたします。
何卒よろしくお願いたします。
他の方なら原因含めて回答可能かもしれませんが、私個人の回答としてはテーマのサポートに問い合わせることをお勧めします。
以下はデモストアの同じ商品のページで、記載いただいたURLのパターンに合致していると思いますが、どちらのURLでも「Recommended products」は表示されているためです。
https://mr-parker.myshopify.com/products/rockstar-romper
https://mr-parker.myshopify.com/collections/new-arrivals/products/rockstar-romper
■recommendations object
自力で調査を行うという場合には、下記を参照しつつ該当部分の仕組みを確認された方が良いように思います。
全く同じコードではないかもしれませんが、根幹は同じではと思いますので。
https://shopify.dev/docs/themes/liquid/reference/objects/recommendations
https://shopify.dev/tutorials/develop-theme-recommended-products
https://shopify.dev/tutorials/develop-theme-recommended-products-using-liquid
以上ですが、すでに確認済みのことばかりでしたら申し訳ありません。
Shopifyに限らずですが、レコメンドのアルゴリズムは大量のデータが貯まらないと使い物にならないことが多いので、私は自動レコメンドを使用しません。
レコメンド自動化の代わりに、メタフィールドに出したい商品IDを書き込み表示する方法で代替してます。
また、メタフィールドに手動レコメンドが登録されてない場合は、商品が所属しているコレクションを上から数点出す方式でカバーしてます。
Shopify アカデミーの学習パスと認定スキルバッジExpanding Your Shopify Business Internationallyを活用して、国際的にビジネ...
By Shopify Feb 7, 2025Shopify アカデミーの学習パスB2B on Shopify:立ち上げとカスタマイズで卸売販売に進出しましょう。これら3つの無料コースは、ShopifyストアでB2B機能...
By Shopify Jan 31, 2025サポートの選択肢が増えていく中、最適となる選択の判断が難しくなっているかと存じます。今回は問題の解決に最適となるサポートの選択方法を、紹介させて頂きます。 選択肢のご紹介...
By Mirai Oct 6, 2024