Skip to content

Commit 0ad8199

Browse files
committed
Update address form and refactored
Added translations
1 parent 3da8dd6 commit 0ad8199

File tree

8 files changed

+109
-53
lines changed

8 files changed

+109
-53
lines changed

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ gem 'pg', '~> 1.0', require: false if dbs.match?(/all|postgres/)
2121
gem 'fast_sqlite', require: false if dbs.match?(/all|sqlite/)
2222
gem 'sqlite3', '>= 2.1', require: false if dbs.match?(/all|sqlite/)
2323

24+
2425
gem 'database_cleaner', '~> 2.0', require: false
2526
gem 'rspec-activemodel-mocks', '~> 1.1', require: false
2627
gem 'rspec-rails', '~> 6.0.3', require: false

api/lib/spree/api_configuration.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,10 @@ def promotion_attributes=(value)
125125
deprecate "promotion_attributes=" => promotion_attributes_deprecation_message, deprecator: Spree.deprecator
126126

127127
preference :store_attributes, :array, default: [
128-
:id, :name, :url, :meta_description, :meta_keywords, :seo_title,
129-
:mail_from_address, :default_currency, :code, :default, :available_locales,
130-
:bcc_email, :code, :legal_name, :tax_id, :contact_phone,
131-
:contact_email, :vat_id, :description, :address
128+
:id, :name, :legal_name, :url, :meta_description, :meta_keywords, :seo_title,
129+
:mail_from_address, :default_currency, :code, :default,
130+
:bcc_email, :contact_phone, :contact_email, :tax_id, :vat_id, :description,
131+
:address1, :address2, :city, :postal_code, :country_id, :state_id, :state_name, :available_locales
132132
]
133133

134134
preference :store_credit_history_attributes, :array, default: [

api/spec/requests/spree/api/stores_spec.rb

Lines changed: 35 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,19 @@ module Spree::Api
3838
"code" => store.code,
3939
"default" => true,
4040
"available_locales" => ["en"],
41-
"legal_name": nil,
42-
"tax_id": nil,
43-
"contact_phone": nil,
44-
"contact_email": nil,
45-
"vat_id": nil,
46-
"description": nil,
47-
"address": nil
41+
"legal_name" => nil,
42+
"contact_phone" => nil,
43+
"contact_email" => nil,
44+
"description" => nil,
45+
"tax_id" => nil,
46+
"vat_id" => nil,
47+
"address1" => nil,
48+
"address2" => nil,
49+
"city" => nil,
50+
"postal_code" => nil,
51+
"country_id" => nil,
52+
"state_id" => nil,
53+
"state_name" => nil
4854
},
4955
{
5056
"id" => non_default_store.id,
@@ -59,13 +65,19 @@ module Spree::Api
5965
"code" => non_default_store.code,
6066
"default" => false,
6167
"available_locales" => ["en"],
62-
"legal_name": nil,
63-
"tax_id": nil,
64-
"contact_phone": nil,
65-
"contact_email": nil,
66-
"vat_id": nil,
67-
"description": nil,
68-
"address": nil
68+
"legal_name" => nil,
69+
"contact_phone" => nil,
70+
"contact_email" => nil,
71+
"description" => nil,
72+
"tax_id" => nil,
73+
"vat_id" => nil,
74+
"address1" => nil,
75+
"address2" => nil,
76+
"city" => nil,
77+
"postal_code" => nil,
78+
"country_id" => nil,
79+
"state_id" => nil,
80+
"state_name" => nil
6981
}
7082
])
7183
end
@@ -86,12 +98,18 @@ module Spree::Api
8698
"default" => true,
8799
"available_locales" => ["en"],
88100
"legal_name" => nil,
89-
"tax_id" => nil,
90101
"contact_phone" => nil,
91102
"contact_email" => nil,
92-
"vat_id" => nil,
93103
"description" => nil,
94-
"address" => nil
104+
"tax_id" => nil,
105+
"vat_id" => nil,
106+
"address1" => nil,
107+
"address2" => nil,
108+
"city" => nil,
109+
"postal_code" => nil,
110+
"country_id" => nil,
111+
"state_id" => nil,
112+
"state_name" => nil
95113
)
96114
end
97115

backend/app/views/spree/admin/stores/_form.html.erb

Lines changed: 40 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<div class="row">
1+
<div class="row js-addresses-form">
22
<div class="col-12 col-md-6">
33
<%= f.field_container :name do %>
44
<%= f.label :name, class: 'required' %>
@@ -37,18 +37,18 @@
3737
<%= f.error_message_on :legal_name %>
3838
<% end %>
3939

40-
<%= f.field_container :tax_id do %>
41-
<%= f.label :tax_id %>
42-
<%= f.text_field :tax_id, class: 'fullwidth' %>
43-
<%= f.error_message_on :tax_id %>
44-
<% end %>
45-
4640
<%= f.field_container :contact_phone do %>
4741
<%= f.label :contact_phone %>
4842
<%= f.phone_field :contact_phone, class: 'fullwidth' %>
4943
<%= f.error_message_on :contact_phone %>
5044
<% end %>
5145

46+
<%= f.field_container :tax_id do %>
47+
<%= f.label :tax_id %>
48+
<%= f.text_field :tax_id, class: 'fullwidth' %>
49+
<%= f.error_message_on :tax_id %>
50+
<% end %>
51+
5252
<%= f.field_container :vat_id do %>
5353
<%= f.label :vat_id %>
5454
<%= f.text_field :vat_id, class: 'fullwidth' %>
@@ -116,39 +116,53 @@
116116

117117
<%= f.field_container :description do %>
118118
<%= f.label :description %>
119-
<%= f.text_area :description, class: 'fullwidth', style: 'height: 130px;' %>
119+
<%= f.text_area :description, class: 'fullwidth', rows: 6 %>
120120
<%= f.error_message_on :description %>
121121
<% end %>
122122
</div>
123123

124124
<div class="col-12">
125-
<%= f.label :address, "Address" %>
125+
<%= f.label :address %>
126126
<div class="row border mx-1 py-3 border-secondary rounded">
127127
<div class="col-md-6 mb-3">
128-
<%= f.label :streetAddress, "Street Address", class: "form-label" %>
129-
<%= text_field_tag 'store[address][streetAddress]', f.object.address&.dig('streetAddress'), class: 'form-control', placeholder: "Street Address" %>
128+
<%= f.field_container :address1 do %>
129+
<%= f.label :address1 %>
130+
<%= f.text_field :address1, class: 'fullwidth' %>
131+
<% end %>
130132
</div>
131-
132133
<div class="col-md-6 mb-3">
133-
<%= f.label :addressLocality, "City", class: "form-label" %>
134-
<%= text_field_tag 'store[address][addressLocality]', f.object.address&.dig('addressLocality'), class: 'form-control', placeholder: "City" %>
134+
<%= f.field_container :address2 do %>
135+
<%= f.label :address2 %>
136+
<%= f.text_field :address2, class: 'fullwidth' %>
137+
<% end %>
135138
</div>
136-
137139
<div class="col-md-6 mb-3">
138-
<%= f.label :addressRegion, "Region", class: "form-label" %>
139-
<%= text_field_tag 'store[address][addressRegion]', f.object.address&.dig('addressRegion'), class: 'form-control', placeholder: "Region" %>
140+
<%= f.field_container :city do %>
141+
<%= f.label :city %>
142+
<%= f.text_field :city, class: 'fullwidth' %>
143+
<% end %>
140144
</div>
141-
142-
<div class="mb-3 col-md-6">
143-
<%= f.label :addressCountry, "Country", class: "form-label" %>
144-
<%= select_tag 'store[address][addressCountry]',
145-
options_from_collection_for_select(available_countries(restrict_to_zone: nil), :id, :name, f.object.address&.dig('addressCountry')),
146-
class: 'form-control', placeholder: "Country" %>
145+
<div class="col-md-6 mb-3">
146+
<%= f.field_container :postal_code do %>
147+
<%= f.label :postal_code %>
148+
<%= f.text_field :postal_code, class: 'fullwidth' %>
149+
<% end %>
150+
</div>
151+
<div class="col-md-6 mb-3">
152+
<%= f.field_container :country_id do %>
153+
<%= f.label :country_id %>
154+
<span id="country"><%= f.collection_select :country_id, available_countries(restrict_to_zone: nil), :id, :name, { include_blank: true }, { class: 'custom-select js-country_id fullwidth' } %></span>
155+
<% end %>
147156
</div>
148-
149157
<div class="col-md-6 mb-3">
150-
<%= f.label :postalCode, "Postal Code", class: "form-label" %>
151-
<%= text_field_tag 'store[address][postalCode]', f.object.address&.dig('postalCode'), class: 'form-control', placeholder: "Postal Code" %>
158+
<%= f.field_container :state do %>
159+
<% country = f.object.country %>
160+
<%= f.label :state_id %>
161+
<span id="state" class="region">
162+
<%= f.text_field :state_name, style: "display: none", class: 'fullwidth state_name js-state_name' %>
163+
<%= f.collection_select :state_id, country ? country.states.sort : [], :id, :name, { include_blank: true }, {class: 'custom-select fullwidth js-state_id', style: "display: none" } %>
164+
</span>
165+
<% end %>
152166
</div>
153167
</div>
154168
</div>

core/app/models/spree/store.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ class Store < Spree::Base
1515
has_many :store_shipping_methods, inverse_of: :store
1616
has_many :shipping_methods, through: :store_shipping_methods
1717

18+
belongs_to :state, class_name: 'Spree::State', optional: true
19+
belongs_to :country, class_name: 'Spree::Country', optional: true
20+
1821
has_many :orders, class_name: "Spree::Order"
1922

2023
validates :code, presence: true, uniqueness: { allow_blank: true, case_sensitive: true }

core/config/locales/en.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,18 +350,31 @@ en:
350350
quantity: Quantity
351351
variant: Variant
352352
spree/store:
353+
address: Address
354+
address1: Street Address
355+
address2: Street Address (cont'd)
353356
available_locales: Locales Available in the Storefront
354357
bcc_email: BCC Email
355358
cart_tax_country_iso: Tax Country for Empty Carts
359+
city: City
356360
code: Slug
361+
contact_email: Contact Email
362+
contact_phone: Contact Phone
363+
country_id: Country
357364
default: Default
358365
default_currency: Default Currency
366+
description: Store Description
367+
legal_name: Legal Name
359368
mail_from_address: Mail From Address
360369
meta_description: Meta Description
361370
meta_keywords: Meta Keywords
362371
name: Site Name
372+
postal_code: Postal Code
363373
seo_title: Seo Title
374+
state_id: State
375+
tax_id: Tax ID
364376
url: Site URL
377+
vat_id: VAT ID
365378
spree/store_credit:
366379
amount: Amount
367380
amount_authorized: Amount Authorized
Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
class AddStoreAttributesToSpreeStores < ActiveRecord::Migration[7.2]
22
def change
33
add_column :spree_stores, :legal_name, :string
4-
add_column :spree_stores, :tax_id, :string
5-
add_column :spree_stores, :address, :jsonb
64
add_column :spree_stores, :contact_phone, :string
75
add_column :spree_stores, :contact_email, :string
8-
add_column :spree_stores, :vat_id, :string
96
add_column :spree_stores, :description, :text
7+
add_column :spree_stores, :vat_id, :string
8+
add_column :spree_stores, :tax_id, :string
9+
add_column :spree_stores, :address1, :string
10+
add_column :spree_stores, :address2, :string
11+
add_column :spree_stores, :city, :string
12+
add_column :spree_stores, :postal_code, :string
13+
add_column :spree_stores, :state_name, :string
14+
add_reference :spree_stores, :country, foreign_key: { to_table: :spree_countries }, index: true
15+
add_reference :spree_stores, :state, foreign_key: { to_table: :spree_states }, index: true
1016
end
1117
end

core/lib/spree/permitted_attributes.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,12 @@ module PermittedAttributes
110110
:quantity, :stock_item, :stock_item_id, :originator, :action
111111
]
112112

113-
@@store_attributes = [:name, :url, :seo_title, :meta_keywords,
113+
@@store_attributes = [:name, :legal_name, :url, :seo_title, :meta_keywords,
114114
:meta_description, :default_currency,
115115
:mail_from_address, :cart_tax_country_iso,
116-
:bcc_email, :code, :legal_name, :tax_id, :contact_phone,
117-
:contact_email, :vat_id, :description, address: {}]
116+
:bcc_email, :contact_email, :contact_phone, :code,
117+
:tax_id, :vat_id, :description, :address1, :address2,
118+
:city, :postal_code, :country_id, :state_id, :state_name]
118119

119120
@@taxonomy_attributes = [:name]
120121

0 commit comments

Comments
 (0)