Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Avoid automatic customer creation on website user login (backport #27914) #27926

Merged
merged 3 commits into from
Oct 27, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 16 additions & 10 deletions erpnext/e_commerce/shopping_cart/utils.py
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -17,10 +14,19 @@ 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():
from erpnext.e_commerce.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
set_cart_count()

def clear_cart_count(login_manager):
Expand All @@ -31,13 +37,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