Description
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:

Steps to reproduce
- Do a clean install with craft 4.x and copy the commerce example-templates
- Create a account and log in.
- Set a default primary address
- Open a tab with the /shop/ page.
- Clear all active carts
- Go to the /shop/ tab and refresh fast, like multiple times per second
- 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