diff --git a/erpnext/www/shop-by-category/index.py b/erpnext/www/shop-by-category/index.py index 7b493c3c2886..219747c9f8a5 100644 --- a/erpnext/www/shop-by-category/index.py +++ b/erpnext/www/shop-by-category/index.py @@ -51,36 +51,31 @@ def get_tabs(categories): return tab_values -def get_category_records(categories): +def get_category_records(categories: list): categorical_data = {} - for category in categories: - if category == "item_group": - categorical_data["item_group"] = frappe.db.sql( - """ - Select - name, parent_item_group, is_group, image, route - from - `tabItem Group` - where - parent_item_group = 'All Item Groups' - and show_in_website = 1 - """, - as_dict=1, + + for c in categories: + if c == "item_group": + categorical_data["item_group"] = frappe.db.get_all( + "Item Group", + filters={"parent_item_group": "All Item Groups", "show_in_website": 1}, + fields=["name", "parent_item_group", "is_group", "image", "route"], ) - else: - doctype = frappe.unscrub(category) - fields = ["name"] - if frappe.get_meta(doctype, cached=True).get_field("image"): + + continue + + doctype = frappe.unscrub(c) + fields = ["name"] + + try: + meta = frappe.get_meta(doctype, cached=True) + if meta.get_field("image"): fields += ["image"] - categorical_data[category] = frappe.db.sql( - f""" - Select - {",".join(fields)} - from - `tab{doctype}` - """, - as_dict=1, - ) + data = frappe.db.get_all(doctype, fields=fields) + categorical_data[c] = data + except BaseException: + frappe.throw(_("DocType {} not found").format(doctype)) + continue return categorical_data