diff --git a/app/models/solidus_stripe/address_from_params_service.rb b/app/models/solidus_stripe/address_from_params_service.rb index 5c56d4a9..5e8f588a 100644 --- a/app/models/solidus_stripe/address_from_params_service.rb +++ b/app/models/solidus_stripe/address_from_params_service.rb @@ -12,7 +12,13 @@ def call if user user.addresses.find_or_initialize_by(attributes) else - Spree::Address.new(attributes) + begin + Spree::Address.new(attributes) + rescue ActiveModel::UnknownAttributeError # Handle old address format + name = attributes.delete!(:name) + attributes[:first_name], attributes[:last_name] = name.split(/[[:space:]]/, 2) + Spree::Address.new(attributes) + end end end @@ -24,12 +30,11 @@ def attributes # possibly anonymized attributes: phone = address_params[:phone] lines = address_params[:addressLine] - names = address_params[:recipient].split(' ') + name = address_params[:recipient] attributes.merge!( state_id: state&.id, - firstname: names.first, - lastname: names.last, + name: name, phone: phone, address1: lines.first, address2: lines.second diff --git a/lib/views/frontend/spree/checkout/payment/v2/_javascript.html.erb b/lib/views/frontend/spree/checkout/payment/v2/_javascript.html.erb index 6f5d27ee..93b815db 100644 --- a/lib/views/frontend/spree/checkout/payment/v2/_javascript.html.erb +++ b/lib/views/frontend/spree/checkout/payment/v2/_javascript.html.erb @@ -66,7 +66,7 @@ <%- if @order.has_checkout_step?('address') -%>