[IMP] website_sale: remove unnecessary param for collapse category
The parent categories can be retrieved directly from the current category by using the efficient `parents_and_self` field. This also prevents computing the parents on the controller for no reason when not using the collapse view. PR: #34249
This commit is contained in:
@@ -267,14 +267,8 @@ class WebsiteSale(http.Controller):
|
||||
search_categories = Category
|
||||
categs = Category.search([('parent_id', '=', False)] + request.website.website_domain())
|
||||
|
||||
parent_category_ids = []
|
||||
if category:
|
||||
url = "/shop/category/%s" % slug(category)
|
||||
parent_category_ids = [category.id]
|
||||
current_category = category
|
||||
while current_category.parent_id:
|
||||
parent_category_ids.append(current_category.parent_id.id)
|
||||
current_category = current_category.parent_id
|
||||
|
||||
product_count = len(search_product)
|
||||
pager = request.website.pager(url=url, total=product_count, page=page, step=ppg, scope=7, url_args=post)
|
||||
@@ -313,7 +307,6 @@ class WebsiteSale(http.Controller):
|
||||
'attributes': attributes,
|
||||
'compute_currency': compute_currency,
|
||||
'keep': keep,
|
||||
'parent_category_ids': parent_category_ids,
|
||||
'search_categories_ids': search_categories.ids,
|
||||
'layout_mode': layout_mode,
|
||||
}
|
||||
|
||||
@@ -370,11 +370,11 @@
|
||||
|
||||
<template id="option_collapse_categories_recursive" name="Collapse Category Recursive">
|
||||
<li class="nav-item">
|
||||
<i t-if="c.child_id" t-attf-class="text-primary fa #{'fa-chevron-down' if c.id in parent_category_ids else 'fa-chevron-right'}"
|
||||
t-attf-title="#{'Unfold' if c.id in parent_category_ids else 'Fold'}"
|
||||
t-attf-aria-label="#{'Unfold' if c.id in parent_category_ids else 'Fold'}" role="img"/>
|
||||
<i t-if="c.child_id" t-attf-class="text-primary fa #{'fa-chevron-down' if c.id in category.parents_and_self.ids else 'fa-chevron-right'}"
|
||||
t-attf-title="#{'Unfold' if c.id in category.parents_and_self.ids else 'Fold'}"
|
||||
t-attf-aria-label="#{'Unfold' if c.id in category.parents_and_self.ids else 'Fold'}" role="img"/>
|
||||
<a t-att-href="keep('/shop/category/' + slug(c), category=0)" t-attf-class="nav-link #{'active' if c.id == category.id else ''}" t-field="c.name"></a>
|
||||
<ul t-if="c.child_id" class="nav nav-pills flex-column nav-hierarchy" t-att-style="'display:block;' if c.id in parent_category_ids else 'display:none;'">
|
||||
<ul t-if="c.child_id" class="nav nav-pills flex-column nav-hierarchy" t-att-style="'display:block;' if c.id in category.parents_and_self.ids else 'display:none;'">
|
||||
<t t-foreach="c.child_id" t-as="c">
|
||||
<t t-if="not search or c.id in search_categories_ids">
|
||||
<t t-call="website_sale.option_collapse_categories_recursive"/>
|
||||
|
||||
Reference in New Issue
Block a user