fix: Move get_product_filtrs_data to website item file
This commit is contained in:
parent
423d7516b4
commit
499fb56c0f
@ -442,3 +442,37 @@ def check_if_user_is_customer(user=None):
|
|||||||
party = contact.links[0].link_name
|
party = contact.links[0].link_name
|
||||||
|
|
||||||
return True if party else False
|
return True if party else False
|
||||||
|
|
||||||
|
@frappe.whitelist(allow_guest=True)
|
||||||
|
def get_product_filter_data():
|
||||||
|
"""Get pre-rendered filtered products and discount filters on load."""
|
||||||
|
from erpnext.e_commerce.product_query import ProductQuery
|
||||||
|
from erpnext.e_commerce.filters import ProductFiltersBuilder
|
||||||
|
from erpnext.setup.doctype.item_group.item_group import get_child_groups
|
||||||
|
|
||||||
|
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)) if frappe.form_dict.start else 0
|
||||||
|
item_group = frappe.form_dict.item_group
|
||||||
|
else:
|
||||||
|
search, attribute_filters, item_group = None, None, None
|
||||||
|
field_filters = {}
|
||||||
|
start = 0
|
||||||
|
|
||||||
|
sub_categories = []
|
||||||
|
if item_group:
|
||||||
|
field_filters['item_group'] = item_group
|
||||||
|
sub_categories = get_child_groups(item_group)
|
||||||
|
|
||||||
|
engine = ProductQuery()
|
||||||
|
items, discounts = engine.query(attribute_filters, field_filters, search_term=search, start=start)
|
||||||
|
|
||||||
|
# discount filter data
|
||||||
|
filters = {}
|
||||||
|
if discounts:
|
||||||
|
filter_engine = ProductFiltersBuilder()
|
||||||
|
filters["discount_filters"] = filter_engine.get_discount_filters(discounts)
|
||||||
|
|
||||||
|
return items or [], filters, engine.settings, sub_categories
|
@ -29,7 +29,7 @@ erpnext.ProductView = class {
|
|||||||
$('#list').prop('disabled', true);
|
$('#list').prop('disabled', true);
|
||||||
$('#image-view').prop('disabled', true);
|
$('#image-view').prop('disabled', true);
|
||||||
frappe.call({
|
frappe.call({
|
||||||
method: 'erpnext.www.all-products.index.get_product_filter_data',
|
method: 'erpnext.e_commerce.doctype.website_item.website_item.get_product_filter_data',
|
||||||
args: args,
|
args: args,
|
||||||
callback: function(result) {
|
callback: function(result) {
|
||||||
if (!result.exc && result) {
|
if (!result.exc && result) {
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
import frappe
|
import frappe
|
||||||
from frappe.utils import cint
|
from frappe.utils import cint
|
||||||
from erpnext.e_commerce.product_query import ProductQuery
|
|
||||||
from erpnext.e_commerce.filters import ProductFiltersBuilder
|
from erpnext.e_commerce.filters import ProductFiltersBuilder
|
||||||
from erpnext.setup.doctype.item_group.item_group import get_child_groups
|
|
||||||
|
|
||||||
sitemap = 1
|
sitemap = 1
|
||||||
|
|
||||||
@ -17,33 +15,3 @@ def get_context(context):
|
|||||||
context.page_length = cint(frappe.db.get_single_value('E Commerce Settings', 'products_per_page'))or 20
|
context.page_length = cint(frappe.db.get_single_value('E Commerce Settings', 'products_per_page'))or 20
|
||||||
|
|
||||||
context.no_cache = 1
|
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)) if frappe.form_dict.start else 0
|
|
||||||
item_group = frappe.form_dict.item_group
|
|
||||||
else:
|
|
||||||
search, attribute_filters, item_group = None, None, None
|
|
||||||
field_filters = {}
|
|
||||||
start = 0
|
|
||||||
|
|
||||||
sub_categories = []
|
|
||||||
if item_group:
|
|
||||||
field_filters['item_group'] = item_group
|
|
||||||
sub_categories = get_child_groups(item_group)
|
|
||||||
|
|
||||||
engine = ProductQuery()
|
|
||||||
items, discounts = engine.query(attribute_filters, field_filters, search_term=search, start=start)
|
|
||||||
|
|
||||||
# discount filter data
|
|
||||||
filters = {}
|
|
||||||
if discounts:
|
|
||||||
filter_engine = ProductFiltersBuilder()
|
|
||||||
filters["discount_filters"] = filter_engine.get_discount_filters(discounts)
|
|
||||||
|
|
||||||
return items or [], filters, engine.settings, sub_categories
|
|
Loading…
x
Reference in New Issue
Block a user