custom/plugins/ChespackTheme/src/Resources/views/storefront/component/pagination.html.twig line 1

Open in your IDE?
  1. {% sw_extends '@Storefront/storefront/component/pagination.html.twig' %}
  2. {# Added products counter #}
  3. {% block component_pagination_nav %}
  4.     {% set currentPage = ((criteria.offset + 1) / criteria.limit )|round(0, 'ceil') %}
  5.     {% set totalPages = (entities.total / criteria.limit)|round(0, 'ceil') %}
  6.     {% set sortOrder = app.request.query.get('order')??'name-asc' %}
  7.     {% if searchResult.currentFilters.navigationId is defined %}
  8.         {% set currentNavigationId = searchResult.currentFilters.navigationId %}
  9.     {% endif %}
  10.     {% if page.header.navigation.active.id is defined %}
  11.         {% set currentNavigationId = page.header.navigation.active.id %}
  12.     {% endif %}
  13.     {# New Pagination #}
  14.     {% set urlbase = app.request.getSchemeAndHttpHost() ~ app.request.getBaseUrl() ~ app.request.getPathInfo() %}
  15.     {% set queryParams = [] %}
  16.     {% set p = app.request.query.get('p')|default(1) %}
  17.     {% set maxPage = 10 %} {# Replace maxPage with the actual value for the last page. #}
  18.     {% set allParams = app.request.query.all %}
  19.     {% set allParamsModified = allParams|merge({'p': 1}) %}
  20.     {% set queryParamsFirst = allParamsModified %}
  21.     {% set urlFirst = urlbase ~ ('?' ~ queryParamsFirst|url_encode) %}
  22.     {% if p > 1 %}
  23.         {% set allParamsModified = allParams|merge({'p': p - 1}) %}
  24.         {% set queryParamsPrev = allParamsModified %}
  25.         {% set urlPrev = urlbase ~ ('?' ~ queryParamsPrev|url_encode) %}
  26.     {% endif %}
  27.     {% if p < maxPage %}
  28.         {% set allParamsModified = allParams|merge({'p': p + 1}) %}
  29.         {% set queryParamsNext = allParamsModified %}
  30.         {% set urlNext = urlbase ~ ('?' ~ queryParamsNext|url_encode) %}
  31.     {% endif %}
  32.     {% set allParamsModified = allParams|merge({'p': totalPages}) %}
  33.     {% set queryParamsLast = allParamsModified %}
  34.     {% set urlLast = urlbase ~ ('?' ~ queryParamsLast|url_encode) %}
  35.     {% if totalPages > 1 %}
  36.         <nav aria-label="pagination" class="pagination-nav">
  37.             {# Added products counter #}
  38.             {% set listing = slot.data.listing %}
  39.             {% if listing.total > 0 %}
  40.                 {% block element_product_listing_count %}
  41.                     <div class="products-counter text-center p-3" data-products-counter="true">
  42.                         {{ "chespackTheme.category.counter"|trans({
  43.                             '%items%': listing.elements|length,
  44.                             '%total%': listing.total
  45.                         })|raw }}
  46.                     </div>
  47.                 {% endblock %}
  48.             {% endif %}
  49.             {% block component_pagination %}
  50.                 <ul class="pagination">
  51.                     {% block component_pagination_first %}
  52.                         <li class="page-item page-first{% if currentPage == 1 %} disabled{% endif %}">
  53.                             {% block component_pagination_first_input %}
  54.                                 <input type="radio"
  55.                                        {% if currentPage == 1 %}disabled="disabled"{% endif %}
  56.                                        name="p"
  57.                                        id="p-first"
  58.                                        value="1"
  59.                                        class="d-none"
  60.                                        title="pagination">
  61.                             {% endblock %}
  62.                             {% block component_pagination_first_label %}
  63.                                 <label class="page-link" for="p-first">
  64.                                     {% block component_pagination_first_link %}
  65.                                         {% if sortOrder %}
  66.                                             <a href="{{ urlFirst }}">
  67.                                                 {% sw_icon 'arrow-medium-double-left' style { 'size': 'fluid', 'pack': 'solid'} %}
  68.                                             </a>
  69.                                             {#                                            <a href="{{ seoUrl('frontend.navigation.page', { navigationId: currentNavigationId }) }}?p={{ i }}&order={{ sortOrder }}">#}
  70.                                             {#                                                {% sw_icon 'arrow-medium-double-left' style { 'size': 'fluid', 'pack': 'solid'} %}#}
  71.                                             {#                                            </a>#}
  72.                                         {% else %}
  73.                                             {% sw_icon 'arrow-medium-double-left' style { 'size': 'fluid', 'pack': 'solid'} %}
  74.                                         {% endif %}
  75.                                     {% endblock %}
  76.                                 </label>
  77.                             {% endblock %}
  78.                         </li>
  79.                     {% endblock %}
  80.                     {% block component_pagination_prev %}
  81.                         <li class="page-item page-prev{% if currentPage == 1 %} disabled{% endif %}">
  82.                             {% block component_pagination_prev_input %}
  83.                                 <input type="radio"
  84.                                        {% if currentPage == 1 %}disabled="disabled"{% endif %}
  85.                                        name="p"
  86.                                        id="p-prev"
  87.                                        value="{{ currentPage - 1 }}"
  88.                                        class="d-none"
  89.                                        title="pagination">
  90.                             {% endblock %}
  91.                             {% block component_pagination_prev_label %}
  92.                                 <label class="page-link" for="p-prev">
  93.                                     {% block component_pagination_prev_link %}
  94.                                         {% block component_pagination_prev_icon %}
  95.                                             {% if sortOrder %}
  96.                                                 <a href="{{ urlPrev }}">
  97.                                                     {% sw_icon 'arrow-medium-left' style {'size': 'fluid', 'pack': 'solid'} %}
  98.                                                 </a>
  99.                                                 {#                                                <a href="{{ seoUrl('frontend.navigation.page', { navigationId: currentNavigationId }) }}?p={{ (currentPage - 1) }}&order={{ sortOrder }}">#}
  100.                                                 {#                                                    {% sw_icon 'arrow-medium-left' style {'size': 'fluid', 'pack': 'solid'} %}#}
  101.                                                 {#                                                </a>#}
  102.                                             {% else %}
  103.                                                 {% sw_icon 'arrow-medium-left' style {'size': 'fluid', 'pack': 'solid'} %}
  104.                                             {% endif %}
  105.                                         {% endblock %}
  106.                                     {% endblock %}
  107.                                 </label>
  108.                             {% endblock %}
  109.                         </li>
  110.                     {% endblock %}
  111.                     {% block component_pagination_loop %}
  112.                         {% set start = currentPage - 2 %}
  113.                         {% if start <= 0 %}
  114.                             {% set start = currentPage - 1 %}
  115.                             {% if start <= 0 %}
  116.                                 {% set start = currentPage %}
  117.                             {% endif %}
  118.                         {% endif %}
  119.                         {% set end = start + 4 %}
  120.                         {% if end > totalPages %}
  121.                             {% set end = totalPages %}
  122.                         {% endif %}
  123.                         {% for page in start..end %}
  124.                             {% set isActive = (currentPage == page) %}
  125.                             {% block component_pagination_item %}
  126.                                 <li class="page-item{% if isActive %} active{% endif %}">
  127.                                     {% block component_pagination_item_input %}
  128.                                         {% if not sortOrder %}
  129.                                             <input type="radio"
  130.                                                    name="p"
  131.                                                    id="p{{ page }}"
  132.                                                    value="{{ page }}"
  133.                                                    class="d-none"
  134.                                                    title="pagination"
  135.                                                    data-sort-order="{{ sortOrder }}"
  136.                                                    {% if isActive %}checked="checked"{% endif %}
  137.                                             >
  138.                                         {% endif %}
  139.                                     {% endblock %}
  140.                                     {% block component_pagination_item_label %}
  141.                                         {% block component_pagination_item_link %}
  142.                                             {% block component_pagination_item_text %}
  143.                                                 {% if sortOrder %}
  144.                                                     {% set allParamsModified = allParams|merge({'p': page}) %}
  145.                                                     {% set queryParamsPage = allParamsModified %}
  146.                                                     {% set urlPage = urlbase ~ ('?' ~ queryParamsPage|url_encode) %}
  147.                                                     <a href="{{ urlPage }}">
  148.                                                         <label class="page-link"
  149.                                                                for="p{{ page }}">{{ page }}</label>
  150.                                                     </a>
  151.                                                     {#                                                <a href="{{ seoUrl('frontend.navigation.page', { navigationId: currentNavigationId }) }}?p={{ page }}&order={{ sortOrder }}">#}
  152.                                                     {#                                                    <label class="page-link"#}
  153.                                                     {#                                                           for="p{{ page }}">{{ page }}</label>#}
  154.                                                     {#                                                </a>#}
  155.                                                 {% else %}
  156.                                                     <label class="page-link"
  157.                                                            for="p{{ page }}">{{ page }}</label>
  158.                                                 {% endif %}
  159.                                             {% endblock %}
  160.                                         {% endblock %}
  161.                                         </label>
  162.                                     {% endblock %}
  163.                                 </li>
  164.                             {% endblock %}
  165.                         {% endfor %}
  166.                     {% endblock %}
  167.                     {% block component_pagination_next %}
  168.                         <li class="page-item page-next{% if currentPage == totalPages %} disabled{% endif %}">
  169.                             {% block component_pagination_next_input %}
  170.                                 <input type="radio"
  171.                                        {% if currentPage == totalPages %}disabled="disabled"{% endif %}
  172.                                        name="p"
  173.                                        id="p-next"
  174.                                        value="{{ currentPage + 1 }}"
  175.                                        class="d-none"
  176.                                        title="pagination">
  177.                             {% endblock %}
  178.                             {% block component_pagination_next_label %}
  179.                                 <label class="page-link" for="p-next">
  180.                                     {% block component_pagination_next_link %}
  181.                                         {% block component_pagination_next_icon %}
  182.                                             {% if sortOrder %}
  183.                                                 <a href="{{ urlNext }}">
  184.                                                     {% sw_icon 'arrow-medium-right' style { 'size': 'fluid', 'pack': 'solid'} %}
  185.                                                 </a>
  186.                                                 {#                                                <a href="{{ seoUrl('frontend.navigation.page', { navigationId: currentNavigationId }) }}?p={{ (currentPage + 1) }}&order={{ sortOrder }}">#}
  187.                                                 {#                                                    {% sw_icon 'arrow-medium-right' style { 'size': 'fluid', 'pack': 'solid'} %}#}
  188.                                                 {#                                                </a>#}
  189.                                             {% else %}
  190.                                                 {% sw_icon 'arrow-medium-right' style { 'size': 'fluid', 'pack': 'solid'} %}
  191.                                             {% endif %}
  192.                                         {% endblock %}
  193.                                     {% endblock %}
  194.                                 </label>
  195.                             {% endblock %}
  196.                         </li>
  197.                     {% endblock %}
  198.                     {% block component_pagination_last %}
  199.                         <li class="page-item page-last{% if currentPage == totalPages %} disabled{% endif %}">
  200.                             {% block component_pagination_last_input %}
  201.                                 <input type="radio"
  202.                                        {% if currentPage == totalPages %}disabled="disabled"{% endif %}
  203.                                        name="p"
  204.                                        id="p-last"
  205.                                        value="{{ totalPages }}"
  206.                                        class="d-none"
  207.                                        title="pagination">
  208.                             {% endblock %}
  209.                             {% block component_pagination_last_label %}
  210.                                 <label class="page-link" for="p-last">
  211.                                     {% block component_pagination_last_link %}
  212.                                         {% block component_pagination_last_icon %}
  213.                                             {% if sortOrder %}
  214.                                                 <a href="{{ urlLast }}">
  215.                                                     {% sw_icon 'arrow-medium-double-right' style { 'size': 'fluid', 'pack': 'solid'} %}
  216.                                                 </a>
  217.                                                 {#                                                <a href="{{ seoUrl('frontend.navigation.page', { navigationId: currentNavigationId }) }}?p={{ totalPages }}&order={{ sortOrder }}">#}
  218.                                                 {#                                                    {% sw_icon 'arrow-medium-double-right' style {#}
  219.                                                 {#                                                        'size': 'fluid',#}
  220.                                                 {#                                                        'pack': 'solid'#}
  221.                                                 {#                                                    } %}#}
  222.                                                 {#                                                </a>#}
  223.                                             {% else %}
  224.                                                 {% sw_icon 'arrow-medium-double-right' style {
  225.                                                     'size': 'fluid',
  226.                                                     'pack': 'solid'
  227.                                                 } %}
  228.                                             {% endif %}
  229.                                         {% endblock %}
  230.                                     {% endblock %}
  231.                                 </label>
  232.                             {% endblock %}
  233.                         </li>
  234.                     {% endblock %}
  235.                 </ul>
  236.             {% endblock %}
  237.         </nav>
  238.     {% endif %}
  239. {% endblock %}