Browse Source

Oct 10: [FIX] Bug fixed 'website_hide_button'

17.0
Risvana Cybro 4 days ago
parent
commit
036343affa
  1. 33
      website_hide_button/controllers/website_sale.py
  2. 60
      website_hide_button/models/res_config_settings.py
  3. BIN
      website_hide_button/static/description/assets/screenshots/0.png
  4. BIN
      website_hide_button/static/description/assets/screenshots/1.png
  5. BIN
      website_hide_button/static/description/assets/screenshots/2.png
  6. BIN
      website_hide_button/static/description/assets/screenshots/3.png
  7. BIN
      website_hide_button/static/description/assets/screenshots/4.png
  8. BIN
      website_hide_button/static/description/assets/screenshots/5.png
  9. BIN
      website_hide_button/static/description/assets/screenshots/6.png
  10. 40
      website_hide_button/static/description/index.html
  11. 32
      website_hide_button/views/product_templates.xml
  12. 33
      website_hide_button/views/res_config_settings_views.xml
  13. 4
      website_hide_button/views/shop_templates.xml

33
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/<int: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)

60
website_hide_button/models/res_config_settings.py

@ -19,7 +19,7 @@
# If not, see <http://www.gnu.org/licenses/>.
#
################################################################################
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()]

BIN
website_hide_button/static/description/assets/screenshots/0.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 126 KiB

After

Width:  |  Height:  |  Size: 140 KiB

BIN
website_hide_button/static/description/assets/screenshots/1.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 271 KiB

After

Width:  |  Height:  |  Size: 135 KiB

BIN
website_hide_button/static/description/assets/screenshots/2.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 235 KiB

After

Width:  |  Height:  |  Size: 128 KiB

BIN
website_hide_button/static/description/assets/screenshots/3.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 318 KiB

After

Width:  |  Height:  |  Size: 271 KiB

BIN
website_hide_button/static/description/assets/screenshots/4.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 324 KiB

After

Width:  |  Height:  |  Size: 235 KiB

BIN
website_hide_button/static/description/assets/screenshots/5.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 318 KiB

BIN
website_hide_button/static/description/assets/screenshots/6.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 324 KiB

40
website_hide_button/static/description/index.html

@ -167,7 +167,7 @@
<div class="px-3">
<h4 class="mt-2"
style=" font-weight:600 !important; color:#282F33 !important; font-size:1.3rem !important">
The user can enable the 'Hide Cart for Guests' and 'Hide Product Prices from Guests' options in the general settings of the Website module.</h4>
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.</h4>
</div>
</div>
</div>
@ -180,6 +180,38 @@
class="img-responsive" width="100%"
height="auto">
</div>
<div class="px-3">
<h4 class="mt-2"
style=" font-weight:600 !important; color:#282F33 !important; font-size:1.3rem !important">
If the chosen option is "All Websites", it means that the price and cart will be hidden for guest users on all websites.</h4>
</div>
</div>
</div>
<div class="col-lg-12 py-2"
style="padding: 1rem 4rem !important;">
<div
style="border: 1px solid #d8d6d6; border-radius: 4px; background: #fff; box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);">
<div class="row justify-content-center p-3 w-100 m-0">
<img src="assets/screenshots/2.png"
class="img-responsive" width="100%"
height="auto">
</div>
<div class="px-3">
<h4 class="mt-2"
style=" font-weight:600 !important; color:#282F33 !important; font-size:1.3rem !important">
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.</h4>
</div>
</div>
</div>
<div class="col-lg-12 py-2"
style="padding: 1rem 4rem !important;">
<div
style="border: 1px solid #d8d6d6; border-radius: 4px; background: #fff; box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);">
<div class="row justify-content-center p-3 w-100 m-0">
<img src="assets/screenshots/3.png"
class="img-responsive" width="100%"
height="auto">
</div>
<div class="px-3">
<h4 class="mt-2"
style=" font-weight:600 !important; color:#282F33 !important; font-size:1.3rem !important">
@ -193,7 +225,7 @@
<div
style="border: 1px solid #d8d6d6; border-radius: 4px; background: #fff; box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);">
<div class="row justify-content-center p-3 w-100 m-0">
<img src="assets/screenshots/2.png"
<img src="assets/screenshots/4.png"
class="img-responsive" width="100%"
height="auto">
</div>
@ -211,7 +243,7 @@
<div
style="border: 1px solid #d8d6d6; border-radius: 4px; background: #fff; box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);">
<div class="row justify-content-center p-3 w-100 m-0">
<img src="assets/screenshots/3.png"
<img src="assets/screenshots/5.png"
class="img-responsive" width="100%"
height="auto">
</div>
@ -222,7 +254,7 @@
in Shop page.</h4>
</div>
<div class="row justify-content-center p-3 w-100 m-0">
<img src="assets/screenshots/4.png"
<img src="assets/screenshots/6.png"
class="img-responsive" width="100%"
height="auto">
</div>

32
website_hide_button/views/product_templates.xml

@ -12,8 +12,7 @@
<xpath expr="//a[@id='add_to_cart']" position="attributes">
<attribute name="t-if">
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)
</attribute>
</xpath>
</template>
@ -27,8 +26,7 @@
<template id="product_price_hide" inherit_id="website_sale.product_price">
<xpath expr="//div[@itemprop='offers']" position="attributes">
<attribute name="t-if">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)
</attribute>
</xpath>
</template>
@ -37,15 +35,14 @@
inherit_id="website_sale.header_cart_link">
<xpath expr="//a[@href='/shop/cart']" position="attributes">
<attribute name="t-if">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)
</attribute>
</xpath>
</template>
<!-- Hide details section in search bar for hide price -->
<template id="search_hide" inherit_id="website_sale.search">
<xpath expr="//t[@t-set='display_detail']" position="replace">
<t t-if="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'))">
<t t-if="not request.env.user._is_public() or (request.env.user._is_public() and show_price)">
<t t-set="display_detail" t-valuef="true"/>
</t>
<t t-else="">
@ -60,8 +57,7 @@
position="attributes">
<attribute name="t-if">
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)
</attribute>
</xpath>
</template>
@ -72,8 +68,7 @@
<attribute name="t-if">
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))
</attribute>
</xpath>
<xpath expr="//div[hasclass('o_wsale_product_btn')]"
@ -81,8 +76,7 @@
<attribute name="t-if">
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))
</attribute>
</xpath>
</template>
@ -93,8 +87,7 @@
position="attributes">
<attribute name="t-if">
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)
</attribute>
</xpath>
</template>
@ -104,8 +97,7 @@
<xpath expr="//input[@name='search']" position="attributes">
<attribute name="t-att-data-display-price">
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))
</attribute>
</xpath>
</template>
@ -114,8 +106,7 @@
inherit_id="website_sale.price_dynamic_filter_template_product_product">
<xpath expr="//span[hasclass('fw-bold')]" position="attributes">
<attribute name="t-if">(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))
</attribute>
</xpath>
</template>
@ -125,8 +116,7 @@
<xpath expr="//t[@t-name='website_sale.badge_extra_price']"
position="attributes">
<attribute name="t-if">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)
</attribute>
</xpath>
</template>

33
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">
<field name="hide_price"/>
<!-- Content group that appears when hide_price is enabled -->
<div class="content-group mt16" invisible="hide_price == False">
<!-- Apply To Selection Field -->
<div class="row mt16">
<label for="hide_type" class="col-lg-3 o_light_label" string="Apply To"/>
<field name="hide_type" class="col-lg-9" widget="radio" options="{'horizontal': true}"/>
</div>
<!-- Website Selection Field (visible only when hide_type = 'selected') -->
<div class="row mt16" invisible="hide_type != 'selected'">
<label for="website_ids" class="col-lg-3 o_light_label" string="Select Websites"/>
<field name="website_ids"
class="col-lg-9"
widget="many2many_tags"
placeholder="Select websites where prices should be hidden..."
required="hide_type == 'selected'"/>
</div>
<!-- Info message for All Websites -->
<div class="alert alert-info mt16" invisible="hide_type != 'all'">
<i class="fa fa-info-circle"/>
<span> Product prices and cart will be hidden for guest users on <strong>all websites</strong>.</span>
</div>
<!-- Info message for Selected Websites -->
<div class="alert alert-info mt16" invisible="hide_type != 'selected' or not website_ids">
<i class="fa fa-info-circle"/>
<span> Product prices and cart will be hidden for guest users on <strong>selected websites only</strong>.</span>
</div>
<!-- Warning message when no websites selected -->
<div class="alert alert-warning mt16" invisible="hide_type != 'selected' or website_ids">
<i class="fa fa-warning"/>
<span> Please select at least one website to apply this feature.</span>
</div>
</div>
</setting>
<setting id="show_cart_setting" string="Hide Cart from Guests"
help="Hide 'Add to Cart' button and Cart quick view for Guest users">

4
website_hide_button/views/shop_templates.xml

@ -5,9 +5,7 @@
<xpath expr="//div[hasclass('product_price')]" position="attributes">
<attribute name="t-if">
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)
</attribute>
</xpath>
</template>

Loading…
Cancel
Save