48b3ce82b9
- Auto Height on Cards - Title with ellipses on length exceed - Changed namepaces - Moved product card rendering to JS - Added Image and List View Toggling buttons - Kept basic filters rendering just as before
80 lines
2.5 KiB
Python
80 lines
2.5 KiB
Python
import frappe
|
|
from frappe.utils import cint
|
|
from erpnext.e_commerce.product_query import ProductQuery
|
|
from erpnext.e_commerce.filters import ProductFiltersBuilder
|
|
|
|
sitemap = 1
|
|
|
|
def get_context(context):
|
|
# Add homepage as parent
|
|
context.parents = [{"name": frappe._("Home"), "route":"/"}]
|
|
|
|
filter_engine = ProductFiltersBuilder()
|
|
context.field_filters = filter_engine.get_field_filters()
|
|
context.attribute_filters = filter_engine.get_attribute_filters()
|
|
|
|
context.page_length = cint(frappe.db.get_single_value('E Commerce Settings', 'products_per_page'))or 20
|
|
|
|
context.no_cache = 1
|
|
|
|
@frappe.whitelist(allow_guest=True)
|
|
def get_product_filter_data():
|
|
"""Get pre-rendered filtered products and discount filters on load."""
|
|
if frappe.form_dict:
|
|
search = frappe.form_dict.search
|
|
field_filters = frappe.parse_json(frappe.form_dict.field_filters)
|
|
attribute_filters = frappe.parse_json(frappe.form_dict.attribute_filters)
|
|
start = cint(frappe.parse_json(frappe.form_dict.start))
|
|
item_group = frappe.form_dict.item_group
|
|
else:
|
|
search, attribute_filters, item_group = None, None, None
|
|
field_filters = {}
|
|
start = 0
|
|
|
|
if item_group:
|
|
field_filters['item_group'] = item_group
|
|
|
|
engine = ProductQuery()
|
|
items, discounts = engine.query(attribute_filters, field_filters, search_term=search, start=start)
|
|
|
|
item_html = []
|
|
for item in items:
|
|
item_html.append(frappe.render_template('erpnext/www/all-products/item_row.html', {
|
|
'item': item,
|
|
'e_commerce_settings': engine.settings
|
|
}))
|
|
html = ''.join(item_html)
|
|
|
|
if not items:
|
|
html = frappe.render_template('erpnext/www/all-products/not_found.html', {})
|
|
|
|
# discount filter data
|
|
filters = {}
|
|
if discounts:
|
|
filter_engine = ProductFiltersBuilder()
|
|
filters["discount_filters"] = filter_engine.get_discount_filters(discounts)
|
|
|
|
return html, filters
|
|
|
|
@frappe.whitelist(allow_guest=True)
|
|
def get_products_html_for_website(field_filters=None, attribute_filters=None):
|
|
"""Get Products on filter change."""
|
|
field_filters = frappe.parse_json(field_filters)
|
|
attribute_filters = frappe.parse_json(attribute_filters)
|
|
|
|
engine = ProductQuery()
|
|
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,
|
|
'e_commerce_settings': engine.settings
|
|
}))
|
|
html = ''.join(item_html)
|
|
|
|
if not items:
|
|
html = frappe.render_template('erpnext/www/all-products/not_found.html', {})
|
|
|
|
return html
|