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

[4.x]: Multiple empty carts when refreshing fast with autoSetNewCartAddresses setting #3715

Open
jornwildenbeest opened this issue Oct 11, 2024 · 5 comments
Assignees
Labels
bug commerce4 Issues related to Commerce v4 Craft Commerce

Comments

@jornwildenbeest
Copy link

jornwildenbeest commented Oct 11, 2024

What happened?

Description

When the autoSetNewCartAddresses is enabled, and you've set a default primary address in your account (yes this only applies when you are logged in), it is possible to create multiple empty carts on refresh.

This default code from the example folder:

{% if cart is not defined %}
  {% set cart = craft.commerce.carts.cart %}
{% endif %}

is creating multiple carts when you have the autoSetNewCartAddresses setting enabled and you've setup a default primary address. This happens when you refresh several times in a row. You have to refresh fast but apparently customers are doing this because we are seeing multiple empty carts in our shop.

This only happens when the user has no active carts.

When debugging I found out that this is caused because of the autoSetNewCartAddresses setting. This is causing a save on first reload when you have no active cart. So when reloading multiple times it creates multiple carts:

Image

Steps to reproduce

  1. Do a clean install with craft 4.x and copy the commerce example-templates
  2. Create a account and log in.
  3. Set a default primary address
  4. Open a tab with the /shop/ page.
  5. Clear all active carts
  6. Go to the /shop/ tab and refresh fast, like multiple times per second
  7. You will see multiple empty active carts in the control panel tied to the same user.

Expected behavior

The expected behavior is that Craft Commerce only creates 1 cart.

Actual behavior

Craft Commerce creates multiple empty carts.

Craft CMS version

4.12.6.1

Craft Commerce version

4.6.13

PHP version

8.2

Operating system and version

Mac os 14.5

Database type and version

Mysql 8

Image driver and version

No response

Installed plugins and versions

@jornwildenbeest jornwildenbeest added bug commerce4 Issues related to Commerce v4 Craft Commerce labels Oct 11, 2024
@lukeholder
Copy link
Member

Thanks for reporting. I have a potential fix coming in 4.7 - stay tuned!

@lukeholder
Copy link
Member

Fix was not included in 4.7, we are testing a better fix. Stay tuned!

@jornwildenbeest
Copy link
Author

Thanks for the updates!

@jornwildenbeest
Copy link
Author

Hi @lukeholder,

Do you have any updates?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug commerce4 Issues related to Commerce v4 Craft Commerce
Projects
None yet
Development

No branches or pull requests

2 participants