2021-03-02 14:24:01 +00:00
|
|
|
import frappe
|
|
|
|
from frappe import _
|
|
|
|
|
|
|
|
sitemap = 1
|
|
|
|
|
|
|
|
def get_context(context):
|
2021-09-01 09:27:50 +00:00
|
|
|
context.body_class = "product-page"
|
|
|
|
|
2021-05-24 20:05:22 +00:00
|
|
|
settings = frappe.get_cached_doc("E Commerce Settings")
|
2021-03-02 14:24:01 +00:00
|
|
|
context.categories_enabled = settings.enable_field_filters
|
|
|
|
|
|
|
|
if context.categories_enabled:
|
|
|
|
categories = [row.fieldname for row in settings.filter_fields]
|
|
|
|
context.tabs = get_tabs(categories)
|
|
|
|
|
|
|
|
if settings.slideshow:
|
|
|
|
context.slideshow = get_slideshow(settings.slideshow)
|
|
|
|
|
|
|
|
context.no_cache = 1
|
|
|
|
|
|
|
|
def get_slideshow(slideshow):
|
|
|
|
values = {
|
|
|
|
'show_indicators': 1,
|
|
|
|
'show_controls': 1,
|
|
|
|
'rounded': 1,
|
|
|
|
'slider_name': "Categories"
|
|
|
|
}
|
2021-05-24 20:05:22 +00:00
|
|
|
slideshow = frappe.get_cached_doc("Website Slideshow", slideshow)
|
2021-03-02 14:24:01 +00:00
|
|
|
slides = slideshow.get({"doctype": "Website Slideshow Item"})
|
2021-05-24 20:05:22 +00:00
|
|
|
for index, slide in enumerate(slides, start=1):
|
2021-06-08 09:17:11 +00:00
|
|
|
values[f"slide_{index}_image"] = slide.image
|
|
|
|
values[f"slide_{index}_title"] = slide.heading
|
|
|
|
values[f"slide_{index}_subtitle"] = slide.description
|
|
|
|
values[f"slide_{index}_theme"] = slide.get("theme") or "Light"
|
|
|
|
values[f"slide_{index}_content_align"] = slide.get("content_align") or "Centre"
|
|
|
|
values[f"slide_{index}_primary_action"] = slide.url
|
2021-03-02 14:24:01 +00:00
|
|
|
|
|
|
|
return values
|
|
|
|
|
|
|
|
def get_tabs(categories):
|
|
|
|
tab_values = {
|
|
|
|
'title': _("Shop by Category"),
|
|
|
|
}
|
|
|
|
|
|
|
|
categorical_data = get_category_records(categories)
|
2021-05-24 20:05:22 +00:00
|
|
|
for index, tab in enumerate(categorical_data, start=1):
|
2021-03-02 14:24:01 +00:00
|
|
|
tab_values[f"tab_{index + 1}_title"] = frappe.unscrub(tab)
|
|
|
|
# pre-render cards for each tab
|
|
|
|
tab_values[f"tab_{index + 1}_content"] = frappe.render_template(
|
|
|
|
"erpnext/www/shop-by-category/category_card_section.html",
|
|
|
|
{"data": categorical_data[tab], "type": tab}
|
|
|
|
)
|
|
|
|
return tab_values
|
|
|
|
|
|
|
|
def get_category_records(categories):
|
|
|
|
categorical_data = {}
|
|
|
|
for category in categories:
|
|
|
|
if category == "item_group":
|
2022-02-02 07:28:31 +00:00
|
|
|
categorical_data["item_group"] = frappe.db.get_all(
|
|
|
|
"Item Group",
|
|
|
|
filters={
|
|
|
|
"parent_item_group": "All Item Groups",
|
|
|
|
"show_in_website": 1
|
|
|
|
},
|
2022-02-22 18:45:39 +00:00
|
|
|
fields=["name", "parent_item_group", "is_group", "image", "route"]
|
2022-02-02 07:28:31 +00:00
|
|
|
)
|
2021-03-02 14:24:01 +00:00
|
|
|
else:
|
|
|
|
doctype = frappe.unscrub(category)
|
|
|
|
fields = ["name"]
|
|
|
|
if frappe.get_meta(doctype, cached=True).get_field("image"):
|
|
|
|
fields += ["image"]
|
|
|
|
|
2022-02-22 18:45:39 +00:00
|
|
|
categorical_data[category] = frappe.db.get_all(doctype, fields=fields)
|
2021-03-02 14:24:01 +00:00
|
|
|
|
|
|
|
return categorical_data
|
|
|
|
|