2019-03-19 06:18:32 +00:00
|
|
|
import frappe
|
2021-09-02 11:14:59 +00:00
|
|
|
|
2019-03-19 06:18:32 +00:00
|
|
|
from erpnext.portal.product_configurator.utils import get_product_settings
|
2020-12-29 11:48:58 +00:00
|
|
|
from erpnext.shopping_cart.filters import ProductFiltersBuilder
|
2020-12-24 12:24:07 +00:00
|
|
|
from erpnext.shopping_cart.product_query import ProductQuery
|
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-01-20 12:14:08 +00:00
|
|
|
start = 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-01-20 12:14:08 +00:00
|
|
|
context.items = 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":"/"}]
|
|
|
|
|
2019-03-19 06:18:32 +00:00
|
|
|
product_settings = get_product_settings()
|
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()
|
2019-03-19 06:18:32 +00:00
|
|
|
|
|
|
|
context.product_settings = product_settings
|
2020-12-24 12:24:07 +00:00
|
|
|
context.body_class = "product-page"
|
2020-12-29 11:48:58 +00:00
|
|
|
context.page_length = product_settings.products_per_page or 20
|
2019-03-19 06:18:32 +00:00
|
|
|
|
|
|
|
context.no_cache = 1
|