fix: Items Query, Sub categories, Review Button
- Include Item Variant table in query only if attributes are involved - Render sub categories of they exist, even without items - 'Write a Review' provision only if user is a customer
This commit is contained in:
parent
499fb56c0f
commit
03b88bd7b8
@ -433,15 +433,16 @@ def check_if_user_is_customer(user=None):
|
|||||||
user = frappe.session.user
|
user = frappe.session.user
|
||||||
|
|
||||||
contact_name = get_contact_name(user)
|
contact_name = get_contact_name(user)
|
||||||
party = None
|
customer = None
|
||||||
|
|
||||||
if contact_name:
|
if contact_name:
|
||||||
contact = frappe.get_doc('Contact', contact_name)
|
contact = frappe.get_doc('Contact', contact_name)
|
||||||
if contact.links:
|
for link in contact.links:
|
||||||
party_doctype = contact.links[0].link_doctype
|
if link.link_doctype == "Customer":
|
||||||
party = contact.links[0].link_name
|
customer = link.link_name
|
||||||
|
break
|
||||||
|
|
||||||
return True if party else False
|
return True if customer else False
|
||||||
|
|
||||||
@frappe.whitelist(allow_guest=True)
|
@frappe.whitelist(allow_guest=True)
|
||||||
def get_product_filter_data():
|
def get_product_filter_data():
|
||||||
|
@ -104,27 +104,24 @@ class ProductQuery:
|
|||||||
elif not frappe.db.get_value("Item", item.item_code, "is_stock_item"):
|
elif not frappe.db.get_value("Item", item.item_code, "is_stock_item"):
|
||||||
item.in_stock = "green" # non-stock item will always be available
|
item.in_stock = "green" # non-stock item will always be available
|
||||||
|
|
||||||
def query_items(self, conditions, or_conditions, substitutions, start=0):
|
def query_items(self, conditions, or_conditions, substitutions, start=0, with_attributes=False):
|
||||||
"""Build a query to fetch Website Items based on field filters."""
|
"""Build a query to fetch Website Items based on field filters."""
|
||||||
self.query_fields = (", ").join(self.fields)
|
self.query_fields = (", ").join(self.fields)
|
||||||
|
|
||||||
return frappe.db.sql("""
|
attribute_table = ", `tabItem Variant Attribute` iva" if with_attributes else ""
|
||||||
select distinct {query_fields}
|
|
||||||
|
return frappe.db.sql(f"""
|
||||||
|
select distinct {self.query_fields}
|
||||||
from
|
from
|
||||||
`tabWebsite Item` wi, `tabItem Variant Attribute` iva
|
`tabWebsite Item` wi {attribute_table}
|
||||||
where
|
where
|
||||||
wi.published = 1
|
wi.published = 1
|
||||||
{conditions}
|
{conditions}
|
||||||
{or_conditions}
|
{or_conditions}
|
||||||
limit {limit} offset {start}
|
limit {self.page_length} offset {start}
|
||||||
""".format(
|
""",
|
||||||
query_fields=self.query_fields,
|
tuple(substitutions),
|
||||||
conditions=conditions,
|
as_dict=1)
|
||||||
or_conditions=or_conditions,
|
|
||||||
limit=self.page_length,
|
|
||||||
start=start),
|
|
||||||
tuple(substitutions),
|
|
||||||
as_dict=1)
|
|
||||||
|
|
||||||
def query_items_with_attributes(self, attributes, start=0):
|
def query_items_with_attributes(self, attributes, start=0):
|
||||||
"""Build a query to fetch Website Items based on field & attribute filters."""
|
"""Build a query to fetch Website Items based on field & attribute filters."""
|
||||||
@ -142,7 +139,8 @@ class ProductQuery:
|
|||||||
.format(attribute, (", ").join(['%s'] * len(values)))
|
.format(attribute, (", ").join(['%s'] * len(values)))
|
||||||
substitutions_copy.extend(values)
|
substitutions_copy.extend(values)
|
||||||
|
|
||||||
items = self.query_items(conditions_copy, self.or_conditions, substitutions_copy, start=start)
|
items = self.query_items(conditions_copy, self.or_conditions, substitutions_copy,
|
||||||
|
start=start, with_attributes=True)
|
||||||
|
|
||||||
items_dict = {item.name: item for item in items}
|
items_dict = {item.name: item for item in items}
|
||||||
# TODO: Replace Variants by their parent templates
|
# TODO: Replace Variants by their parent templates
|
||||||
|
@ -32,18 +32,17 @@ erpnext.ProductView = class {
|
|||||||
method: 'erpnext.e_commerce.doctype.website_item.website_item.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 && result.message) {
|
||||||
if (!result.message || !result.message[0].length) {
|
if (me.item_group && result.message[3].length) {
|
||||||
console.log("no items");
|
me.render_item_sub_categories(result.message[3]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!result.message[0].length) {
|
||||||
// if result has no items or result is empty
|
// if result has no items or result is empty
|
||||||
me.render_no_products_section();
|
me.render_no_products_section();
|
||||||
} else {
|
} else {
|
||||||
console.log("there are items");
|
|
||||||
me.render_filters(result.message[1]);
|
me.render_filters(result.message[1]);
|
||||||
|
|
||||||
if (me.item_group) {
|
|
||||||
me.render_item_sub_categories(result.message[3]);
|
|
||||||
}
|
|
||||||
// Render views
|
// Render views
|
||||||
me.render_list_view(result.message[0], result.message[2]);
|
me.render_list_view(result.message[0], result.message[2]);
|
||||||
me.render_grid_view(result.message[0], result.message[2]);
|
me.render_grid_view(result.message[0], result.message[2]);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user