You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When the config autoSetNewCartAddresses is set to true (default) Commerce seems to aggressively attempt to apply an existing user address onto orders if an address is missing, regardless if the cart is new. This can cause issues when trying to clear cart addresses before applying new ones.
CartController::actionUpdateCart() calls getCart() from the Carts service. This causes autoSetAddresses() to run, which will set the _shippingAddress back to the user’s primary address if the order address is empty. The address now has the CustomerAddressBehavior. Later in actionUpdateCart() setShippingAddress() correctly uses the provided address params, but due to this conditional will incorrectly use the Address with CustomerAddressBehavior attached. Validating this address will fail.
Steps to reproduce
Front end example (address in this context can be either shipping or billing):
User has an order with address auto applied
User clears address from order (provide param(s) clearShippingAddress, clearBillingAddress, clearAdresses to commerce/cart/update-cart)
User attempts to apply new address to order (this will error)
Expected behavior
When logged in, providing an order that has no billing / shipping address data with address params, Commerce should either not apply the customer's primary address back onto the order, or ensure that the behavior isn't put onto the new address.
Craft CMS version
4.9.5
Craft Commerce version
4.6.2 (problem also exists on 5.x)
PHP version
No response
Operating system and version
No response
Database type and version
No response
Image driver and version
No response
Installed plugins and versions
The text was updated successfully, but these errors were encountered:
What happened?
Description
When the config
autoSetNewCartAddresses
is set totrue
(default) Commerce seems to aggressively attempt to apply an existing user address onto orders if an address is missing, regardless if the cart is new. This can cause issues when trying to clear cart addresses before applying new ones.Causes error:
Calling unknown method: craft\\commerce\\elements\\Order::getPrimaryBillingAddressId()
I've managed to work around this issue by ensuring that I provide the params
CustomerAddressBehavior::rules()
is expecting with my request:Cause
CartController::actionUpdateCart() calls getCart() from the Carts service. This causes autoSetAddresses() to run, which will set the _shippingAddress back to the user’s primary address if the order address is empty. The address now has the CustomerAddressBehavior. Later in actionUpdateCart() setShippingAddress() correctly uses the provided address params, but due to this conditional will incorrectly use the Address with CustomerAddressBehavior attached. Validating this address will fail.
Steps to reproduce
Front end example (address in this context can be either shipping or billing):
clearShippingAddress
,clearBillingAddress
,clearAdresses
tocommerce/cart/update-cart
)Expected behavior
When logged in, providing an order that has no billing / shipping address data with address params, Commerce should either not apply the customer's primary address back onto the order, or ensure that the behavior isn't put onto the new address.
Craft CMS version
4.9.5
Craft Commerce version
4.6.2 (problem also exists on 5.x)
PHP version
No response
Operating system and version
No response
Database type and version
No response
Image driver and version
No response
Installed plugins and versions
The text was updated successfully, but these errors were encountered: