From dedb3ce9ba79eff98c48fe80039651519c4bccb2 Mon Sep 17 00:00:00 2001 From: Jeremy Kersten Date: Fri, 19 Aug 2016 11:45:25 +0200 Subject: [PATCH] [IMP] website_sale : add sort by Now you can sort products by lst_price, name, ... via the UI In some case the price list or b2b/b2c mode can altered the price and the sort on lst_price can be sometimes wrong. Eg: if price is displayed vat in (b2c), and mix rate of 6% and 21%, the sort will be done on the htva price. --- addons/website_sale/controllers/main.py | 3 +-- .../static/src/js/website_sale.js | 14 ++++++++++ addons/website_sale/views/templates.xml | 26 ++++++++++++++++++- 3 files changed, 40 insertions(+), 3 deletions(-) diff --git a/addons/website_sale/controllers/main.py b/addons/website_sale/controllers/main.py index de209207c71..c9eddfcacce 100644 --- a/addons/website_sale/controllers/main.py +++ b/addons/website_sale/controllers/main.py @@ -198,8 +198,7 @@ class WebsiteSale(http.Controller): domain = self._get_search_domain(search, category, attrib_values) - keep = QueryURL('/shop', category=category and int(category), search=search, attrib=attrib_list) - + keep = QueryURL('/shop', category=category and int(category), search=search, attrib=attrib_list, order=post.get('order')) pricelist_context = dict(request.env.context) if not pricelist_context.get('pricelist'): pricelist = request.website.get_current_pricelist() diff --git a/addons/website_sale/static/src/js/website_sale.js b/addons/website_sale/static/src/js/website_sale.js index bb4a6078c0a..cb7de7d51cb 100644 --- a/addons/website_sale/static/src/js/website_sale.js +++ b/addons/website_sale/static/src/js/website_sale.js @@ -339,6 +339,20 @@ odoo.define('website_sale.website_sale', function (require) { $(this).closest('tr').find('.js_quantity').val(0).trigger('change'); }); + if ($('.oe_website_sale .dropdown_sorty_by').length) { + // this method allow to keep current get param from the action, with new search query + $('.oe_website_sale .o_website_sale_search').on('submit', function (event) { + var $this = $(this); + if (!event.isDefaultPrevented() && !$this.is(".disabled")) { + event.preventDefault(); + var oldurl = $this.attr('action'); + oldurl += (oldurl.indexOf("?")===-1) ? "?" : ""; + var search = $this.find('input.search-query'); + window.location = oldurl + '&' + search.attr('name') + '=' + encodeURIComponent(search.val()); + } + }); + } + if ($(".checkout_autoformat").length) { $(oe_website_sale).on('change', "select[name='country_id']", function () { clickwatch(function() { diff --git a/addons/website_sale/views/templates.xml b/addons/website_sale/views/templates.xml index 5c3fe9e45e7..257773c9212 100644 --- a/addons/website_sale/views/templates.xml +++ b/addons/website_sale/views/templates.xml @@ -161,7 +161,7 @@
- pagination form-inline + pagination form-inline o_website_sale_search @@ -210,6 +210,30 @@ + + +