brotherton-erpnext/erpnext/shopping_cart/utils.py

50 lines
1.5 KiB
Python
Raw Normal View History

# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
2014-10-21 10:46:30 +00:00
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
import frappe
2015-02-23 16:44:12 +00:00
from frappe import _
2014-10-21 10:46:30 +00:00
import frappe.defaults
from frappe.utils import cint
2015-02-23 16:44:12 +00:00
from erpnext.shopping_cart.doctype.shopping_cart_settings.shopping_cart_settings import is_cart_enabled
2014-10-21 10:46:30 +00:00
def show_cart_count():
if (frappe.db.get_default("shopping_cart_enabled") and
frappe.db.get_value("User", frappe.session.user, "user_type") == "Website User"):
return True
return False
def set_cart_count(login_manager):
if show_cart_count():
2015-02-23 16:44:12 +00:00
from erpnext.shopping_cart.cart import set_cart_count
2014-10-21 10:46:30 +00:00
set_cart_count()
def clear_cart_count(login_manager):
if show_cart_count():
frappe.local.cookie_manager.delete_cookie("cart_count")
2015-02-24 12:20:44 +00:00
def update_website_context(context):
2015-02-23 16:44:12 +00:00
cart_enabled = is_cart_enabled()
2014-10-21 10:46:30 +00:00
context["shopping_cart_enabled"] = cart_enabled
if cart_enabled:
2015-02-23 16:44:12 +00:00
post_login = [
{"label": _("Cart"), "url": "cart", "class": "cart-count"},
2014-10-21 10:46:30 +00:00
{"class": "divider"}
]
2015-02-23 16:44:12 +00:00
context["post_login"] = post_login + context.get("post_login", [])
def update_my_account_context(context):
if is_cart_enabled():
context["my_account_list"].append({"label": _("Cart"), "url": "cart"})
context["my_account_list"].extend([
{"label": _("Orders"), "url": "orders"},
{"label": _("Invoices"), "url": "invoices"},
{"label": _("Shipments"), "url": "shipments"},
2015-02-24 12:20:44 +00:00
# {"label": _("Issues"), "url": "tickets"},
2015-02-23 16:44:12 +00:00
{"label": _("Addresses"), "url": "addresses"},
])