{% set Categories = repository('Eccube\\Entity\\Category').getList() %}
{% macro tree(Category) %}
{% from _self import tree %}
<a href="{{ url('product_list') }}?category_id={{ Category.id }}">
{{ Category.name }}
</a>
{% if Category.children|length > 0 %}
<ul>
{% for ChildCategory in Category.children %}
<li>
{{ tree(ChildCategory) }}
</li>
{% endfor %}
</ul>
{% endif %}
{% endmacro %}
<div class="categories mt-4 p-3">
<h5 class="text-center fw-bold">CATEGORIES</h5>
<hr class="hr-custom">
<ul class="list-unstyled">
{% for category in Categories %}
{% set count = repository('Eccube\\Entity\\Product').countProductByCategory(category) %}
{% if count > 0 %}
<li class="mb-2"><i class="fa fa-angle-right mx-2" aria-hidden="true"></i><a href="{{ url('product_list', {'category_id': category.id}) }}">{{ category.name }}({{count}})</a></li>
{% endif %}
{% endfor %}
</ul>
</div>