Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
>
<div class="<%= stimulus_id %>--address-form flex flex-wrap gap-4 pb-4">
<%= render component("ui/forms/field").text_field(@name, :name, object: @address) %>
<%= render component("ui/forms/field").text_field(@name, :firstname, object: @address) %>
<%= render component("ui/forms/field").text_field(@name, :lastname, object: @address) %>
<% if Spree::Config[:company] %>
<%= render component("ui/forms/field").text_field(@name, :company, object: @address) %>
<% end %>
<%= render component("ui/forms/field").text_field(@name, :address1, object: @address) %>
<%= render component("ui/forms/field").text_field(@name, :address2, object: @address) %>
<div class="flex gap-4 w-full">
Expand Down
4 changes: 4 additions & 0 deletions admin/spec/features/orders/show_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@

within("dialog") do
fill_in "Name", with: "John Doe"
fill_in "First Name", with: "John"
fill_in "Last Name", with: "Doe"
fill_in "Street Address", with: "1 John Doe Street"
fill_in "Street Address (cont'd)", with: "Apartment 2"
fill_in "City", with: "John Doe City"
Expand All @@ -78,6 +80,8 @@

within("dialog") do
fill_in "Name", with: "Jane Doe"
fill_in "First Name", with: "Jane"
fill_in "Last Name", with: "Doe"
fill_in "Street Address", with: "1 Jane Doe Street"
fill_in "Street Address (cont'd)", with: "Apartment 3"
fill_in "City", with: "Jane Doe City"
Expand Down
8 changes: 7 additions & 1 deletion admin/spec/features/users_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -129,28 +129,32 @@
# Invalid submission
within("form.ship_address") do
fill_in "Name", with: ""
fill_in "First Name", with: ""
fill_in "Street Address", with: ""
click_on "Update"
end
expect(page).to have_content("can't be blank").twice
expect(page).to have_content("can't be blank").thrice

# Valid submission
within("form.bill_address") do
fill_in "Name", with: "Galadriel"
fill_in "First Name", with: "Galadriel"
click_on "Update"
end
expect(page).to have_content("Billing Address has been successfully updated.")

# Valid submission
within("form.ship_address") do
fill_in "Name", with: "Elrond"
fill_in "First Name", with: "Elrond"
click_on "Update"
end
expect(page).to have_content("Shipping Address has been successfully updated.")

# Cancel submission
within("form.bill_address") do
fill_in "Name", with: "Smeagol"
fill_in "First Name", with: "Smeagol"
click_on "Cancel"
end
expect(page).to have_content("Users / [email protected] / Addresses")
Expand All @@ -159,6 +163,8 @@
# The address forms weirdly only have values rather than actual text on the page.
expect(page).to have_field("user[bill_address_attributes][name]", with: "Galadriel")
expect(page).to have_field("user[ship_address_attributes][name]", with: "Elrond")
expect(page).to have_field("user[bill_address_attributes][firstname]", with: "Galadriel")
expect(page).to have_field("user[ship_address_attributes][firstname]", with: "Elrond")
end
end

Expand Down
2 changes: 2 additions & 0 deletions admin/spec/requests/solidus_admin/users_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
user: {
bill_address_attributes: {
name: address.name,
firstname: address.firstname,
lastname: address.lastname,
address1: address.address1,
address2: address.address2,
city: address.city,
Expand Down
2 changes: 1 addition & 1 deletion api/lib/spree/api_configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class ApiConfiguration < Preferences::Configuration
]

preference :address_attributes, :array, default: [
:id, :name, :address1, :address2, :city, :zipcode, :phone, :company,
:id, :name, :firstname, :lastname, :address1, :address2, :city, :zipcode, :phone, :company,
:alternative_phone, :country_id, :country_iso, :state_id, :state_name,
:state_text
]
Expand Down
12 changes: 10 additions & 2 deletions api/spec/requests/spree/api/address_books_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ module Spree::Api
let!(:harry_address_attributes) do
{
'name' => 'Harry Potter',
'firstname' => 'Harry',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

according to your validation this address record is now invalid. It can either have a name attribute or firstname and lastname. But never both.

This is just an example for what I saw in lot of your tests. We should make sure we never mix both approaches. This is why I am still in favor of just re-introducing firstname and using name as lastname if firstname is present. But never touch the address (and ignore the firstname) if name is already present.

'lastname' => 'Potter',
'address1' => '4 Privet Drive',
'address2' => 'cupboard under the stairs',
'city' => 'Surrey',
Expand All @@ -21,6 +23,8 @@ module Spree::Api
let!(:ron_address_attributes) do
{
'name' => 'Ron Weasly',
'firstname' => 'Ron',
'lastname' => 'Weasly',
'address1' => 'Ottery St. Catchpole',
'address2' => '4th floor',
'city' => 'Devon, West Country',
Expand Down Expand Up @@ -54,6 +58,8 @@ module Spree::Api
user = create(:user, spree_api_key: 'galleon')
address = user.save_in_address_book(harry_address_attributes, true)
harry_address_attributes['name'] = 'Ron Weasly'
harry_address_attributes['firstname'] = 'Ron'
harry_address_attributes['lastname'] = 'Weasly'

expect {
put "/api/users/#{user.id}/address_book",
Expand All @@ -73,7 +79,7 @@ module Spree::Api

context "when updating a default address" do
let(:user) { create(:user, spree_api_key: 'galleon') }
let(:changes) { { name: "Hermione Granger", id: user.ship_address.id} }
let(:changes) { { name: "Hermione Granger", firstname: "Hermione", lastname: "Granger", id: user.ship_address.id} }
before do
# Create "Harry Potter" default shipping address
user.save_in_address_book(harry_address_attributes, true)
Expand Down Expand Up @@ -168,7 +174,9 @@ module Spree::Api
it "updates another user's address" do
other_user = create(:user)
address = other_user.save_in_address_book(harry_address_attributes, true)
updated_harry_address = harry_address_attributes.merge('name' => 'Ron Weasly')
harry_address_attributes.merge('firstname' => 'Ron')
harry_address_attributes.merge('name' => 'Ron Weasly')
updated_harry_address = harry_address_attributes.merge('lastname' => 'Weasly')

expect {
put "/api/users/#{other_user.id}/address_book",
Expand Down
4 changes: 4 additions & 0 deletions api/spec/requests/spree/api/checkouts_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ module Spree::Api
let(:address) do
{
name: 'John Doe',
firstname: 'John',
lastname: 'Doe',
address1: '7735 Old Georgetown Road',
city: 'Bethesda',
phone: '3014445002',
Expand All @@ -96,6 +98,8 @@ module Spree::Api
expect(json_response['state']).to eq('delivery')
expect(json_response['bill_address']['name']).to eq('John Doe')
expect(json_response['ship_address']['name']).to eq('John Doe')
expect(json_response['bill_address']['firstname']).to eq('John')
expect(json_response['ship_address']['firstname']).to eq('John')
expect(response.status).to eq(200)
end

Expand Down
4 changes: 2 additions & 2 deletions api/spec/requests/spree/api/orders_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -531,12 +531,12 @@ module Spree::Api

let(:address_params) { { country_id: country.id } }
let(:billing_address) {
{ name: "Tiago Motta", address1: "Av Paulista",
{ name: "Tiago Motta", firstname: "Tiago", lastname: "Motta", address1: "Av Paulista",
city: "Sao Paulo", zipcode: "01310-300", phone: "12345678",
country_id: country.id, state_id: state.id }
}
let(:shipping_address) {
{ name: "Tiago Motta", address1: "Av Paulista",
{ name: "Tiago Motta", firstname: "Tiago", lastname: "Motta", address1: "Av Paulista",
city: "Sao Paulo", zipcode: "01310-300", phone: "12345678",
country_id: country.id, state_id: state.id }
}
Expand Down
8 changes: 8 additions & 0 deletions api/spec/requests/spree/api/users_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ module Spree::Api
email: "[email protected]",
bill_address_attributes: {
name: 'First Last',
firstname: 'First',
lastname: 'Last',
address1: '1 Test Rd',
city: 'City',
country_id: country.id,
Expand All @@ -60,6 +62,8 @@ module Spree::Api
},
ship_address_attributes: {
name: 'First Last',
firstname: 'First',
lastname: 'Last',
address1: '1 Test Rd',
city: 'City',
country_id: country.id,
Expand All @@ -84,6 +88,8 @@ module Spree::Api
email: "[email protected]",
bill_address_attributes: {
name: 'First Last',
firstname: 'First',
lastname: 'Last',
address1: '1 Test Rd',
city: 'City',
country_id: country.id,
Expand All @@ -93,6 +99,8 @@ module Spree::Api
},
ship_address_attributes: {
name: 'First Last',
firstname: 'First',
lastname: 'Last',
address1: '1 Test Rd',
city: 'City',
country_id: country.id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
{{#if bill_address.name }}
<strong>{{t 'bill_address' }}</strong>
{{bill_address.name}}<br>
{{bill_address.firstname}} {{bill_address.lastname}}<br>
{{bill_address.address1}}, {{bill_address.address2}}<br>
{{bill_address.city}}<br>
{{#if bill_address.state_id }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ $.fn.userAutocomplete = function () {
q: {
m: 'or',
email_start: term,
name_start: term
name_start: term,
firstname_start: term,
lastname_start: term
}
};
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Spree.Views.Order.Address = Backbone.View.extend({

eachField: function(callback){
var view = this;
var fields = ["name", "company", "address1", "address2",
var fields = ["name", "firstname", "lastname", "company", "address1", "address2",
"city", "zipcode", "phone", "country_id", "state_name"];
_.each(fields, function(field) {
var el = view.$('[name$="[' + field + ']"]');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ Spree.Views.Order.CustomerSelect = Backbone.View.extend({
q: {
m: 'or',
email_start: term,
name_start: term
name_start: term,
firstname_start: term,
lastname_start: term
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
}

label[for="order_bill_address_attributes_name"] {
margin-top: 53.5px;
margin-top: 45px;
}

#risk_analysis legend {
Expand Down
4 changes: 3 additions & 1 deletion backend/app/controllers/spree/admin/search_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ def users
@users = Spree.user_class.ransack({
m: 'or',
email_start: params[:q],
name_start: params[:q]
name_start: params[:q],
addresses_firstname_start: params[:q],
addresses_lastname_start: params[:q]
}).result.limit(10)
end
end
Expand Down
2 changes: 2 additions & 0 deletions backend/app/views/spree/admin/search/users.json.jbuilder
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ json.array!(@users) do |user|

address_fields = [
:name,
:firstname,
:lastname,
:address1,
:address2,
:city,
Expand Down
2 changes: 1 addition & 1 deletion backend/app/views/spree/admin/shared/_address.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div data-hook="address">
<%= address.name %> <%= address.company unless address.company.blank? %><br>
<%= address.name %> <%= "#{address.firstname} #{address.lastname} " %> <%= address.company unless address.company.blank? %><br>
<%= address.phone %><%= address.alternative_phone unless address.alternative_phone.blank? %><br>
<%= address.address1 %><br>
<% if address.address2.present? %><%= address.address2 %><br><% end %>
Expand Down
10 changes: 10 additions & 0 deletions backend/app/views/spree/admin/shared/_address_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@
<%= f.text_field :name, class: 'fullwidth' %>
</div>

<div class="field <%= "#{type}-row" %>">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we cannot just introduce the two attributes as additional fields in the forms. How inconsistent is that? We need a toggle (or some very clever logic) to either show the two separate fields or the name field. But never both. Still I think just re-introducing the firstname as an option (via a configuration) is our best bet and helps migrating data. Please elaborate why you just introduced the two additional fields. Maybe I am missing something?

<%= f.label :firstname %>
<%= f.text_field :firstname, class: 'fullwidth' %>
</div>

<div class="field <%= "#{type}-row" %>">
<%= f.label :lastname %>
<%= f.text_field :lastname, class: 'fullwidth' %>
</div>

<% if Spree::Config[:company] %>
<div class="field <%= "#{type}-row" %>">
<%= f.label :company %>
Expand Down
2 changes: 1 addition & 1 deletion backend/lib/spree/backend_configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class BackendConfiguration < Preferences::Configuration
{
partial: "spree/admin/shared/search_fields/text_field",
locals: {
ransack: :bill_address_name_cont,
ransack: :bill_address_firstname_or_bill_address_lastname_cont,
label: -> { I18n.t(:name_contains, scope: :spree) }
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ module Admin
let(:address_attributes) do
{
'name' => address.name,
'firstname' => address.firstname,
'address1' => address.address1,
'city' => address.city,
'country_id' => address.country_id,
Expand Down
26 changes: 25 additions & 1 deletion backend/spec/controllers/spree/admin/search_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def starting_letters(string)
end
end

context 'when searching by ship addresss name' do
context 'when searching by ship address name' do
it_should_behave_like 'user found by search' do
let(:search_query) { starting_letters(user.ship_address.name) }
end
Expand All @@ -48,6 +48,30 @@ def starting_letters(string)
let(:search_query) { starting_letters(user.bill_address.name) }
end
end

context 'when searching by ship address first name' do
it_should_behave_like 'user found by search' do
let(:search_query) { starting_letters(user.ship_address.firstname) }
end
end

context 'when searching by bill address first name' do
it_should_behave_like 'user found by search' do
let(:search_query) { starting_letters(user.bill_address.firstname) }
end
end

context 'when searching by ship address last name' do
it_should_behave_like 'user found by search' do
let(:search_query) { starting_letters(user.ship_address.lastname) }
end
end

context 'when searching by bill address last name' do
it_should_behave_like 'user found by search' do
let(:search_query) { starting_letters(user.bill_address.lastname) }
end
end
end

context 'when searching by user ids' do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
let(:valid_address_attributes) do
{
name: 'Foo Bar',
firstname: 'Foo',
lastname: 'Bar',
city: "New York",
country_id: state.country.id,
state_id: state.id,
Expand Down
Loading
Loading