From 06c5e17279a1ec3ca3f1d0db0f916e00b4007520 Mon Sep 17 00:00:00 2001 From: rohitwaghchaure Date: Fri, 20 Dec 2024 13:10:21 +0530 Subject: [PATCH] fix: Shop by Category (#232) (cherry picked from commit 1c33fd66fc2bfb83155aee114ab6e02ae93e8ba1) --- webshop/www/shop-by-category/index.py | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/webshop/www/shop-by-category/index.py b/webshop/www/shop-by-category/index.py index 0dedce6029..beeabb53f5 100644 --- a/webshop/www/shop-by-category/index.py +++ b/webshop/www/shop-by-category/index.py @@ -53,6 +53,7 @@ def get_tabs(categories): def get_category_records(categories): categorical_data = {} + website_item_meta = frappe.get_meta("Website Item", cached=True) for category in categories: if category == "item_group": @@ -62,8 +63,18 @@ def get_category_records(categories): fields=["name", "parent_item_group", "is_group", "image", "route"], ) else: - doctype = frappe.unscrub(category) + field_type = website_item_meta.get_field(category).fieldtype + + if field_type == "Table MultiSelect": + child_doc = website_item_meta.get_field(category).options + for field in frappe.get_meta(child_doc, cached=True).fields: + if field.fieldtype == "Link" and field.reqd: + doctype = field.options + else: + doctype = website_item_meta.get_field(category).options + fields = ["name"] + meta = frappe.get_meta(doctype, cached=True) if meta.get_field("image"): fields += ["image"] @@ -75,9 +86,13 @@ def get_category_records(categories): elif meta.get_field("custom_show_in_website"): filters = {"custom_show_in_website": 1} - if filters: - categorical_data[category] = frappe.db.get_all(doctype, fields=fields, filters=filters) - else: - categorical_data[category] = frappe.db.get_all(doctype, fields=fields) + try: + if filters: + categorical_data[category] = frappe.db.get_all(doctype, fields=fields, filters=filters) + else: + categorical_data[category] = frappe.db.get_all(doctype, fields=fields) + + except BaseException: + frappe.throw(_("DocType {} not found").format(doctype)) return categorical_data