Users whose shipping address defaults to a country with states (e.g., USA) cannot create an order that ships to a country without states (e.g., Anguilla). They will be stopped from getting past the Address phase of the checkout flow with an error saying Shipping address state does not match the country
Solidus Version:
2.8.1
To Reproduce
1 error prohibited this record from being saved: There were problems with the following fields: Shipping address state does not match the countryCurrent behavior
User cannot check out.
Expected behavior
User can check out.
Desktop (please complete the following information):
By a bit of investigation, I see that the problem is that https://github.com/solidusio/solidus/blob/master/frontend/app/controllers/spree/checkout_controller.rb#L54 which invokes https://github.com/solidusio/solidus/blob/master/core/app/models/spree/order_update_attributes.rb#L18-L25 does not perform a ship address update, I thought on a way to solve it, by following kind of what is being made with the payments in the same class, something like
def apply
order.validate_payments_attributes(@payments_attributes)
assign_order_attributes
assign_payments_attributes
assign_ship_address_attributes unless order.use_billing.in?([true, 'true', '1']) # Or moving the `Spree::Order#use_billing?` method to be public and call it
order.save
end
# ...
def assign_ship_address_attributes
# update order.ship_address attributes
end
But I'm not sure if this is a path we'd like to follow, that was just my first thought to fix this
Thanks @brchristian for reporting and @VzqzAc for these initial thoughts. I think this is also related to https://github.com/solidusio/solidus/pull/2417, which I started fixing on the view layer (by resetting the state to nilin the form). We have fixed this already the same way in backend but I think we should do something on the model layer. I know @cedum started working on this already.
Do you think we should finalize and merge https://github.com/solidusio/solidus/pull/2417/files in the meantime? Once identified the bug I think it's quite easy to fix in each application, and merging that PR will not help devs using a custom frontend, while the model level bugfix would. Let me know your thoughts.
Should be related to this part:
https://github.com/solidusio/solidus/blob/6b5c90034f1406b53982bde35ad69295878393b4/core/app/models/spree/address.rb#L181-L220
I'm splitting this logic in two parts: one that performs the state normalization before the validation occurs and another that performs the actual validation. As discussed also in #2417 it should nullify the state when a country w/o states has been chosen.
I agree on that @kennyadsl, solving this by resetting the value on the frontend does not perform a final solution, however, it would be good to still finalize #2417 so we send the proper params in the request.
I do also like @cedum's approach, normalization of the state if needed (which is this bug), and validate the state (since the validate state is receiving a non-normalized state here because of the previous method)
https://github.com/solidusio/solidus/blob/6b5c90034f1406b53982bde35ad69295878393b4/core/app/models/spree/address.rb#L216-L220
This is fixed now in master, thanks for reporting @brchristian and @cedum for the fix.
Most helpful comment
Should be related to this part:
https://github.com/solidusio/solidus/blob/6b5c90034f1406b53982bde35ad69295878393b4/core/app/models/spree/address.rb#L181-L220
I'm splitting this logic in two parts: one that performs the
statenormalization before the validation occurs and another that performs the actual validation. As discussed also in #2417 it should nullify the state when a country w/o states has been chosen.