Exemplo n.º 1
0
def get_context(context):
    item_context = context.doc.as_dict()
    item_context["parent_groups"] = get_parent_item_groups(context.doc.item_group) + [{"name": context.doc.name}]
    if context.doc.slideshow:
        item_context.update(get_slideshow(context.doc))

    return item_context
Exemplo n.º 2
0
	def get_context(self, context):
		context["parent_groups"] = get_parent_item_groups(self.item_group) + \
			[{"name": self.name}]
		if self.slideshow:
			context.update(get_slideshow(self))

		return context
Exemplo n.º 3
0
	def test_website_item_breadcrumbs(self):
		"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

		item_code = "Test Breadcrumb Item"
		item = make_item(
			item_code,
			{
				"item_group": "_Test Item Group B - 1",
			},
		)

		if not frappe.db.exists("Website Item", {"item_code": item_code}):
			web_item = make_website_item(item, save=False)
			web_item.save()
		else:
			web_item = frappe.get_cached_doc("Website Item", {"item_code": item_code})

		frappe.db.set_value("Item Group", "_Test Item Group B - 1", "show_in_website", 1)
		frappe.db.set_value("Item Group", "_Test Item Group B", "show_in_website", 1)

		breadcrumbs = get_parent_item_groups(item.item_group)

		self.assertEqual(breadcrumbs[0]["name"], "Home")
		self.assertEqual(breadcrumbs[1]["name"], "Shop by Category")
		self.assertEqual(breadcrumbs[2]["name"], "_Test Item Group B")  # parent item group
		self.assertEqual(breadcrumbs[3]["name"], "_Test Item Group B - 1")

		# tear down
		web_item.delete()
		item.delete()
Exemplo n.º 4
0
    def get_context(self, context):
        context["parent_groups"] = get_parent_item_groups(self.item_group) + \
         [{"name": self.name}]
        if self.slideshow:
            context.update(get_slideshow(self))

        return context
Exemplo n.º 5
0
	def get_context(self, context):
		context.show_search=True
		context.search_link = '/product_search'

		context.parents = get_parent_item_groups(self.item_group)

		self.set_variant_context(context)
		self.set_attribute_context(context)
		self.set_disabled_attributes(context)

		return context
Exemplo n.º 6
0
    def get_context(self, context):
        context.show_search = True
        context.search_link = '/product_search'

        context.parents = get_parent_item_groups(self.item_group)

        self.set_variant_context(context)
        self.set_attribute_context(context)
        self.set_disabled_attributes(context)

        return context
Exemplo n.º 7
0
def get_context(context):
	item_group_context = context.doc.as_dict()
	item_group_context.update({
		"items": get_product_list_for_group(product_group = context.docname, limit=100),
		"parent_groups": get_parent_item_groups(context.docname),
		"title": context.docname
	})

	if context.doc.slideshow:
		item_group_context.update(get_slideshow(context.doc))

	return item_group_context
Exemplo n.º 8
0
def get_context(context):
    item_group_context = context.doc.as_dict()
    item_group_context.update({
        "items":
        get_product_list_for_group(product_group=context.docname, limit=100),
        "parent_groups":
        get_parent_item_groups(context.docname),
        "title":
        context.docname
    })

    if context.doc.slideshow:
        item_group_context.update(get_slideshow(context.doc))

    return item_group_context
Exemplo n.º 9
0
	def get_context(self, context):
		if self.variant_of:
			# redirect to template page!
			template_item = frappe.get_doc("Item", self.variant_of)
			frappe.flags.redirect_location = template_item.get_route() + "?variant=" + urllib.quote(self.name)
			raise frappe.Redirect

		context.parent_groups = get_parent_item_groups(self.item_group) + \
			[{"name": self.name}]

		self.set_variant_context(context)

		self.set_attribute_context(context)

		context.parents = self.get_parents(context)

		return context
Exemplo n.º 10
0
    def get_context(self, context):
        context.show_search = True
        context.search_link = "/search"
        context.body_class = "product-page"

        context.parents = get_parent_item_groups(self.item_group,
                                                 from_item=True)  # breadcumbs
        self.attributes = frappe.get_all(
            "Item Variant Attribute",
            fields=["attribute", "attribute_value"],
            filters={"parent": self.item_code})

        if self.slideshow:
            context.update(get_slideshow(self))

        self.set_variant_context(context)
        self.set_attribute_context(context)
        self.set_disabled_attributes(context)
        self.set_metatags(context)
        self.set_shopping_cart_data(context)

        settings = context.shopping_cart.cart_settings

        self.get_product_details_section(context)

        if settings.get("enable_reviews"):
            reviews_data = get_item_reviews(self.name)
            context.update(reviews_data)
            context.reviews = context.reviews[:4]

        context.wished = False
        if frappe.db.exists("Wishlist Item", {
                "item_code": self.item_code,
                "parent": frappe.session.user
        }):
            context.wished = True

        context.user_is_customer = check_if_user_is_customer()

        context.recommended_items = None
        if settings and settings.enable_recommendations:
            context.recommended_items = self.get_recommended_items(settings)

        return context
Exemplo n.º 11
0
	def get_context(self, context):
		context.show_search=True
		context.search_link = '/product_search'
		if self.variant_of:
			# redirect to template page!
			template_item = frappe.get_doc("Item", self.variant_of)
			frappe.flags.redirect_location = template_item.route + "?variant=" + urllib.quote(self.name)
			raise frappe.Redirect

		context.parent_groups = get_parent_item_groups(self.item_group) + \
			[{"name": self.name}]

		self.set_variant_context(context)

		self.set_attribute_context(context)

		self.set_disabled_attributes(context)

		context.parents = self.get_parents(context)

		return context
Exemplo n.º 12
0
	def get_context(self, context):
		context.parent_groups = get_parent_item_groups(self.item_group) + \
			[{"name": self.name}]
		if self.slideshow:
			context.update(get_slideshow(self))

		if self.has_variants:
			attribute_values_available = {}
			context.attribute_values = {}

			# load variants
			context.variants = frappe.get_all("Item",
				filters={"variant_of": self.name, "show_in_website": 1})

			# load attributes
			for v in context.variants:
				v.attributes = frappe.get_all("Item Variant Attribute",
					fields=["attribute", "attribute_value"], filters={"parent": v.name})

				for attr in v.attributes:
					values = attribute_values_available.setdefault(attr.attribute, [])
					if attr.attribute_value not in values:
						values.append(attr.attribute_value)

			# filter attributes, order based on attribute table
			for attr in self.attributes:
				values = context.attribute_values.setdefault(attr.attribute, [])

				# get list of values defined (for sequence)
				for attr_value in frappe.db.get_all("Item Attribute Value",
					fields=["attribute_value"], filters={"parent": attr.attribute}, order_by="idx asc"):

					if attr_value.attribute_value in attribute_values_available.get(attr.attribute, []):
						values.append(attr_value.attribute_value)

			context.variant_info = json.dumps(context.variants)

		context.parents = self.get_parents(context)

		return context