{% sw_extends '@Storefront/storefront/component/pagination.html.twig' %}{# Added products counter #}{% block component_pagination_nav %} {% set currentPage = ((criteria.offset + 1) / criteria.limit )|round(0, 'ceil') %} {% set totalPages = (entities.total / criteria.limit)|round(0, 'ceil') %} {% set sortOrder = app.request.query.get('order')??'name-asc' %} {% if searchResult.currentFilters.navigationId is defined %} {% set currentNavigationId = searchResult.currentFilters.navigationId %} {% endif %} {% if page.header.navigation.active.id is defined %} {% set currentNavigationId = page.header.navigation.active.id %} {% endif %} {# New Pagination #} {% set urlbase = app.request.getSchemeAndHttpHost() ~ app.request.getBaseUrl() ~ app.request.getPathInfo() %} {% set queryParams = [] %} {% set p = app.request.query.get('p')|default(1) %} {% set maxPage = 10 %} {# Replace maxPage with the actual value for the last page. #} {% set allParams = app.request.query.all %} {% set allParamsModified = allParams|merge({'p': 1}) %} {% set queryParamsFirst = allParamsModified %} {% set urlFirst = urlbase ~ ('?' ~ queryParamsFirst|url_encode) %} {% if p > 1 %} {% set allParamsModified = allParams|merge({'p': p - 1}) %} {% set queryParamsPrev = allParamsModified %} {% set urlPrev = urlbase ~ ('?' ~ queryParamsPrev|url_encode) %} {% endif %} {% if p < maxPage %} {% set allParamsModified = allParams|merge({'p': p + 1}) %} {% set queryParamsNext = allParamsModified %} {% set urlNext = urlbase ~ ('?' ~ queryParamsNext|url_encode) %} {% endif %} {% set allParamsModified = allParams|merge({'p': totalPages}) %} {% set queryParamsLast = allParamsModified %} {% set urlLast = urlbase ~ ('?' ~ queryParamsLast|url_encode) %} {% if totalPages > 1 %} <nav aria-label="pagination" class="pagination-nav"> {# Added products counter #} {% set listing = slot.data.listing %} {% if listing.total > 0 %} {% block element_product_listing_count %} <div class="products-counter text-center p-3" data-products-counter="true"> {{ "chespackTheme.category.counter"|trans({ '%items%': listing.elements|length, '%total%': listing.total })|raw }} </div> {% endblock %} {% endif %} {% block component_pagination %} <ul class="pagination"> {% block component_pagination_first %} <li class="page-item page-first{% if currentPage == 1 %} disabled{% endif %}"> {% block component_pagination_first_input %} <input type="radio" {% if currentPage == 1 %}disabled="disabled"{% endif %} name="p" id="p-first" value="1" class="d-none" title="pagination"> {% endblock %} {% block component_pagination_first_label %} <label class="page-link" for="p-first"> {% block component_pagination_first_link %} {% if sortOrder %} <a href="{{ urlFirst }}"> {% sw_icon 'arrow-medium-double-left' style { 'size': 'fluid', 'pack': 'solid'} %} </a> {# <a href="{{ seoUrl('frontend.navigation.page', { navigationId: currentNavigationId }) }}?p={{ i }}&order={{ sortOrder }}">#} {# {% sw_icon 'arrow-medium-double-left' style { 'size': 'fluid', 'pack': 'solid'} %}#} {# </a>#} {% else %} {% sw_icon 'arrow-medium-double-left' style { 'size': 'fluid', 'pack': 'solid'} %} {% endif %} {% endblock %} </label> {% endblock %} </li> {% endblock %} {% block component_pagination_prev %} <li class="page-item page-prev{% if currentPage == 1 %} disabled{% endif %}"> {% block component_pagination_prev_input %} <input type="radio" {% if currentPage == 1 %}disabled="disabled"{% endif %} name="p" id="p-prev" value="{{ currentPage - 1 }}" class="d-none" title="pagination"> {% endblock %} {% block component_pagination_prev_label %} <label class="page-link" for="p-prev"> {% block component_pagination_prev_link %} {% block component_pagination_prev_icon %} {% if sortOrder %} <a href="{{ urlPrev }}"> {% sw_icon 'arrow-medium-left' style {'size': 'fluid', 'pack': 'solid'} %} </a> {# <a href="{{ seoUrl('frontend.navigation.page', { navigationId: currentNavigationId }) }}?p={{ (currentPage - 1) }}&order={{ sortOrder }}">#} {# {% sw_icon 'arrow-medium-left' style {'size': 'fluid', 'pack': 'solid'} %}#} {# </a>#} {% else %} {% sw_icon 'arrow-medium-left' style {'size': 'fluid', 'pack': 'solid'} %} {% endif %} {% endblock %} {% endblock %} </label> {% endblock %} </li> {% endblock %} {% block component_pagination_loop %} {% set start = currentPage - 2 %} {% if start <= 0 %} {% set start = currentPage - 1 %} {% if start <= 0 %} {% set start = currentPage %} {% endif %} {% endif %} {% set end = start + 4 %} {% if end > totalPages %} {% set end = totalPages %} {% endif %} {% for page in start..end %} {% set isActive = (currentPage == page) %} {% block component_pagination_item %} <li class="page-item{% if isActive %} active{% endif %}"> {% block component_pagination_item_input %} {% if not sortOrder %} <input type="radio" name="p" id="p{{ page }}" value="{{ page }}" class="d-none" title="pagination" data-sort-order="{{ sortOrder }}" {% if isActive %}checked="checked"{% endif %} > {% endif %} {% endblock %} {% block component_pagination_item_label %} {% block component_pagination_item_link %} {% block component_pagination_item_text %} {% if sortOrder %} {% set allParamsModified = allParams|merge({'p': page}) %} {% set queryParamsPage = allParamsModified %} {% set urlPage = urlbase ~ ('?' ~ queryParamsPage|url_encode) %} <a href="{{ urlPage }}"> <label class="page-link" for="p{{ page }}">{{ page }}</label> </a> {# <a href="{{ seoUrl('frontend.navigation.page', { navigationId: currentNavigationId }) }}?p={{ page }}&order={{ sortOrder }}">#} {# <label class="page-link"#} {# for="p{{ page }}">{{ page }}</label>#} {# </a>#} {% else %} <label class="page-link" for="p{{ page }}">{{ page }}</label> {% endif %} {% endblock %} {% endblock %} </label> {% endblock %} </li> {% endblock %} {% endfor %} {% endblock %} {% block component_pagination_next %} <li class="page-item page-next{% if currentPage == totalPages %} disabled{% endif %}"> {% block component_pagination_next_input %} <input type="radio" {% if currentPage == totalPages %}disabled="disabled"{% endif %} name="p" id="p-next" value="{{ currentPage + 1 }}" class="d-none" title="pagination"> {% endblock %} {% block component_pagination_next_label %} <label class="page-link" for="p-next"> {% block component_pagination_next_link %} {% block component_pagination_next_icon %} {% if sortOrder %} <a href="{{ urlNext }}"> {% sw_icon 'arrow-medium-right' style { 'size': 'fluid', 'pack': 'solid'} %} </a> {# <a href="{{ seoUrl('frontend.navigation.page', { navigationId: currentNavigationId }) }}?p={{ (currentPage + 1) }}&order={{ sortOrder }}">#} {# {% sw_icon 'arrow-medium-right' style { 'size': 'fluid', 'pack': 'solid'} %}#} {# </a>#} {% else %} {% sw_icon 'arrow-medium-right' style { 'size': 'fluid', 'pack': 'solid'} %} {% endif %} {% endblock %} {% endblock %} </label> {% endblock %} </li> {% endblock %} {% block component_pagination_last %} <li class="page-item page-last{% if currentPage == totalPages %} disabled{% endif %}"> {% block component_pagination_last_input %} <input type="radio" {% if currentPage == totalPages %}disabled="disabled"{% endif %} name="p" id="p-last" value="{{ totalPages }}" class="d-none" title="pagination"> {% endblock %} {% block component_pagination_last_label %} <label class="page-link" for="p-last"> {% block component_pagination_last_link %} {% block component_pagination_last_icon %} {% if sortOrder %} <a href="{{ urlLast }}"> {% sw_icon 'arrow-medium-double-right' style { 'size': 'fluid', 'pack': 'solid'} %} </a> {# <a href="{{ seoUrl('frontend.navigation.page', { navigationId: currentNavigationId }) }}?p={{ totalPages }}&order={{ sortOrder }}">#} {# {% sw_icon 'arrow-medium-double-right' style {#} {# 'size': 'fluid',#} {# 'pack': 'solid'#} {# } %}#} {# </a>#} {% else %} {% sw_icon 'arrow-medium-double-right' style { 'size': 'fluid', 'pack': 'solid' } %} {% endif %} {% endblock %} {% endblock %} </label> {% endblock %} </li> {% endblock %} </ul> {% endblock %} </nav> {% endif %}{% endblock %}