Skip to content

Commit 4254d40

Browse files
committed
Update backend to have firstname and lastname fields
- Update the backend logic to separate 'name' into 'firstname' and 'lastname' for better data handling. - Adjusted user and address forms, search functionality, and related views to use the new fields.
1 parent fa9c4df commit 4254d40

File tree

15 files changed

+52
-26
lines changed

15 files changed

+52
-26
lines changed

backend/app/assets/javascripts/spree/backend/templates/orders/customer_details/autocomplete.hbs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<div class='customer-autocomplete-item'>
22
<div class='customer-details'>
33
<span class="customer-email">{{customer.email}}</span>
4-
{{#if bill_address.name }}
4+
{{#if bill_address.firstname }}
55
<strong>{{t 'bill_address' }}</strong>
6-
{{bill_address.name}}<br>
6+
{{bill_address.firstname}} {{bill_address.lastname}}<br>
77
{{bill_address.address1}}, {{bill_address.address2}}<br>
88
{{bill_address.city}}<br>
99
{{#if bill_address.state_id }}

backend/app/assets/javascripts/spree/backend/user_picker.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ $.fn.userAutocomplete = function () {
2828
q: {
2929
m: 'or',
3030
email_start: term,
31-
name_start: term
31+
firstname_start: term,
32+
lastname_start: term
3233
}
3334
};
3435
},

backend/app/assets/javascripts/spree/backend/views/order/address.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Spree.Views.Order.Address = Backbone.View.extend({
2323

2424
eachField: function(callback){
2525
var view = this;
26-
var fields = ["name", "company", "address1", "address2",
26+
var fields = ["firstname", "lastname", "company", "address1", "address2",
2727
"city", "zipcode", "phone", "country_id", "state_name"];
2828
_.each(fields, function(field) {
2929
var el = view.$('[name$="[' + field + ']"]');

backend/app/assets/javascripts/spree/backend/views/order/customer_select.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ Spree.Views.Order.CustomerSelect = Backbone.View.extend({
3434
q: {
3535
m: 'or',
3636
email_start: term,
37-
name_start: term
37+
firstname_start: term,
38+
lastname_start: term
3839
}
3940
}
4041
},

backend/app/assets/stylesheets/spree/backend/sections/_orders.scss

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@
6464
margin-bottom: 15px;
6565
}
6666

67-
label[for="order_bill_address_attributes_name"] {
68-
margin-top: 53.5px;
67+
label[for="order_bill_address_attributes_firstname"] {
68+
margin-top: 45px;
6969
}
7070

7171
#risk_analysis legend {

backend/app/controllers/spree/admin/search_controller.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ def users
1616
@users = Spree.user_class.ransack({
1717
m: 'or',
1818
email_start: params[:q],
19-
name_start: params[:q]
19+
addresses_firstname_start: params[:q],
20+
addresses_lastname_start: params[:q]
2021
}).result.limit(10)
2122
end
2223
end

backend/app/views/spree/admin/search/users.json.jbuilder

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ json.array!(@users) do |user|
55
json.email user.email
66

77
address_fields = [
8-
:name,
8+
:firstname,
9+
:lastname,
910
:address1,
1011
:address2,
1112
:city,

backend/app/views/spree/admin/shared/_address.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<div data-hook="address">
2-
<%= address.name %> <%= address.company unless address.company.blank? %><br>
2+
<%= "#{address.firstname} #{address.lastname} " %> <%= address.company unless address.company.blank? %><br>
33
<%= address.phone %><%= address.alternative_phone unless address.alternative_phone.blank? %><br>
44
<%= address.address1 %><br>
55
<% if address.address2.present? %><%= address.address2 %><br><% end %>

backend/app/views/spree/admin/shared/_address_form.html.erb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,13 @@
22

33
<div id="<%= type %>" data-hook="address_fields">
44
<div class="field <%= "#{type}-row" %>">
5-
<%= f.label :name %>
6-
<%= f.text_field :name, class: 'fullwidth' %>
5+
<%= f.label :firstname %>
6+
<%= f.text_field :firstname, class: 'fullwidth' %>
7+
</div>
8+
9+
<div class="field <%= "#{type}-row" %>">
10+
<%= f.label :lastname %>
11+
<%= f.text_field :lastname, class: 'fullwidth' %>
712
</div>
813

914
<% if Spree::Config[:company] %>

backend/lib/spree/backend_configuration.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ class BackendConfiguration < Preferences::Configuration
7272
{
7373
partial: "spree/admin/shared/search_fields/text_field",
7474
locals: {
75-
ransack: :bill_address_name_cont,
75+
ransack: :bill_address_firstname_or_bill_address_lastname_cont,
7676
label: -> { I18n.t(:name_contains, scope: :spree) }
7777
}
7878
},

0 commit comments

Comments
 (0)