Skip to content

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

Open
@jornwildenbeest

Description

@jornwildenbeest

What happened?

Description

New issue in favor of #3715 because the problem still exists.

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.14.14

Craft Commerce version

4.8.3

PHP version

8.2

Operating system and version

Mac os 15.2 (24C101)

Database type and version

MySQL 8

Image driver and version

No response

Installed plugins and versions

  • Craft Commerce

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions