Skip to content

Commit

Permalink
[FIX] website_sale: ensure applied filters are preserved when sorting
Browse files Browse the repository at this point in the history
Problem:
When generating sorting URLs, the `post` dictionary only contains
a single selected attribute. This is due to `request.params` only
passing the first `attrib` parameter during dispatch, even though
there can be multiple.

Solution:
Modify the `post` dictionary to store attributes as a list before
passing it to the `_shop_get_query_url_kwargs` method. This ensures
that all selected attributes are preserved and properly passed to the
`keep` query parameters.

Steps to reproduce:
- Go to `/shop`.
- Apply multiple attribute filters.
- Change the sorting option.
- Only the first selected attribute is applied in the filter.

opw-4244895

closes odoo#187890

X-original-commit: 99c7bdd
Signed-off-by: Valentin Chevalier <[email protected]>
Signed-off-by: Walid Sahli (wasa) <[email protected]>
  • Loading branch information
walidsahli committed Nov 20, 2024
1 parent 35ef4b2 commit 0f6370d
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions addons/website_sale/controllers/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ def _shop_lookup_products(self, attrib_set, options, post, search, website):
return fuzzy_search_term, product_count, search_result

def _shop_get_query_url_kwargs(
self, category, search, min_price, max_price, order=None, tags=None, **post
self, category, search, min_price, max_price, order=None, tags=None, attribute_value=None, **post
):
return {
'category': category,
Expand All @@ -220,6 +220,7 @@ def _shop_get_query_url_kwargs(
'min_price': min_price,
'max_price': max_price,
'order': order,
'attribute_value': attribute_value,
}

def _get_additional_shop_values(self, values):
Expand Down Expand Up @@ -276,6 +277,8 @@ def shop(self, page=0, category=None, search='', min_price=0.0, max_price=0.0, p
attrib_values = [[int(x) for x in v.split("-")] for v in attrib_list if v]
attributes_ids = {v[0] for v in attrib_values}
attrib_set = {v[1] for v in attrib_values}
if attrib_list:
post['attribute_value'] = attrib_list

filter_by_tags_enabled = website.is_view_active('website_sale.filter_products_tags')
if filter_by_tags_enabled:
Expand Down Expand Up @@ -316,8 +319,6 @@ def shop(self, page=0, category=None, search='', min_price=0.0, max_price=0.0, p
url = '/shop'
if search:
post['search'] = search
if attrib_list:
post['attribute_value'] = attrib_list

options = self._get_search_options(
category=category,
Expand Down

0 comments on commit 0f6370d

Please sign in to comment.