Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Maintain compatibility with Solidus 3.0 Address#name #100

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions app/models/solidus_stripe/address_from_params_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
<%- if @order.has_checkout_step?('address') -%>
<script>
Spree.stripeAdditionalInfo = {
name: "<%= @order.bill_address.full_name %>",
name: "<%= @order.bill_address.try(:full_name) || @order.bill_address.name %>",
address_line1: "<%= @order.bill_address.address1 %>",
address_line2: "<%= @order.bill_address.address2 %>",
address_city: "<%= @order.bill_address.city %>",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<div class="field field-required">
<%= label_tag "name_on_card_#{payment_method.id}", t('spree.name_on_card') %>
<%= text_field_tag "#{param_prefix}[name]", "#{@order.billing_firstname} #{@order.billing_lastname}", { id: "name_on_card_#{payment_method.id}", autocomplete: "cc-name" } %>
<%= text_field_tag "#{param_prefix}[name]", @order.try(:billing_name) || "#{@order.billing_firstname} #{@order.billing_lastname}", { id: "name_on_card_#{payment_method.id}", autocomplete: "cc-name" } %>
</div>

<div class="field field-required" data-hook="card_number">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@
user.addresses << create(
:address, city: params[:city],
zipcode: params[:postalCode],
firstname: 'Clark',
lastname: 'Kent',
name: 'Clark Kent',
address1: params[:addressLine].first,
address2: nil,
phone: '555-555-0199'
Expand Down
6 changes: 3 additions & 3 deletions spec/support/solidus_address_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
# previous first/last name combination.
module SolidusAddressNameHelper
def fill_in_name
if Spree::Config.preferences[:use_combined_first_and_last_name_in_address]
fill_in "Name", with: "Han Solo"
else
if has_field?("First Name")
fill_in "First Name", with: "Han"
fill_in "Last Name", with: "Solo"
else
fill_in "Name", with: "Han Solo"
end
end
end