From 1590ac3ec79afadf046a66fc43e9787fe0406a9a Mon Sep 17 00:00:00 2001 From: marination Date: Mon, 11 Oct 2021 23:14:28 +0530 Subject: [PATCH 1/3] fix: Avoid automatic customer creation on website user login (cherry picked from commit d824a90fac68eb76d3f824249e83466201e96b02) # Conflicts: # erpnext/e_commerce/shopping_cart/utils.py --- erpnext/e_commerce/shopping_cart/utils.py | 28 +++++++++++++++-------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/erpnext/e_commerce/shopping_cart/utils.py b/erpnext/e_commerce/shopping_cart/utils.py index 51398596fd8f..5d9e239f3f3a 100644 --- a/erpnext/e_commerce/shopping_cart/utils.py +++ b/erpnext/e_commerce/shopping_cart/utils.py @@ -1,8 +1,5 @@ # Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors # License: GNU General Public License v3. See license.txt - -from __future__ import unicode_literals - import frappe import frappe.defaults @@ -17,10 +14,21 @@ def show_cart_count(): return False def set_cart_count(login_manager): - role, parties = check_customer_or_supplier() - if role == 'Supplier': return + # 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() + if not user_is_customer: return + if show_cart_count(): +<<<<<<< HEAD:erpnext/e_commerce/shopping_cart/utils.py from erpnext.e_commerce.shopping_cart.cart import set_cart_count +======= + from erpnext.shopping_cart.cart import set_cart_count + # 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 +>>>>>>> d824a90fac (fix: Avoid automatic customer creation on website user login):erpnext/shopping_cart/utils.py set_cart_count() def clear_cart_count(login_manager): @@ -31,13 +39,13 @@ def update_website_context(context): cart_enabled = is_cart_enabled() context["shopping_cart_enabled"] = cart_enabled -def check_customer_or_supplier(): - if frappe.session.user: +def is_customer(): + if frappe.session.user and frappe.session.user != "Guest": 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: - if link.link_doctype in ('Customer', 'Supplier'): - return link.link_doctype, link.link_name + if link.link_doctype == 'Customer': + return True - return 'Customer', None + return False From 6b8dad945487d1652c2db445e3c06996100f9047 Mon Sep 17 00:00:00 2001 From: marination Date: Tue, 12 Oct 2021 13:18:28 +0530 Subject: [PATCH 2/3] fix: Sider, Linter - Moved return to next line - Space between function import and body (cherry picked from commit a780f78f38b247e5679053e15ee5113f9065a68e) --- erpnext/e_commerce/shopping_cart/utils.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/erpnext/e_commerce/shopping_cart/utils.py b/erpnext/e_commerce/shopping_cart/utils.py index 5d9e239f3f3a..7665f4b5a9d4 100644 --- a/erpnext/e_commerce/shopping_cart/utils.py +++ b/erpnext/e_commerce/shopping_cart/utils.py @@ -18,13 +18,15 @@ def set_cart_count(login_manager): # make sure user is already a customer # before trying to set cart count user_is_customer = is_customer() - if not user_is_customer: return + if not user_is_customer: + return if show_cart_count(): <<<<<<< HEAD:erpnext/e_commerce/shopping_cart/utils.py from erpnext.e_commerce.shopping_cart.cart import set_cart_count ======= from erpnext.shopping_cart.cart import set_cart_count + # 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 From f3650b4f9d0f66eb4445161703ef84d552c35330 Mon Sep 17 00:00:00 2001 From: marination Date: Tue, 12 Oct 2021 20:29:13 +0530 Subject: [PATCH 3/3] fix: Merge conflicts with e-commerce --- erpnext/e_commerce/shopping_cart/utils.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/erpnext/e_commerce/shopping_cart/utils.py b/erpnext/e_commerce/shopping_cart/utils.py index 7665f4b5a9d4..0cc0ab7c0028 100644 --- a/erpnext/e_commerce/shopping_cart/utils.py +++ b/erpnext/e_commerce/shopping_cart/utils.py @@ -22,15 +22,11 @@ def set_cart_count(login_manager): return if show_cart_count(): -<<<<<<< HEAD:erpnext/e_commerce/shopping_cart/utils.py from erpnext.e_commerce.shopping_cart.cart import set_cart_count -======= - from erpnext.shopping_cart.cart import set_cart_count # 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 ->>>>>>> d824a90fac (fix: Avoid automatic customer creation on website user login):erpnext/shopping_cart/utils.py set_cart_count() def clear_cart_count(login_manager):