Skip to content

Commit

Permalink
fix(ecom): do not create a new contact if a contact already exists (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
nextchamp-saqib authored Jan 26, 2024
1 parent 169c7f3 commit 47c591c
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions erpnext/e_commerce/shopping_cart/cart.py
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,7 @@ def get_party(user=None):
contact_name = get_contact_name(user)
party = None

contact = None
if contact_name:
contact = frappe.get_doc("Contact", contact_name)
if contact.links:
Expand Down Expand Up @@ -538,11 +539,15 @@ def get_party(user=None):
customer.flags.ignore_mandatory = True
customer.insert(ignore_permissions=True)

contact = frappe.new_doc("Contact")
contact.update({"first_name": fullname, "email_ids": [{"email_id": user, "is_primary": 1}]})
if not contact:
contact = frappe.new_doc("Contact")
contact.update({"first_name": fullname, "email_ids": [{"email_id": user, "is_primary": 1}]})
contact.insert(ignore_permissions=True)
contact.reload()

contact.append("links", dict(link_doctype="Customer", link_name=customer.name))
contact.flags.ignore_mandatory = True
contact.insert(ignore_permissions=True)
contact.save(ignore_permissions=True)

return customer

Expand Down

0 comments on commit 47c591c

Please sign in to comment.