{% set route = app.request.attributes.get('_route') %}
{% set route_parameters = app.request.attributes.get('_route_params')|merge(app.request.query.all) %}
{% set criteria = app.request.query.get('criteria', {}) %}
{% set default_path = path(route, route_parameters|merge({'sorting': null, 'criteria': criteria})) %}
{% set from_a_to_z_path = path(route, route_parameters|merge({'sorting': {'name': 'asc'}, 'criteria': criteria})) %}
{% set from_z_to_a_path = path(route, route_parameters|merge({'sorting': {'name': 'desc'}, 'criteria': criteria})) %}
{% set oldest_first_path = path(route, route_parameters|merge({'sorting': {'createdAt': 'asc'}, 'criteria': criteria})) %}
{% set newest_first_path = path(route, route_parameters|merge({'sorting': {'createdAt': 'desc'}, 'criteria': criteria})) %}
{% set cheapest_first_path = path(route, route_parameters|merge({'sorting': {'price': 'asc'}, 'criteria': criteria})) %}
{% set most_expensive_first_path = path(route, route_parameters|merge({'sorting': {'price': 'desc'}, 'criteria': criteria})) %}
{% if app.request.query.get('sorting').name is defined and app.request.query.get('sorting').name == 'asc'%}
{% set current_sorting_label = 'sylius.ui.from_a_to_z'|trans|lower %}
{% set current_sorting_name = 'name' %}
{% set current_sorting_order = 'ASC' %}
{% elseif app.request.query.get('sorting').name is defined and app.request.query.get('sorting').name == 'desc'%}
{% set current_sorting_label = 'sylius.ui.from_z_to_a'|trans|lower %}
{% set current_sorting_name = 'name' %}
{% set current_sorting_order = 'DESC' %}
{% elseif app.request.query.get('sorting').price is defined and app.request.query.get('sorting').price == 'asc'%}
{% set current_sorting_label = 'sylius.ui.cheapest_first'|trans|lower %}
{% set current_sorting_name = 'variants.first.channelPricings.first.price' %}
{% set current_sorting_order = 'DESC' %}
{% elseif app.request.query.get('sorting').price is defined and app.request.query.get('sorting').price == 'desc' %}
{% set current_sorting_label = 'sylius.ui.most_expensive_first'|trans|lower %}
{% set current_sorting_name = 'variants.first.channelPricings.first.price' %}
{% set current_sorting_order = 'ASC' %}
{% endif %}
<div class="mb-3 col-12 d-flex flex-row-reverse ff-os-regular">
<a aria-expanded="false" aria-haspopup="true" class="btn btn-light dropdown-toggle" data-toggle="dropdown" href="#" id="dropdownMenuLink" role="button">
{{ 'group.sorting.dropdown.label'|trans }}
</a>
<div aria-labelledby="dropdownMenuLink" class="dropdown-menu dropdown-menu-right">
<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>
<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>
<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>
<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>
</div>
</div>
<div class="col-12 row px-0 mx-0">
{% if current_sorting_name|default(0) %}
{% for product in iterable|sort_by(current_sorting_name, current_sorting_order) %}
{% include 'app/Group/product.html.twig' with {'product': product, 'group': group} %}
{% endfor %}
{% else %}
{% for product in iterable %}
{% include 'app/Group/product.html.twig' with {'product': product, 'group': group} %}
{% endfor %}
{% endif %}
</div>