mirror of
https://github.com/frappe/erpnext.git
synced 2026-06-03 04:09:11 +00:00
feat: Discount Filters
- Discount filters in filters section - Code cleanup
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
{% from "erpnext/templates/includes/macros.html" import attribute_filter_section, field_filter_section, discount_range_filters %}
|
||||
{% extends "templates/web.html" %}
|
||||
|
||||
{% block title %}{{ _('Products') }}{% endblock %}
|
||||
{% block header %}
|
||||
<div class="mb-6">{{ _('Products') }}</div>
|
||||
@@ -53,71 +55,19 @@
|
||||
<div class="mb-4 filters-title" > {{ _('Filters') }} </div>
|
||||
<a class="mb-4 clear-filters" href="/all-products">{{ _('Clear All') }}</a>
|
||||
</div>
|
||||
<!-- field filters -->
|
||||
{% 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 %}
|
||||
<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>
|
||||
{% else %}
|
||||
<i class="text-muted">{{ _('No values') }}</i>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endfor %}
|
||||
{{ field_filter_section(field_filters) }}
|
||||
{% endif %}
|
||||
|
||||
<!-- attribute filters -->
|
||||
{% 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 %}
|
||||
{{ attribute_filter_section(attribute_filters) }}
|
||||
{% 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>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% else %}
|
||||
<i class="text-muted">{{ _('No values') }}</i>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endfor %}
|
||||
<!-- discount filters -->
|
||||
{% if discount_filters %}
|
||||
{{ discount_range_filters(discount_filters) }}
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
|
||||
@@ -32,12 +32,16 @@ $(() => {
|
||||
if (this.attribute_filters[attribute_name].length === 0) {
|
||||
delete this.attribute_filters[attribute_name];
|
||||
}
|
||||
} else if ($checkbox.is('.field-filter')) {
|
||||
} else if ($checkbox.is('.field-filter') || $checkbox.is('.discount-filter')) {
|
||||
const {
|
||||
filterName: filter_name,
|
||||
filterValue: filter_value
|
||||
} = $checkbox.data();
|
||||
|
||||
if ($checkbox.is('.discount-filter')) {
|
||||
// clear previous discount filter to accomodate new
|
||||
delete this.field_filters["discount"];
|
||||
}
|
||||
if (is_checked) {
|
||||
this.field_filters[filter_name] = this.field_filters[filter_name] || [];
|
||||
this.field_filters[filter_name].push(filter_value);
|
||||
|
||||
@@ -17,7 +17,7 @@ def get_context(context):
|
||||
start = 0
|
||||
|
||||
engine = ProductQuery()
|
||||
context.items = engine.query(attribute_filters, field_filters, search, start)
|
||||
context.items, discounts = engine.query(attribute_filters, field_filters, search, start)
|
||||
|
||||
# Add homepage as parent
|
||||
context.parents = [{"name": frappe._("Home"), "route":"/"}]
|
||||
@@ -26,6 +26,8 @@ def get_context(context):
|
||||
|
||||
context.field_filters = filter_engine.get_field_filters()
|
||||
context.attribute_filters = filter_engine.get_attribute_filters()
|
||||
if discounts:
|
||||
context.discount_filters = filter_engine.get_discount_filters(discounts)
|
||||
|
||||
context.e_commerce_settings = engine.settings
|
||||
context.page_length = engine.settings.products_per_page or 20
|
||||
@@ -39,12 +41,13 @@ def get_products_html_for_website(field_filters=None, attribute_filters=None):
|
||||
attribute_filters = frappe.parse_json(attribute_filters)
|
||||
|
||||
engine = ProductQuery()
|
||||
items = engine.query(attribute_filters, field_filters, search_term=None, start=0)
|
||||
items, discounts = engine.query(attribute_filters, field_filters, search_term=None, start=0)
|
||||
|
||||
item_html = []
|
||||
for item in items:
|
||||
item_html.append(frappe.render_template('erpnext/www/all-products/item_row.html', {
|
||||
'item': item
|
||||
'item': item,
|
||||
'e_commerce_settings': None
|
||||
}))
|
||||
html = ''.join(item_html)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user