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 #27914

Merged

Conversation

marination
Copy link
Collaborator

Issue:

TLDR: When a website user logs in, if they are not a customer and if cart is enabled, a customer was automatically created

  • This user could have been created for blogs, or for other purposes, and not e-commerce.
  • This happens because: on login, hooks triggers an event that sets the cart count. For this it tries to fetch the current users shopping cart (cart quotation). If it cannot find a quotation it creates a new one against this user. While doing this, it creates a customer if non-existent.
  • If a quotation is found then its items count becomes the cart count, else an empty quotation(cart) is initialised.
  • If a logged in user has ever added anything to cart, they are made a customer in the backend. So if this user is not a customer, we don't need to refresh the cart at all, it will be empty or non-existent.

Fix:

  • Setting of cart count (refreshing the cart count) must happen only if the user logging in is a valid customer in the system. Otherwise the user has no business with the cart.
  • Changed check_customer_or_supplier to is_customer. If supplier we were exiting the function anyway so why return it.

To test:

  • Create a new website user (do not use this user for e-commerce)
  • login as this user
  • Check if customer was auto created after login

- Moved return to next line
- Space between function import and body
@marination marination force-pushed the avoid-auto-customer-creation-website branch from 197a3f0 to a780f78 Compare October 12, 2021 07:59
@codecov
Copy link

codecov bot commented Oct 12, 2021

Codecov Report

Merging #27914 (a780f78) into develop (401e22f) will decrease coverage by 0.03%.
The diff coverage is 12.50%.

@@             Coverage Diff             @@
##           develop   #27914      +/-   ##
===========================================
- Coverage    54.40%   54.37%   -0.04%     
===========================================
  Files         1254     1254              
  Lines        67717    67720       +3     
===========================================
- Hits         36840    36820      -20     
- Misses       30877    30900      +23     
Impacted Files Coverage Δ
erpnext/shopping_cart/utils.py 32.14% <12.50%> (-3.58%) ⬇️
...tch_item_expiry_status/batch_item_expiry_status.py 69.81% <0.00%> (-24.53%) ⬇️
...wise_balance_history/batch_wise_balance_history.py 69.49% <0.00%> (-22.04%) ⬇️
...ctype/woocommerce_settings/woocommerce_settings.py 80.39% <0.00%> (-3.93%) ⬇️
erpnext/stock/reorder_item.py 74.57% <0.00%> (-3.39%) ⬇️
...ctype/accounting_dimension/accounting_dimension.py 64.34% <0.00%> (-1.56%) ⬇️
...e/period_closing_voucher/period_closing_voucher.py 88.23% <0.00%> (-1.48%) ⬇️
erpnext/portal/utils.py 30.00% <0.00%> (-1.43%) ⬇️
.../report/stock_projected_qty/stock_projected_qty.py 88.31% <0.00%> (-1.30%) ⬇️
erpnext/stock/stock_ledger.py 85.76% <0.00%> (-1.27%) ⬇️
... and 13 more

@marination marination added needs-tests This PR needs automated unit-tests. and removed needs-tests This PR needs automated unit-tests. labels Oct 12, 2021
@marination
Copy link
Collaborator Author

marination commented Oct 12, 2021

Not sure what test to write here, it just refreshes cart count. test case is too specific.

Failing UI tests are unrelated

@marination marination merged commit b6da7ff into frappe:develop Oct 12, 2021
@marination
Copy link
Collaborator Author

@Mergifyio backport version-13-hotfix

@mergify
Copy link
Contributor

mergify bot commented Oct 12, 2021

Command backport version-13-hotfix: success

Backports have been created

marination added a commit that referenced this pull request Oct 27, 2021
…-27914

fix: Avoid automatic customer creation on website user login (backport #27914)
asoral pushed a commit to asoral/erpnext that referenced this pull request Nov 12, 2021
…reation-website

fix: Avoid automatic customer creation on website user login
asoral pushed a commit to asoral/erpnext that referenced this pull request Nov 12, 2021
…fix/pr-27914

fix: Avoid automatic customer creation on website user login (backport frappe#27914)
@rasos
Copy link
Contributor

rasos commented Nov 15, 2021

We need to test the B2C scenario: a new user registers as s/he wants to buy an item with the cart. So that user is immediately a customer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants