diff --git a/website_hide_button/controllers/website_sale.py b/website_hide_button/controllers/website_sale.py index 98f33d8d1..10b5e266c 100644 --- a/website_hide_button/controllers/website_sale.py +++ b/website_hide_button/controllers/website_sale.py @@ -27,6 +27,30 @@ from odoo.addons.website_sale.controllers.main import WebsiteSale class WebsiteSaleInherit(WebsiteSale): """class to hide price, add to cart and quantity""" + def should_show_price_for_current_website(self): + """ + Check if price should be SHOWN for the current website + Returns: True if price should be shown, False if should be hidden + """ + # If hide_price setting is not enabled, show price + if not request.env['ir.config_parameter'].sudo().get_param('website_hide_button.hide_price'): + return True + + hide_type = request.env['ir.config_parameter'].sudo().get_param('website_hide_button.hide_type') + website_ids_param = request.env['ir.config_parameter'].sudo().get_param('website_hide_button.website_ids') or '' + website_ids = [int(w) for w in website_ids_param.split(',') if w] + current_website = request.env['website'].get_current_website() + + if hide_type == 'all': + # Hide price on ALL websites + return False + else: + # Hide price only on specific websites + if current_website.id in website_ids: + return False # Hide on this website + else: + return True # Show on other websites + @http.route([ '''/shop''', '''/shop/page/''', @@ -42,7 +66,8 @@ class WebsiteSaleInherit(WebsiteSale): res.qcontext.update({ 'login_user': True if request.env.user._is_public() and request.env[ 'ir.config_parameter'].sudo().get_param( - 'website_hide_button.hide_cart') else False + 'website_hide_button.hide_cart') else False, + 'show_price': self.should_show_price_for_current_website() }) return res @@ -56,6 +81,7 @@ class WebsiteSaleInherit(WebsiteSale): request.env[ 'ir.config_parameter'].sudo().get_param( 'website_hide_button.hide_cart') else False + res['show_price'] = self.should_show_price_for_current_website() return res @http.route() @@ -64,10 +90,7 @@ class WebsiteSaleInherit(WebsiteSale): creation will be disabled """ user = http.request.env.user if ( - not user._is_public() or user._is_public() and not request.env.user._is_public() and not - request.env[ - 'ir.config_parameter'].sudo().get_param( - 'website_hide_button.hide_cart')) and user.has_group( + not user._is_public() or user._is_public() and not request.env.user._is_public() and self.should_show_price_for_current_website()) and user.has_group( 'base.group_portal') or \ user.has_group('base.group_user'): res = super(WebsiteSaleInherit, self).shop_payment(**post) diff --git a/website_hide_button/models/res_config_settings.py b/website_hide_button/models/res_config_settings.py index 2471fbb1f..14d7d08ab 100755 --- a/website_hide_button/models/res_config_settings.py +++ b/website_hide_button/models/res_config_settings.py @@ -19,7 +19,7 @@ # If not, see . # ################################################################################ -from odoo import api, fields, models +from odoo import api, fields, models, Command class ResConfigSettings(models.TransientModel): @@ -31,6 +31,19 @@ class ResConfigSettings(models.TransientModel): hide_price = fields.Boolean(string='Hide Price', config_parameter='website_hide_button.hide_price', help="If enabled, the price of product will not be visible to guest users in website") + hide_type = fields.Selection( + [('all', 'All Websites'), ('selected', 'Selected Websites')], + string='Apply To', + config_parameter='website_hide_button.hide_type', + default='all', + help="Choose whether to apply the hide settings to all websites or only selected websites" + ) + # Changed from Many2many to Char to store comma-separated website IDs + website_ids = fields.Many2many( + 'website', + string='Websites', + help="Select the websites where price and cart should be hidden for guest users" + ) hide_cart = fields.Boolean(string='Hide Cart', config_parameter='website_hide_button.hide_cart', help="If enabled, the Add to Cart button and Cart Icon will be visible to guest users") @@ -38,10 +51,42 @@ class ResConfigSettings(models.TransientModel): def set_values(self): """Method for setting the parameters""" super(ResConfigSettings, self).set_values() - self.env['ir.config_parameter'].sudo().set_param( - 'website_hide_button.hide_price', self.hide_price) - self.env['ir.config_parameter'].sudo().set_param( - 'website_hide_button.hide_cart', self.hide_cart) + params = self.env['ir.config_parameter'].sudo() + + params.set_param('website_hide_button.hide_price', self.hide_price) + params.set_param('website_hide_button.hide_cart', self.hide_cart) + params.set_param('website_hide_button.hide_type', self.hide_type) + + # Store website_ids as comma-separated string + website_ids_str = ','.join(map(str, self.website_ids.ids)) if self.website_ids else '' + params.set_param('website_hide_button.website_ids', website_ids_str) + + @api.model + def get_values(self): + """Method for getting the parameters""" + res = super(ResConfigSettings, self).get_values() + params = self.env['ir.config_parameter'].sudo() + + hide_price = params.get_param('website_hide_button.hide_price', default=False) + hide_cart = params.get_param('website_hide_button.hide_cart', default=False) + hide_type = params.get_param('website_hide_button.hide_type', default='all') + website_ids_str = params.get_param('website_hide_button.website_ids', default='') + + # Convert string to list of integers + website_ids = [] + if website_ids_str: + try: + website_ids = [int(x) for x in website_ids_str.split(',') if x] + except ValueError: + website_ids = [] + + res.update({ + 'hide_price': hide_price, + 'hide_cart': hide_cart, + 'hide_type': hide_type, + 'website_ids': [(6, 0, website_ids)], + }) + return res @api.model def get_smartsupp_details(self): @@ -61,3 +106,8 @@ class ResConfigSettings(models.TransientModel): self.hide_cart = True self.env['ir.config_parameter'].sudo().set_param( 'website_hide_button.hide_cart', self.hide_cart) + + def _onchange_hide_type(self): + """Clear website_ids when changing to 'all' using Command format""" + if self.hide_type == 'all': + self.website_ids = [Command.clear()] diff --git a/website_hide_button/static/description/assets/screenshots/0.png b/website_hide_button/static/description/assets/screenshots/0.png index 75f400c00..f5dc16fc2 100644 Binary files a/website_hide_button/static/description/assets/screenshots/0.png and b/website_hide_button/static/description/assets/screenshots/0.png differ diff --git a/website_hide_button/static/description/assets/screenshots/1.png b/website_hide_button/static/description/assets/screenshots/1.png index c25af2963..46d729a8d 100644 Binary files a/website_hide_button/static/description/assets/screenshots/1.png and b/website_hide_button/static/description/assets/screenshots/1.png differ diff --git a/website_hide_button/static/description/assets/screenshots/2.png b/website_hide_button/static/description/assets/screenshots/2.png index e574a95af..9714bdf9f 100644 Binary files a/website_hide_button/static/description/assets/screenshots/2.png and b/website_hide_button/static/description/assets/screenshots/2.png differ diff --git a/website_hide_button/static/description/assets/screenshots/3.png b/website_hide_button/static/description/assets/screenshots/3.png index cabf919ee..c25af2963 100644 Binary files a/website_hide_button/static/description/assets/screenshots/3.png and b/website_hide_button/static/description/assets/screenshots/3.png differ diff --git a/website_hide_button/static/description/assets/screenshots/4.png b/website_hide_button/static/description/assets/screenshots/4.png index b203d7e12..e574a95af 100644 Binary files a/website_hide_button/static/description/assets/screenshots/4.png and b/website_hide_button/static/description/assets/screenshots/4.png differ diff --git a/website_hide_button/static/description/assets/screenshots/5.png b/website_hide_button/static/description/assets/screenshots/5.png new file mode 100644 index 000000000..cabf919ee Binary files /dev/null and b/website_hide_button/static/description/assets/screenshots/5.png differ diff --git a/website_hide_button/static/description/assets/screenshots/6.png b/website_hide_button/static/description/assets/screenshots/6.png new file mode 100644 index 000000000..b203d7e12 Binary files /dev/null and b/website_hide_button/static/description/assets/screenshots/6.png differ diff --git a/website_hide_button/static/description/index.html b/website_hide_button/static/description/index.html index f7ea5954c..c61014424 100644 --- a/website_hide_button/static/description/index.html +++ b/website_hide_button/static/description/index.html @@ -167,7 +167,7 @@

- The user can enable the 'Hide Cart for Guests' and 'Hide Product Prices from Guests' options in the general settings of the Website module.

+ The user can enable 'Hide Product Prices for Guests', which will also turn on 'Hide Cart from Guests'. They can then choose to apply it to all websites or only specific websites.
@@ -180,6 +180,38 @@ class="img-responsive" width="100%" height="auto"> +
+

+ If the chosen option is "All Websites", it means that the price and cart will be hidden for guest users on all websites.

+
+ + +
+
+
+ +
+
+

+ If the chosen option is "Selected Websites", another field will appear where you can specify the websites on which the price and cart will be hidden for guest users. This feature will be applied only to the selected websites.

+
+
+
+
+
+
+ +

@@ -193,7 +225,7 @@
-
@@ -211,7 +243,7 @@
-
@@ -222,7 +254,7 @@ in Shop page.

-
diff --git a/website_hide_button/views/product_templates.xml b/website_hide_button/views/product_templates.xml index cb464c188..2678a98da 100644 --- a/website_hide_button/views/product_templates.xml +++ b/website_hide_button/views/product_templates.xml @@ -12,8 +12,7 @@ not request.env.user._is_public() or - (request.env.user._is_public() and not - request.env['ir.config_parameter'].sudo().get_param('website_hide_button.hide_cart')) + (request.env.user._is_public() and show_price) @@ -27,8 +26,7 @@ @@ -37,15 +35,14 @@ inherit_id="website_sale.header_cart_link"> not request.env.user._is_public() or - (request.env.user._is_public() and not - request.env['ir.config_parameter'].sudo().get_param('website_hide_button.hide_cart')) + (request.env.user._is_public() and show_price) @@ -72,8 +68,7 @@ product.product_variant_ids and (not request.env.user._is_public() or (request.env.user._is_public() - and not - request.env['ir.config_parameter'].sudo().get_param('website_hide_button.hide_price'))) + and show_price)) product.product_variant_ids and (not request.env.user._is_public() or (request.env.user._is_public() - and not - request.env['ir.config_parameter'].sudo().get_param('website_hide_button.hide_price'))) + and show_price)) @@ -93,8 +87,7 @@ position="attributes"> not request.env.user._is_public() or - (request.env.user._is_public() and not - request.env['ir.config_parameter'].sudo().get_param('website_hide_button.hide_cart')) + (request.env.user._is_public() and show_price) @@ -104,8 +97,7 @@ website and (not request.env.user._is_public() or - (request.env.user._is_public() and not - request.env['ir.config_parameter'].sudo().get_param('website_hide_button.hide_price'))) + (request.env.user._is_public() and show_price)) @@ -114,8 +106,7 @@ inherit_id="website_sale.price_dynamic_filter_template_product_product"> (not request.env.user._is_public() or - (request.env.user._is_public() and not - request.env['ir.config_parameter'].sudo().get_param('website_hide_button.hide_price'))) + (request.env.user._is_public() and show_price)) @@ -125,8 +116,7 @@ not request.env.user._is_public() or - (request.env.user._is_public() and not - request.env['ir.config_parameter'].sudo().get_param('website_hide_button.hide_price')) + (request.env.user._is_public() and show_price) diff --git a/website_hide_button/views/res_config_settings_views.xml b/website_hide_button/views/res_config_settings_views.xml index 56d8bd50f..2b706faed 100755 --- a/website_hide_button/views/res_config_settings_views.xml +++ b/website_hide_button/views/res_config_settings_views.xml @@ -13,6 +13,39 @@ string="Hide Product Prices for Guests" help="Hides product prices from guest users in Website"> + +
+ + +
+
+ +
+
+ +
+ + Product prices and cart will be hidden for guest users on all websites. +
+ +
+ + Product prices and cart will be hidden for guest users on selected websites only. +
+ +
+ + Please select at least one website to apply this feature. +
+
diff --git a/website_hide_button/views/shop_templates.xml b/website_hide_button/views/shop_templates.xml index 0757ce323..d8859207f 100644 --- a/website_hide_button/views/shop_templates.xml +++ b/website_hide_button/views/shop_templates.xml @@ -5,9 +5,7 @@ not request.env.user._is_public() or ( - request.env.user._is_public() and not request.env[ - 'ir.config_parameter'].sudo().get_param( - 'website_hide_button.hide_price')) + request.env.user._is_public() and show_price)