From f2b13dd0ec68da1e31bcf19517004036c19c40c2 Mon Sep 17 00:00:00 2001 From: Thibault Libioulle Date: Wed, 3 Nov 2021 17:30:27 +0000 Subject: [PATCH] [FIX] website{,_sale}: fix search product with several categories This commit fixes an issue when there are several public categories on a single product. Categories are shown side-by-side under product name in the search bar. This commit also fixes the issue where the `Category:X` text is matched and highlighted whereas the search text is not used to match the product categories. Steps to reproduce : - Install eCommerce - Add several eCommerce Categories to a product - Go to shop - Search for the product in the searchbar - Traceback Current Behavior : - Traceback when generating the results in the quick search bar. It's not expected to have several categories in the current implementation. - If all products have a unique category, then the text in `Category:X` is matched and highlighted. Desired Behavior : - No traceback - When there are multiple categories, an extra link should be present on each category rather than a unique link on all categories. - The product categories don't have to be matched. Related PR: #79258 task-2680726 closes odoo/odoo#79363 Signed-off-by: Yannick Tivisse (yti) --- .../website/static/src/snippets/s_searchbar/000.xml | 2 ++ addons/website/views/website_templates.xml | 2 ++ addons/website_sale/models/product_template.py | 10 +++++----- addons/website_sale/views/templates.xml | 11 +++++++++++ 4 files changed, 20 insertions(+), 5 deletions(-) diff --git a/addons/website/static/src/snippets/s_searchbar/000.xml b/addons/website/static/src/snippets/s_searchbar/000.xml index 11318eb5a93..d82521ce96d 100644 --- a/addons/website/static/src/snippets/s_searchbar/000.xml +++ b/addons/website/static/src/snippets/s_searchbar/000.xml @@ -20,9 +20,11 @@
+

diff --git a/addons/website/views/website_templates.xml b/addons/website/views/website_templates.xml index eec3f871774..6bd7f603d10 100644 --- a/addons/website/views/website_templates.xml +++ b/addons/website/views/website_templates.xml @@ -2568,10 +2568,12 @@ Sitemap: sitemap.xml
+

diff --git a/addons/website_sale/models/product_template.py b/addons/website_sale/models/product_template.py index a8e488e647c..a50e6fc25a1 100644 --- a/addons/website_sale/models/product_template.py +++ b/addons/website_sale/models/product_template.py @@ -375,8 +375,7 @@ class ProductTemplate(models.Model): mapping['detail'] = {'name': 'price', 'type': 'html', 'display_currency': options['display_currency']} mapping['detail_strike'] = {'name': 'list_price', 'type': 'html', 'display_currency': options['display_currency']} if with_category: - mapping['extra_link'] = {'name': 'category', 'type': 'text', 'match': True} - mapping['extra_link_url'] = {'name': 'category_url', 'type': 'text'} + mapping['extra_link'] = {'name': 'category', 'type': 'html'} return { 'model': 'product.template', 'base_domain': domains, @@ -401,9 +400,10 @@ class ProductTemplate(models.Model): if with_image: data['image_url'] = '/web/image/product.template/%s/image_128' % data['id'] if with_category and product.public_categ_ids: - data['category'] = _('Category: %s', product.public_categ_ids.name) - slugs = [slug(category) for category in product.public_categ_ids] - data['category_url'] = '/shop/category/%s' % ','.join(slugs) + data['category'] = self.env['ir.ui.view'].sudo()._render_template( + "website_sale.product_category_extra_link", + {'categories': product.public_categ_ids, 'slug': slug} + ) return results_data @api.model diff --git a/addons/website_sale/views/templates.xml b/addons/website_sale/views/templates.xml index 9d4d7710fe3..4ed8f433ee8 100644 --- a/addons/website_sale/views/templates.xml +++ b/addons/website_sale/views/templates.xml @@ -1985,4 +1985,15 @@ + +