templates/app/Group/sorting.html.twig line 1

Open in your IDE?
  1. {% set route = app.request.attributes.get('_route') %}
  2. {% set route_parameters = app.request.attributes.get('_route_params')|merge(app.request.query.all) %}
  3. {% set criteria = app.request.query.get('criteria', {}) %}
  4. {% set default_path = path(route, route_parameters|merge({'sorting': null, 'criteria': criteria})) %}
  5. {% set from_a_to_z_path = path(route, route_parameters|merge({'sorting': {'name': 'asc'}, 'criteria': criteria})) %}
  6. {% set from_z_to_a_path = path(route, route_parameters|merge({'sorting': {'name': 'desc'}, 'criteria': criteria})) %}
  7. {% set oldest_first_path = path(route, route_parameters|merge({'sorting': {'createdAt': 'asc'}, 'criteria': criteria})) %}
  8. {% set newest_first_path = path(route, route_parameters|merge({'sorting': {'createdAt': 'desc'}, 'criteria': criteria})) %}
  9. {% set cheapest_first_path = path(route, route_parameters|merge({'sorting': {'price': 'asc'}, 'criteria': criteria})) %}
  10. {% set most_expensive_first_path = path(route, route_parameters|merge({'sorting': {'price': 'desc'}, 'criteria': criteria})) %}
  11. {% if app.request.query.get('sorting').name is defined and app.request.query.get('sorting').name == 'asc'%}
  12.     {% set current_sorting_label = 'sylius.ui.from_a_to_z'|trans|lower %}
  13.     {% set current_sorting_name = 'name' %}
  14.     {% set current_sorting_order = 'ASC' %}
  15. {% elseif app.request.query.get('sorting').name is defined and app.request.query.get('sorting').name == 'desc'%}
  16.     {% set current_sorting_label = 'sylius.ui.from_z_to_a'|trans|lower %}
  17.     {% set current_sorting_name = 'name' %}
  18.     {% set current_sorting_order = 'DESC' %}
  19. {% elseif app.request.query.get('sorting').price is defined and app.request.query.get('sorting').price == 'asc'%}
  20.     {% set current_sorting_label = 'sylius.ui.cheapest_first'|trans|lower %}
  21.     {% set current_sorting_name = 'variants.first.channelPricings.first.price' %}
  22.     {% set current_sorting_order = 'DESC' %}
  23. {% elseif app.request.query.get('sorting').price is defined and app.request.query.get('sorting').price == 'desc' %}
  24.     {% set current_sorting_label = 'sylius.ui.most_expensive_first'|trans|lower %}
  25.     {% set current_sorting_name = 'variants.first.channelPricings.first.price' %}
  26.     {% set current_sorting_order = 'ASC' %}
  27. {% endif %}
  28. <div class="mb-3  col-12 d-flex flex-row-reverse ff-os-regular">
  29.     <a aria-expanded="false" aria-haspopup="true" class="btn btn-light dropdown-toggle" data-toggle="dropdown" href="#" id="dropdownMenuLink" role="button">
  30.         {{ 'group.sorting.dropdown.label'|trans }}
  31.     </a>
  32.     <div aria-labelledby="dropdownMenuLink" class="dropdown-menu dropdown-menu-right">
  33.         <a class="dropdown-item" href="{{ from_a_to_z_path }}" data-text="{{ 'group.sorting.dropdown.from_a_to_z.label'|trans|lower }}">{{ 'group.sorting.dropdown.from_a_to_z.label'|trans }}</a>
  34.         <a class="dropdown-item" href="{{ from_z_to_a_path }}" data-text="{{ 'group.sorting.dropdown.from_z_to_a.label'|trans|lower }}">{{ 'group.sorting.dropdown.from_z_to_a.label'|trans }}</a>
  35.         <a class="dropdown-item" href="{{ cheapest_first_path }}" data-text="{{ 'group.sorting.dropdown.cheapest_first.label'|trans|lower }}">{{ 'group.sorting.dropdown.cheapest_first.label'|trans }}</a>
  36.         <a class="dropdown-item" href="{{ most_expensive_first_path }}" data-text="{{ 'group.sorting.dropdown.most_expensive_first.label'|trans|lower }}">{{ 'group.sorting.dropdown.most_expensive_first.label'|trans }}</a>
  37.     </div>
  38. </div>
  39. <div class="col-12 row px-0 mx-0">
  40.     {% if current_sorting_name|default(0) %}
  41.         {% for product in iterable|sort_by(current_sorting_name, current_sorting_order) %}
  42.             {% include 'app/Group/product.html.twig' with {'product': product, 'group': group} %}
  43.         {% endfor %}
  44.     {% else %}
  45.         {% for product in iterable %}
  46.             {% include 'app/Group/product.html.twig' with {'product': product, 'group': group} %}
  47.         {% endfor %}
  48.     {% endif %}
  49. </div>