2019-03-19 06:18:32 +00:00
|
|
|
import frappe
|
2021-02-16 13:15:36 +00:00
|
|
|
from frappe.utils import cint
|
2021-02-25 08:26:38 +00:00
|
|
|
from erpnext.e_commerce.product_query import ProductQuery
|
|
|
|
from erpnext.e_commerce.filters import ProductFiltersBuilder
|
2019-03-19 06:18:32 +00:00
|
|
|
|
2019-03-20 08:41:22 +00:00
|
|
|
sitemap = 1
|
|
|
|
|
2019-03-19 06:18:32 +00:00
|
|
|
def get_context(context):
|
|
|
|
|
|
|
|
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)
|
2021-02-16 13:15:36 +00:00
|
|
|
start = cint(frappe.parse_json(frappe.form_dict.start))
|
2019-03-19 06:18:32 +00:00
|
|
|
else:
|
|
|
|
search = field_filters = attribute_filters = None
|
2021-01-20 12:14:08 +00:00
|
|
|
start = 0
|
2019-03-19 06:18:32 +00:00
|
|
|
|
2020-12-24 12:24:07 +00:00
|
|
|
engine = ProductQuery()
|
2021-04-20 16:24:52 +00:00
|
|
|
context.items, discounts = engine.query(attribute_filters, field_filters, search, start)
|
2019-03-19 06:18:32 +00:00
|
|
|
|
2020-12-22 07:14:09 +00:00
|
|
|
# Add homepage as parent
|
|
|
|
context.parents = [{"name": frappe._("Home"), "route":"/"}]
|
|
|
|
|
2020-12-29 11:48:58 +00:00
|
|
|
filter_engine = ProductFiltersBuilder()
|
2019-03-19 06:18:32 +00:00
|
|
|
|
2020-12-29 11:48:58 +00:00
|
|
|
context.field_filters = filter_engine.get_field_filters()
|
2021-09-14 06:11:19 +00:00
|
|
|
context.attribute_filters = filter_engine.get_attribute_filters()
|
2021-04-20 16:24:52 +00:00
|
|
|
if discounts:
|
|
|
|
context.discount_filters = filter_engine.get_discount_filters(discounts)
|
2019-03-19 06:18:32 +00:00
|
|
|
|
2021-02-16 13:15:36 +00:00
|
|
|
context.e_commerce_settings = engine.settings
|
|
|
|
context.page_length = engine.settings.products_per_page or 20
|
2019-03-19 06:18:32 +00:00
|
|
|
|
|
|
|
context.no_cache = 1
|
2021-02-16 13:15:36 +00:00
|
|
|
|
|
|
|
@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()
|
2021-04-20 16:24:52 +00:00
|
|
|
items, discounts = engine.query(attribute_filters, field_filters, search_term=None, start=0)
|
2021-02-16 13:15:36 +00:00
|
|
|
|
|
|
|
item_html = []
|
|
|
|
for item in items:
|
|
|
|
item_html.append(frappe.render_template('erpnext/www/all-products/item_row.html', {
|
2021-04-20 16:24:52 +00:00
|
|
|
'item': item,
|
|
|
|
'e_commerce_settings': None
|
2021-02-16 13:15:36 +00:00
|
|
|
}))
|
|
|
|
html = ''.join(item_html)
|
|
|
|
|
|
|
|
if not items:
|
|
|
|
html = frappe.render_template('erpnext/www/all-products/not_found.html', {})
|
|
|
|
|
|
|
|
return html
|