[3.4.14]: Shipping and Billing address not automatically set for a cart after logging in with a user that has primary addresses
Description
We rely on Craft Commerce setting the addresses to carts based on customers' primary shipping and billing addresses because during a checkout we do not offer to change/set them. It works as expected if a cart is created when a user is already logged in but it does not work if the cart was created as a guest and then a customer logs in with its existing user that has primary addresses - during the transfer from guest to customer cart the addresses are not automatically set.
Problems started to occur when we updated from 3.4.11 to 3.4.14 version.
Steps to reproduce
- Set commerce setting "autoSetNewCartAddresses" to true
- Create a new cart as a guest
- Login with an existing user that has primary shipping and billing addresses
- Check the cart and see that it does not have set addresses
Expected behavior
We expect that after a guest has created a cart and logged in with an existing user, Craft Commerce would automatically set shipping and billing addresses to the cart that was created initially by a guest if setting "autoSetNewCartAddresses" is set to true.
Actual behavior
After a guest creates a cart and then logs in with an existing user that has primary addresses then the cart still does not have addresses.
Ideas
I assume that by fixing this issue https://github.com/craftcms/commerce/issues/2745 in 3.4.14 version the problem was introduced because it seems like the addresses are now set only upon a new cart creation and since the guest creates a cart the addresses are not set automatically and later on there are no checks if cart should grab the addresses from a customer.
Craft CMS version
3.7.44
Craft Commerce version
3.4.15
PHP version
7.4.21
Operating system and version
No response
Database type and version
MYSQL 5.7.34
Image driver and version
No response
Installed plugins and versions
No response
This issue completely broke our website, and not just for guest carts. Somehow even when a logged in user checks out, the address isn't set based on their primary address anymore.
I tried to debug the issue but it's pretty confusing. The first time Carts::getCart is called, it looks like autoSetAddresses() is called because the cart doesn't exist yet, but the cart isn't saved. The second time Carts::getCart is called, as the result of the customer adding a line item, the cart is saved, but autoSetAddresses() isn't called so the address is blank. Seems pretty flimsy
We've encountered the same problem in the latest craft commerce 3 version (3.4.17.1) . When we are not logged in, and we add product to our cart, when we go to the checkout we have to login, register or go further as guest. After we login with an existing user with an already set primary shipping and billing address, it is not added to the cart.
Could you please take a look at this?
This will be fixed in the next release.
Commerce 3.4.19 is out with this fix.