0
0

More than 3 years have passed since last update.

EC-CUBE4 の関連カテゴリをシンプルな表示にする

Last updated at Posted at 2021-09-01

EC-CUBE4 の関連カテゴリをシンプルな表示にする

EC-CUBE4は、標準で商品詳細ページに「関連カテゴリ」が表示されます。
ただし、この関連カテゴリ、親カテゴリの階層もすべて表示してしまいます。

価格帯
価格帯 > 2001円~3000円
お菓子・スイーツ
お菓子・スイーツ > 洋菓子
お菓子・スイーツ > 洋菓子 > クッキー

これを

価格帯 > 2001円~3000円
お菓子・スイーツ > 洋菓子 > クッキー

というすっきりした表示にしたいと思います。
当初はDB(dtb_product_category)のデータ側で対処しようかと思いましたが、表示側のみの変更で可能でした。

\app\template\default\Product\detail.twig

                    {# 関連カテゴリ #}
                    {% if Product.ProductCategories is not empty %}
                        <div class="ec-productRole__category">
                            <div class="confilm-table-btn">{{ '▼ 関連カテゴリ'|trans }}</div>
                            <div class="confilm-tables" style="display:none;">
                            {% for ProductCategory in Product.ProductCategories %}
                                <ul>
                                    <li>
                                        {% for Category in ProductCategory.Category.path %}
                                            <a href="{{ url('product_list') }}?category_id={{ Category.id }}">{{ Category.name }}</a> {%- if loop.last == false %}
                                            <span>></span>{% endif -%}
                                        {% endfor %}
                                    </li>
                                </ul>
                            {% endfor %}
                            </div>
                        </div>
                    {% endif %}

これに、「子供がいるかどうか」の分岐を1つ入れてやればOKです。

                    {# 関連カテゴリ #}
                    {% if Product.ProductCategories is not empty %}
                        <div class="ec-productRole__category">
                            <div class="confilm-table-btn">{{ '▼ 関連カテゴリ'|trans }}</div>
                            <div class="confilm-tables" style="display:none;">
                            {% for ProductCategory in Product.ProductCategories %}
                                {% if ProductCategory.Category.countBranches == 1 %}
                                <ul>
                                    <li>
                                        {% for Category in ProductCategory.Category.path %}
                                            <a href="{{ url('product_list') }}?category_id={{ Category.id }}">{{ Category.name }}</a> {%- if loop.last == false %}
                                            <span>></span>{% endif -%}
                                        {% endfor %}
                                    </li>
                                </ul>
                                {% endif %}
                            {% endfor %}
                            </div>
                        </div>
                    {% endif %}

とします。

ほーらすっきり!

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0