[ADD] Manage product category visibility on website by partners/customers tags!

If specific tag(s) of partner/customer matches with product category's ``Partner Tags`` field then,
that product category will be visible to that partner/customer in website/E-commerce.

Partner Tags Hierarchy will also work...
For Ex.
-> ``Partner`` is Parent Tag
-> ``Partner/Gold`` is Child Tag

If Any Partner/Customer which have Tag of ``Partner``,
then automatically it'll also shows the prodcut category with ``Partner/Gold``,
because ``Partner/Gold`` is Child Of ``Partner`` tag.

Also, If Main Product Category have Partner Tag then that tag will automatically apply to its Child Category & their products.

For More Info: Issue - https://gitlab.com/flectra-hq/flectra/issues/45
This commit is contained in:
Siddharth Bhalgami 2018-03-23 15:37:12 +05:30
parent 85cc4448ea
commit 3c75c057d1
5 changed files with 57 additions and 4 deletions

View File

@ -239,7 +239,6 @@ class WebsiteSale(http.Controller):
compute_currency, pricelist_context, pricelist = self._get_compute_currency_and_context()
request.context = dict(request.context, pricelist=pricelist.id, partner=request.env.user.partner_id)
url = "/shop"
if search:
post["search"] = search
@ -252,7 +251,34 @@ class WebsiteSale(http.Controller):
if attrib_list:
post['attrib'] = attrib_list
categs = request.env['product.public.category'].search([('parent_id', '=', False), ('website_ids', 'in', request.website.id)])
current_partner_tags = request.context['partner'].category_id
partner_child_tags = request.env['res.partner.category'].search(
[('parent_id', 'in', current_partner_tags.ids)])
if not request.env.user.has_group('website.group_website_publisher'):
categs = request.env['product.public.category'].search(
[('parent_id', '=', False),
('website_ids', 'in', request.website.id),
'|', ('partner_tag_ids', 'in',
current_partner_tags.ids + partner_child_tags.ids),
('partner_tag_ids', '=', False)])
else:
categs = request.env['product.public.category'].search(
[('parent_id', '=', False),
('website_ids', 'in', request.website.id)])
categs_with_childs = request.env['product.public.category'].search(
[('website_ids', 'in', request.website.id),
'|', ('partner_tag_ids', 'in',
current_partner_tags.ids + partner_child_tags.ids),
('partner_tag_ids', '=', False)])
parent_categ_with_childs = request.env['product.public.category'].\
search([('parent_id', 'in', categs_with_childs.ids),
'|', ('partner_tag_ids', 'in',
current_partner_tags.ids + partner_child_tags.ids),
('partner_tag_ids', '=', False)])
Product = request.env['product.template']
parent_category_ids = []
@ -263,10 +289,16 @@ class WebsiteSale(http.Controller):
parent_category_ids.append(current_category.parent_id.id)
current_category = current_category.parent_id
if not request.env.user.has_group('website.group_website_publisher') \
and (categs_with_childs or parent_categ_with_childs):
domain += ['|', '&',
('public_categ_ids', 'in', categs_with_childs.ids),
('public_categ_ids', 'in', parent_categ_with_childs.ids),
('public_categ_ids', '=', False)]
product_count = Product.search_count(domain)
pager = request.website.pager(url=url, total=product_count, page=page, step=ppg, scope=7, url_args=post)
products = Product.search(domain, limit=ppg, offset=pager['offset'], order=self._get_search_order(post))
ProductAttribute = request.env['product.attribute']
ProductBrand = request.env['product.brand']
ProductTag = request.env['product.tags']
@ -302,6 +334,8 @@ class WebsiteSale(http.Controller):
'bins': TableCompute().process(products, ppg),
'rows': PPR,
'categories': categs,
'categories_with_child': categs_with_childs.ids +
parent_categ_with_childs.ids,
'attributes': attributes,
'compute_currency': compute_currency,
'keep': keep,

View File

@ -131,6 +131,17 @@ class ProductPublicCategory(models.Model):
string='Websites', copy=False,
help='List of websites in which '
'category will published.')
partner_tag_ids = fields.Many2many('res.partner.category',
'partner_public_categ_tags_rel',
'tag_id', 'category_id',
string='Partner Tags',
help='If logged in customers/partners '
'have this tag then this product '
'category will appear to them in '
'E-commerce website.\n\n'
'If empty then it becomes general '
'category which display to any '
'customers/partners.')
@api.model
def create(self, vals):

View File

@ -22,3 +22,4 @@ access_product_view_limit,access_product_view_limit,model_product_view_limit,,1,
access_product_ribbon,product_ribbon,model_product_ribbon,,1,0,0,0
access_product_tags,access_product_tags,model_product_tags,,1,0,0,0
access_product_brand,access_product_brand,model_product_brand,,1,0,0,0
access_res_partner_category_group_public,res_partner_category_group_public,base.model_res_partner_category,,1,0,0,0

1 id name model_id:id group_id:id perm_read perm_write perm_create perm_unlink
22 access_product_ribbon product_ribbon model_product_ribbon 1 0 0 0
23 access_product_tags access_product_tags model_product_tags 1 0 0 0
24 access_product_brand access_product_brand model_product_brand 1 0 0 0
25 access_res_partner_category_group_public res_partner_category_group_public base.model_res_partner_category 1 0 0 0

View File

@ -156,6 +156,7 @@
<field name="name"/>
<field name="parent_id"/>
<field name="sequence"/>
<field name="partner_tag_ids" widget="many2many_tags"/>
<field name="website_ids" widget="many2many_tags"/>
</group>
</div>

View File

@ -362,7 +362,13 @@
<!-- Add to cart button-->
<template id="categories_recursive" name="Category list">
<li t-att-class="'active' if c.id == int(category or 0) else None" t-if="website in c.website_ids or not c.website_ids">
<a t-att-href="keep('/shop/category/' + slug(c), category=0)" t-field="c.name"></a>
<t t-set="is_publisher" t-value="request.env['res.users'].has_group('website.group_website_publisher')" />
<t t-if="not is_publisher">
<a t-if="c.id in categories_with_child" t-att-href="keep('/shop/category/' + slug(c), category=0)" t-field="c.name"></a>
</t>
<t t-else="">
<a t-att-href="keep('/shop/category/' + slug(c), category=0)" t-field="c.name"></a>
</t>
<ul t-if="c.child_id" class="nav nav-pills nav-stacked nav-hierarchy">
<t t-foreach="c.child_id" t-as="c">
<t t-call="website_sale.categories_recursive" />