From 353a837d9a45d189e7abcc61231ab1e5bd9efdb7 Mon Sep 17 00:00:00 2001 From: "Achraf (abz)" Date: Mon, 27 Jun 2022 12:49:37 +0000 Subject: [PATCH] [FIX] website_sale: Prevent displaying categories from other websites Steps: - Go to website/configuration/ecommerce categories - Change `Chairs` website to `Website` - Go to `Website 2`/shop - Write `ch` in the search bar Autocomplete returns `Chairs` even if it's not available in `Website 2` opw-2884856 closes odoo/odoo#95219 X-original-commit: 2f99929accc4b71156d235019f7b78a2dd4c75e5 Signed-off-by: Achraf Signed-off-by: William Braeckman (wbr) --- addons/website_sale/models/product_public_category.py | 2 +- addons/website_sale/models/product_template.py | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/addons/website_sale/models/product_public_category.py b/addons/website_sale/models/product_public_category.py index 2dac4a3e867..23307f2af46 100644 --- a/addons/website_sale/models/product_public_category.py +++ b/addons/website_sale/models/product_public_category.py @@ -65,7 +65,7 @@ class ProductPublicCategory(models.Model): mapping['description'] = {'name': 'website_description', 'type': 'text', 'match': True, 'html': True} return { 'model': 'product.public.category', - 'base_domain': [], # categories are not website-specific + 'base_domain': [website.website_domain()], 'search_fields': search_fields, 'fetch_fields': fetch_fields, 'mapping': mapping, diff --git a/addons/website_sale/models/product_template.py b/addons/website_sale/models/product_template.py index 8fd48eece90..57c8377ac22 100644 --- a/addons/website_sale/models/product_template.py +++ b/addons/website_sale/models/product_template.py @@ -470,7 +470,9 @@ class ProductTemplate(models.Model): with_category = 'extra_link' in mapping with_price = 'detail' in mapping results_data = super()._search_render_results(fetch_fields, mapping, icon, limit) + current_website = self.env['website'].get_current_website() for product, data in zip(self, results_data): + categ_ids = product.public_categ_ids.filtered(lambda c: not c.website_id or c.website_id == current_website) if with_price: combination_info = product._get_combination_info(only_template=True) data['price'], list_price = self._search_render_results_prices( @@ -480,10 +482,10 @@ class ProductTemplate(models.Model): data['list_price'] = list_price if with_image: data['image_url'] = '/web/image/product.template/%s/image_128' % data['id'] - if with_category and product.public_categ_ids: + if with_category and categ_ids: data['category'] = self.env['ir.ui.view'].sudo()._render_template( "website_sale.product_category_extra_link", - {'categories': product.public_categ_ids, 'slug': slug} + {'categories': categ_ids, 'slug': slug} ) return results_data