fix(ecommerce): breadcrumb: fallback to /all-products (#33718)

* fix(ecommerce): breadcrumb: fallback to `/all-products`

* fix(item_group): use `==` instead of `is`

* test(ecommerce): breadcrumb
This commit is contained in:
Sabu Siyad 2023-01-20 18:54:54 +05:30 committed by GitHub
parent 17045f88a1
commit a94aa7a79f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 4 deletions

View File

@ -174,7 +174,10 @@ class TestWebsiteItem(unittest.TestCase):
# Website Item Portal Tests Begin # Website Item Portal Tests Begin
def test_website_item_breadcrumbs(self): def test_website_item_breadcrumbs(self):
"Check if breadcrumbs include homepage, product listing navigation page, parent item group(s) and item group." """
Check if breadcrumbs include homepage, product listing navigation page,
parent item group(s) and item group
"""
from erpnext.setup.doctype.item_group.item_group import get_parent_item_groups from erpnext.setup.doctype.item_group.item_group import get_parent_item_groups
item_code = "Test Breadcrumb Item" item_code = "Test Breadcrumb Item"
@ -197,7 +200,7 @@ class TestWebsiteItem(unittest.TestCase):
breadcrumbs = get_parent_item_groups(item.item_group) breadcrumbs = get_parent_item_groups(item.item_group)
self.assertEqual(breadcrumbs[0]["name"], "Home") self.assertEqual(breadcrumbs[0]["name"], "Home")
self.assertEqual(breadcrumbs[1]["name"], "Shop by Category") self.assertEqual(breadcrumbs[1]["name"], "All Products")
self.assertEqual(breadcrumbs[2]["name"], "_Test Item Group B") # parent item group self.assertEqual(breadcrumbs[2]["name"], "_Test Item Group B") # parent item group
self.assertEqual(breadcrumbs[3]["name"], "_Test Item Group B - 1") self.assertEqual(breadcrumbs[3]["name"], "_Test Item Group B - 1")

View File

@ -148,12 +148,12 @@ def get_item_for_list_in_html(context):
def get_parent_item_groups(item_group_name, from_item=False): def get_parent_item_groups(item_group_name, from_item=False):
base_nav_page = {"name": _("Shop by Category"), "route": "/shop-by-category"} base_nav_page = {"name": _("All Products"), "route": "/all-products"}
if from_item and frappe.request.environ.get("HTTP_REFERER"): if from_item and frappe.request.environ.get("HTTP_REFERER"):
# base page after 'Home' will vary on Item page # base page after 'Home' will vary on Item page
last_page = frappe.request.environ["HTTP_REFERER"].split("/")[-1].split("?")[0] last_page = frappe.request.environ["HTTP_REFERER"].split("/")[-1].split("?")[0]
if last_page and last_page in ("shop-by-category", "all-products"): if last_page and last_page == "shop-by-category":
base_nav_page_title = " ".join(last_page.split("-")).title() base_nav_page_title = " ".join(last_page.split("-")).title()
base_nav_page = {"name": _(base_nav_page_title), "route": "/" + last_page} base_nav_page = {"name": _(base_nav_page_title), "route": "/" + last_page}