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
This commit is contained in:
parent
b38339c979
commit
f1ce418bdc
@ -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)
|
||||
|
@ -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
|
||||
|
@ -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:
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -53,68 +53,72 @@
|
||||
<div class="mb-4 filters-title" > {{ _('Filters') }} </div>
|
||||
<a class="mb-4 clear-filters" href="/all-products">{{ _('Clear All') }}</a>
|
||||
</div>
|
||||
{% for field_filter in field_filters %}
|
||||
{%- set item_field = field_filter[0] %}
|
||||
{%- set values = field_filter[1] %}
|
||||
<div class="mb-4 filter-block pb-5">
|
||||
<div class="filter-label mb-3">{{ item_field.label }}</div>
|
||||
{% if field_filters %}
|
||||
{% for field_filter in field_filters %}
|
||||
{%- set item_field = field_filter[0] %}
|
||||
{%- set values = field_filter[1] %}
|
||||
<div class="mb-4 filter-block pb-5">
|
||||
<div class="filter-label mb-3">{{ item_field.label }}</div>
|
||||
|
||||
{% if values | len > 20 %}
|
||||
<!-- show inline filter if values more than 20 -->
|
||||
<input type="text" class="form-control form-control-sm mb-2 product-filter-filter"/>
|
||||
{% endif %}
|
||||
{% if values | len > 20 %}
|
||||
<!-- show inline filter if values more than 20 -->
|
||||
<input type="text" class="form-control form-control-sm mb-2 product-filter-filter"/>
|
||||
{% endif %}
|
||||
|
||||
{% if values %}
|
||||
<div class="filter-options">
|
||||
{% for value in values %}
|
||||
<div class="checkbox" data-value="{{ value }}">
|
||||
<label for="{{value}}">
|
||||
<input type="checkbox"
|
||||
class="product-filter field-filter"
|
||||
id="{{value}}"
|
||||
data-filter-name="{{ item_field.fieldname }}"
|
||||
data-filter-value="{{ value }}"
|
||||
>
|
||||
<span class="label-area">{{ value }}</span>
|
||||
</label>
|
||||
{% if values %}
|
||||
<div class="filter-options">
|
||||
{% for value in values %}
|
||||
<div class="checkbox" data-value="{{ value }}">
|
||||
<label for="{{value}}">
|
||||
<input type="checkbox"
|
||||
class="product-filter field-filter"
|
||||
id="{{value}}"
|
||||
data-filter-name="{{ item_field.fieldname }}"
|
||||
data-filter-value="{{ value }}"
|
||||
>
|
||||
<span class="label-area">{{ value }}</span>
|
||||
</label>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% endfor %}
|
||||
{% else %}
|
||||
<i class="text-muted">{{ _('No values') }}</i>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% else %}
|
||||
<i class="text-muted">{{ _('No values') }}</i>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endfor %}
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
|
||||
{% for attribute in attribute_filters %}
|
||||
<div class="mb-4 filter-block pb-5">
|
||||
<div class="filter-label mb-3">{{ attribute.name}}</div>
|
||||
{% if values | len > 20 %}
|
||||
<!-- show inline filter if values more than 20 -->
|
||||
<input type="text" class="form-control form-control-sm mb-2 product-filter-filter"/>
|
||||
{% endif %}
|
||||
{% if attribute_filters %}
|
||||
{% for attribute in attribute_filters %}
|
||||
<div class="mb-4 filter-block pb-5">
|
||||
<div class="filter-label mb-3">{{ attribute.name}}</div>
|
||||
{% if values | len > 20 %}
|
||||
<!-- show inline filter if values more than 20 -->
|
||||
<input type="text" class="form-control form-control-sm mb-2 product-filter-filter"/>
|
||||
{% endif %}
|
||||
|
||||
{% if attribute.item_attribute_values %}
|
||||
<div class="filter-options">
|
||||
{% for attr_value in attribute.item_attribute_values %}
|
||||
<div class="checkbox">
|
||||
<label>
|
||||
<input type="checkbox"
|
||||
class="product-filter attribute-filter"
|
||||
id="{{attr_value}}"
|
||||
data-attribute-name="{{ attribute.name }}"
|
||||
data-attribute-value="{{ attr_value }}"
|
||||
{% if attr_value.checked %} checked {% endif %}>
|
||||
<span class="label-area">{{ attr_value }}</span>
|
||||
</label>
|
||||
{% if attribute.item_attribute_values %}
|
||||
<div class="filter-options">
|
||||
{% for attr_value in attribute.item_attribute_values %}
|
||||
<div class="checkbox">
|
||||
<label data-value="{{ value }}">
|
||||
<input type="checkbox"
|
||||
class="product-filter attribute-filter"
|
||||
id="{{attr_value.name}}"
|
||||
data-attribute-name="{{ attribute.name }}"
|
||||
data-attribute-value="{{ attr_value.attribute_value }}"
|
||||
{% if attr_value.checked %} checked {% endif %}>
|
||||
<span class="label-area">{{ attr_value.attribute_value }}</span>
|
||||
</label>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% endfor %}
|
||||
{% else %}
|
||||
<i class="text-muted">{{ _('No values') }}</i>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% else %}
|
||||
<i class="text-muted">{{ _('No values') }}</i>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endfor %}
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
<script>
|
||||
|
Loading…
x
Reference in New Issue
Block a user