mirror of
https://github.com/frappe/erpnext.git
synced 2026-03-28 23:51:48 +01:00
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:
@@ -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)
|
||||
|
||||
@@ -136,15 +136,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
|
||||
|
||||
@@ -15,6 +15,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')
|
||||
@@ -52,6 +54,8 @@ class ProductFiltersBuilder:
|
||||
return filter_data
|
||||
|
||||
def get_attribute_fitlers(self):
|
||||
if not self.doc.enable_attribute_filters: return
|
||||
|
||||
attributes = [row.attribute for row in self.doc.filter_attributes]
|
||||
attribute_docs = [
|
||||
frappe.get_doc('Item Attribute', attribute) for attribute in attributes
|
||||
|
||||
@@ -40,9 +40,11 @@ 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 = []
|
||||
|
||||
self.query_fields = (", ").join(self.fields)
|
||||
if attributes:
|
||||
result = self.query_items_with_attributes(attributes, start)
|
||||
else:
|
||||
@@ -59,6 +61,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
|
||||
|
||||
@@ -18,7 +18,6 @@ from frappe.utils.html_utils import clean_html
|
||||
|
||||
from frappe.website.render import clear_cache
|
||||
from frappe.model.document import Document
|
||||
from frappe.website.website_generator import WebsiteGenerator
|
||||
|
||||
from six import iteritems
|
||||
|
||||
@@ -830,6 +829,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:
|
||||
@@ -839,6 +839,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 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>
|
||||
{% 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>
|
||||
|
||||
Reference in New Issue
Block a user