From f1ce418bdc0c3c522ffce58e79c92ad4a2dda079 Mon Sep 17 00:00:00 2001 From: marination Date: Fri, 19 Feb 2021 15:56:52 +0530 Subject: [PATCH] fix: Hide Attribute filters if 'Hide Variants' is enabled in E Commerce Settings - Hide Attribute filters if 'Hide Variants' is enabled in E Commerce Settings - Consider 'Hide Variants' in ProductQuery Engine - Added docstrings - Remove `get_e_commerce_settings`, redundant --- .../doctype/website_item/website_item.py | 1 + erpnext/portal/product_configurator/utils.py | 12 -- erpnext/shopping_cart/filters.py | 8 +- erpnext/shopping_cart/product_query.py | 6 +- erpnext/stock/doctype/item/item.py | 3 +- erpnext/www/all-products/index.html | 112 +++++++++--------- 6 files changed, 71 insertions(+), 71 deletions(-) diff --git a/erpnext/e_commerce/doctype/website_item/website_item.py b/erpnext/e_commerce/doctype/website_item/website_item.py index 53ed5e8891..64655716b4 100644 --- a/erpnext/e_commerce/doctype/website_item/website_item.py +++ b/erpnext/e_commerce/doctype/website_item/website_item.py @@ -326,6 +326,7 @@ class WebsiteItem(WebsiteGenerator): row.description = desc def invalidate_cache_for_web_item(doc): + """Invalidate Website Item Group cache and rebuild ItemVariantsCacheManager.""" from erpnext.stock.doctype.item.item import invalidate_item_variants_cache_for_website invalidate_cache_for(doc, doc.item_group) diff --git a/erpnext/portal/product_configurator/utils.py b/erpnext/portal/product_configurator/utils.py index 0de97294f3..7ce8f805d4 100644 --- a/erpnext/portal/product_configurator/utils.py +++ b/erpnext/portal/product_configurator/utils.py @@ -138,15 +138,3 @@ def get_item_attributes(item_code): return attributes -def get_html_for_items(items): - html = [] - for item in items: - html.append(frappe.render_template('erpnext/www/all-products/item_row.html', { - 'item': item - })) - return html - -def get_e_commerce_settings(): - doc = frappe.get_cached_doc('E Commerce Settings') - doc.products_per_page = doc.products_per_page or 20 - return doc diff --git a/erpnext/shopping_cart/filters.py b/erpnext/shopping_cart/filters.py index 4fe346b659..f074081ba3 100644 --- a/erpnext/shopping_cart/filters.py +++ b/erpnext/shopping_cart/filters.py @@ -1,8 +1,6 @@ -# Copyright (c) 2020, Frappe Technologies Pvt. Ltd. and Contributors +# Copyright (c) 2021, Frappe Technologies Pvt. Ltd. and Contributors # License: GNU General Public License v3. See license.txt -from __future__ import unicode_literals - import frappe @@ -16,6 +14,8 @@ class ProductFiltersBuilder: self.item_group = item_group def get_field_filters(self): + if not self.doc.enable_field_filters: return + filter_fields = [row.fieldname for row in self.doc.filter_fields] meta = frappe.get_meta('Item') @@ -56,6 +56,8 @@ class ProductFiltersBuilder: return filter_data def get_attribute_filters(self): + if not self.doc.enable_attribute_filters: return + attributes = [row.attribute for row in self.doc.filter_attributes] if not attributes: diff --git a/erpnext/shopping_cart/product_query.py b/erpnext/shopping_cart/product_query.py index 140e1c6b38..a2d2994bc1 100644 --- a/erpnext/shopping_cart/product_query.py +++ b/erpnext/shopping_cart/product_query.py @@ -42,6 +42,9 @@ class ProductQuery: if fields: self.build_fields_filters(fields) if search_term: self.build_search_filters(search_term) + if self.settings.hide_variants: + self.conditions += " and wi.variant_of is null" + result = [] website_item_groups = [] @@ -53,7 +56,6 @@ class ProductQuery: filters=[["Website Item Group", "item_group", "=", item_group]] ) - self.query_fields = (", ").join(self.fields) if attributes: result = self.query_items_with_attributes(attributes, start) else: @@ -70,6 +72,8 @@ class ProductQuery: def query_items(self, conditions, or_conditions, substitutions, start=0): """Build a query to fetch Website Items based on field filters.""" + self.query_fields = (", ").join(self.fields) + return frappe.db.sql(""" select distinct {query_fields} from diff --git a/erpnext/stock/doctype/item/item.py b/erpnext/stock/doctype/item/item.py index ebc3276014..2185694d60 100644 --- a/erpnext/stock/doctype/item/item.py +++ b/erpnext/stock/doctype/item/item.py @@ -23,7 +23,6 @@ from frappe.utils import ( from frappe.utils.html_utils import clean_html from frappe.website.utils import clear_cache from frappe.model.document import Document -from frappe.website.website_generator import WebsiteGenerator import erpnext from erpnext.controllers.item_variant import ( @@ -858,6 +857,7 @@ def get_last_purchase_details(item_code, doc_name=None, conversion_rate=1.0): def invalidate_cache_for_item(doc): + """Invalidate Item Group cache and rebuild ItemVariantsCacheManager.""" invalidate_cache_for(doc, doc.item_group) if doc.get("old_item_group") and doc.get("old_item_group") != doc.item_group: @@ -867,6 +867,7 @@ def invalidate_cache_for_item(doc): def invalidate_item_variants_cache_for_website(doc): + """Rebuild ItemVariantsCacheManager via Item or Website Item.""" from erpnext.portal.product_configurator.item_variants_cache import ItemVariantsCacheManager item_code = None diff --git a/erpnext/www/all-products/index.html b/erpnext/www/all-products/index.html index a7838eebc1..d32ef62275 100644 --- a/erpnext/www/all-products/index.html +++ b/erpnext/www/all-products/index.html @@ -53,68 +53,72 @@
{{ _('Filters') }}
{{ _('Clear All') }} - {% for field_filter in field_filters %} - {%- set item_field = field_filter[0] %} - {%- set values = field_filter[1] %} -
-
{{ item_field.label }}
+ {% if field_filters %} + {% for field_filter in field_filters %} + {%- set item_field = field_filter[0] %} + {%- set values = field_filter[1] %} +
+
{{ item_field.label }}
- {% if values | len > 20 %} - - - {% endif %} + {% if values | len > 20 %} + + + {% endif %} - {% if values %} -
- {% for value in values %} -
- + {% if values %} +
+ {% for value in values %} +
+ +
+ {% endfor %}
- {% endfor %} + {% else %} + {{ _('No values') }} + {% endif %}
- {% else %} - {{ _('No values') }} - {% endif %} -
- {% endfor %} + {% endfor %} + {% endif %} - {% for attribute in attribute_filters %} -
-
{{ attribute.name}}
- {% if values | len > 20 %} - - - {% endif %} + {% if attribute_filters %} + {% for attribute in attribute_filters %} +
+
{{ attribute.name}}
+ {% if values | len > 20 %} + + + {% endif %} - {% if attribute.item_attribute_values %} -
- {% for attr_value in attribute.item_attribute_values %} -
- + {% if attribute.item_attribute_values %} +
+ {% for attr_value in attribute.item_attribute_values %} +
+ +
+ {% endfor %}
- {% endfor %} + {% else %} + {{ _('No values') }} + {% endif %}
- {% else %} - {{ _('No values') }} - {% endif %} -
- {% endfor %} + {% endfor %} + {% endif %}