2015-03-03 09:25:30 +00:00
|
|
|
# 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
|
|
|
|
import frappe
|
2021-09-02 11:14:59 +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():
|
2015-07-13 10:53:42 +00:00
|
|
|
if (is_cart_enabled() and
|
2014-10-21 10:46:30 +00:00
|
|
|
frappe.db.get_value("User", frappe.session.user, "user_type") == "Website User"):
|
|
|
|
return True
|
|
|
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
def set_cart_count(login_manager):
|
2021-10-11 17:44:28 +00:00
|
|
|
# since this is run only on hooks login event
|
|
|
|
# make sure user is already a customer
|
|
|
|
# before trying to set cart count
|
|
|
|
user_is_customer = is_customer()
|
2021-10-12 07:48:28 +00:00
|
|
|
if not user_is_customer:
|
|
|
|
return
|
2021-10-11 17:44:28 +00:00
|
|
|
|
2014-10-21 10:46:30 +00:00
|
|
|
if show_cart_count():
|
2015-02-23 16:44:12 +00:00
|
|
|
from erpnext.shopping_cart.cart import set_cart_count
|
2021-10-12 07:48:28 +00:00
|
|
|
|
2021-10-11 17:44:28 +00:00
|
|
|
# set_cart_count will try to fetch existing cart quotation
|
|
|
|
# or create one if non existent (and create a customer too)
|
|
|
|
# cart count is calculated from this quotation's items
|
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
|
|
|
|
|
2021-10-11 17:44:28 +00:00
|
|
|
def is_customer():
|
|
|
|
if frappe.session.user and frappe.session.user != "Guest":
|
2017-01-13 18:55:22 +00:00
|
|
|
contact_name = frappe.get_value("Contact", {"email_id": frappe.session.user})
|
|
|
|
if contact_name:
|
|
|
|
contact = frappe.get_doc('Contact', contact_name)
|
|
|
|
for link in contact.links:
|
2021-10-11 17:44:28 +00:00
|
|
|
if link.link_doctype == 'Customer':
|
|
|
|
return True
|
2016-03-03 08:30:35 +00:00
|
|
|
|
2021-10-11 17:44:28 +00:00
|
|
|
return False
|