Skip to content

Commit

Permalink
[ADD] website_sale_ux: allow to disable categories on shop search
Browse files Browse the repository at this point in the history
closes #249

Signed-off-by: Juan Ignacio Rivero <jr@adhoc.com.ar>
  • Loading branch information
jjscarafia committed May 29, 2023
1 parent 260efaf commit 2764bce
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 1 deletion.
1 change: 1 addition & 0 deletions website_sale_ux/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Website Sale UX
* If the product has variants, when users click the Add to cart button then they are redirected to the Product page (new feature) so they could choice among all variants, instead of opening the pop-up to choice among all variants (default behaviour). This new feature is required because "variant pop-up" shows a malfunction when user tries to add to cart a bigger quantity of a variant product than stock available.
#. By default, on Settings > Website the option Customer account (which set Free sign up option or By invitation on website) is not able. This module adds this setting option per website.
#. Rename "All products" to "All categories" in categories left snippet on shop
#. Add an option to disable returning categories on shop search bar. To do so you need to go to website settings and check option "Disable Categories Search"

Installation
============
Expand Down
1 change: 1 addition & 0 deletions website_sale_ux/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
# directory
##############################################################################
from . import res_config_settings
from . import website
4 changes: 3 additions & 1 deletion website_sale_ux/models/res_config_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@
# For copyright and license notices, see __manifest__.py file in module root
# directory
##############################################################################
from odoo import models, api
from odoo import models, api, fields


class ResConfigSettings(models.TransientModel):
_inherit = 'res.config.settings'

disable_categories_search = fields.Boolean(related='website_id.disable_categories_search', readonly=False)

@api.model
def _inverse_account_on_checkout(self):
for record in self:
Expand Down
28 changes: 28 additions & 0 deletions website_sale_ux/models/website.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
##############################################################################
# For copyright and license notices, see __manifest__.py file in module root
# directory
##############################################################################
from odoo import models, tools, fields


class Website(models.Model):

_inherit = "website"

disable_categories_search = fields.Boolean()

def _search_get_details(self, search_type, order, options):
res = super(Website, self)._search_get_details(search_type, order, options)
if search_type == 'products' and self.sudo()._get_disable_categories_search():
# borrar el elemento no es lo más elegante pero no vi otra forma facil
# de heredar. no es caro en temas de performance ya que el metodo super
# es super liviano (no hace busquedas ni nada)
for idx, item in enumerate(res):
if item.get('model') == 'product.public.category':
res.pop(idx)
return res

@tools.ormcache('self.id')
def _get_disable_categories_search(self):
self.ensure_one()
return self.disable_categories_search
13 changes: 13 additions & 0 deletions website_sale_ux/views/res_config_settings_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,19 @@
</div>
</div>
</xpath>
<div id="sale_product_catalog_settings">
<div class="col-12 col-lg-6 o_setting_box">
<div class="o_setting_left_pane">
<field name="disable_categories_search"/>
</div>
<div class="o_setting_right_pane">
<label for="disable_categories_search"/>
<div class="text-muted">
Disable search by categories on shop searchbar
</div>
</div>
</div>
</div>
</field>
</record>
</odoo>

0 comments on commit 2764bce

Please sign in to comment.