fix: Shop by category fixes (#34688)
* fix: Shop by category fixes
* chore: Update tests
diff --git a/erpnext/e_commerce/doctype/website_item/test_website_item.py b/erpnext/e_commerce/doctype/website_item/test_website_item.py
index e41c9da..43b2f67 100644
--- a/erpnext/e_commerce/doctype/website_item/test_website_item.py
+++ b/erpnext/e_commerce/doctype/website_item/test_website_item.py
@@ -199,8 +199,14 @@
breadcrumbs = get_parent_item_groups(item.item_group)
+ settings = frappe.get_cached_doc("E Commerce Settings")
+ if settings.enable_field_filters:
+ base_breadcrumb = "Shop by Category"
+ else:
+ base_breadcrumb = "All Products"
+
self.assertEqual(breadcrumbs[0]["name"], "Home")
- self.assertEqual(breadcrumbs[1]["name"], "All Products")
+ self.assertEqual(breadcrumbs[1]["name"], base_breadcrumb)
self.assertEqual(breadcrumbs[2]["name"], "_Test Item Group B") # parent item group
self.assertEqual(breadcrumbs[3]["name"], "_Test Item Group B - 1")
diff --git a/erpnext/setup/doctype/item_group/item_group.py b/erpnext/setup/doctype/item_group/item_group.py
index 2fdfcf6..2eca5ca 100644
--- a/erpnext/setup/doctype/item_group/item_group.py
+++ b/erpnext/setup/doctype/item_group/item_group.py
@@ -148,12 +148,17 @@
def get_parent_item_groups(item_group_name, from_item=False):
- base_nav_page = {"name": _("All Products"), "route": "/all-products"}
+ settings = frappe.get_cached_doc("E Commerce Settings")
+
+ if settings.enable_field_filters:
+ base_nav_page = {"name": _("Shop by Category"), "route": "/shop-by-category"}
+ else:
+ base_nav_page = {"name": _("All Products"), "route": "/all-products"}
if from_item and frappe.request.environ.get("HTTP_REFERER"):
# base page after 'Home' will vary on Item page
last_page = frappe.request.environ["HTTP_REFERER"].split("/")[-1].split("?")[0]
- if last_page and last_page == "shop-by-category":
+ if last_page and last_page in ("shop-by-category", "all-products"):
base_nav_page_title = " ".join(last_page.split("-")).title()
base_nav_page = {"name": _(base_nav_page_title), "route": "/" + last_page}
diff --git a/erpnext/www/shop-by-category/index.py b/erpnext/www/shop-by-category/index.py
index 219747c..913c183 100644
--- a/erpnext/www/shop-by-category/index.py
+++ b/erpnext/www/shop-by-category/index.py
@@ -53,6 +53,7 @@
def get_category_records(categories: list):
categorical_data = {}
+ website_item_meta = frappe.get_meta("Website Item", cached=True)
for c in categories:
if c == "item_group":
@@ -64,7 +65,16 @@
continue
- doctype = frappe.unscrub(c)
+ field_type = website_item_meta.get_field(c).fieldtype
+
+ if field_type == "Table MultiSelect":
+ child_doc = website_item_meta.get_field(c).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(c).options
+
fields = ["name"]
try: