Skip to content

armgit / spree

Public Imported from GitHub
0

Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.

CR remarks & adjusted specs

Przemek Kosakowski2759cee7147a
diff --git a/api/app/serializers/spree/v2/storefront/store_serializer.rb b/api/app/serializers/spree/v2/storefront/store_serializer.rb
index 7bf8e8a5bf..735922f5f9 100644
--- a/api/app/serializers/spree/v2/storefront/store_serializer.rb
+++ b/api/app/serializers/spree/v2/storefront/store_serializer.rb
@@ -7,6 +7,8 @@ module Spree
attributes :name, :url, :meta_description, :meta_keywords, :seo_title, :default_currency, :default, :supported_currencies, :facebook,
:twitter, :instagram, :default_locale, :customer_support_email, :default_country_id, :description,
:address, :contact_phone, :contact_email
+
+ has_one :default_country, serializer: :country, record_type: :country, id_method_name: :default_country_id
end
end
end
diff --git a/api/spec/requests/spree/api/v2/storefront/stores_controller_spec.rb b/api/spec/requests/spree/api/v2/storefront/stores_controller_spec.rb
index 5072ae8e33..5ae72e4353 100644
--- a/api/spec/requests/spree/api/v2/storefront/stores_controller_spec.rb
+++ b/api/spec/requests/spree/api/v2/storefront/stores_controller_spec.rb
@@ -1,7 +1,7 @@
require 'spec_helper'
describe 'Storefront API v2 Stores spec', type: :request do
- let!(:store) { create(:store) }
+ let!(:store) { create(:store, default_country: create(:country)) }
describe 'stores#show' do
context 'with code param' do
@@ -20,12 +20,13 @@ describe 'Storefront API v2 Stores spec', type: :request do
expect(json_response['data']).to have_attribute(:twitter).with_value(store.twitter)
expect(json_response['data']).to have_attribute(:instagram).with_value(store.instagram)
expect(json_response['data']).to have_attribute(:default_locale).with_value(store.default_locale)
- expect(json_response['data']).to have_attribute(:customer_support_email).with_value(store.customer_support_email)
- expect(json_response['data']).to have_attribute(:default_country_id).with_value(store.default_country_id)
expect(json_response['data']).to have_attribute(:description).with_value(store.description)
expect(json_response['data']).to have_attribute(:address).with_value(store.address)
expect(json_response['data']).to have_attribute(:contact_phone).with_value(store.contact_phone)
expect(json_response['data']).to have_attribute(:contact_email).with_value(store.contact_email)
+
+ expect(json_response['data']).to have_relationship(:default_country)
+ expect(json_response['data']).to have_relationship(:default_country).with_data('id' => store.default_country_id.to_s, 'type' => 'country')
end
end
diff --git a/backend/app/helpers/spree/admin/stores_helper.rb b/backend/app/helpers/spree/admin/stores_helper.rb
index c99a988d41..0787cb1ee2 100644
--- a/backend/app/helpers/spree/admin/stores_helper.rb
+++ b/backend/app/helpers/spree/admin/stores_helper.rb
@@ -3,15 +3,16 @@ module Spree
module StoresHelper
def selected_checkout_zone(store)
return store.checkout_zone_id unless store.checkout_zone_id.nil?
- return checkout_zone('No Limits').id if Spree::Config[:checkout_zone].nil?
+ return checkout_zone_id('No Limits') if Spree::Config[:checkout_zone].nil?
- return checkout_zone(Spree::Config[:checkout_zone]).id unless Spree::Config[:checkout_zone].nil?
+ return checkout_zone_id(Spree::Config[:checkout_zone]) unless Spree::Config[:checkout_zone].nil?
end
private
- def checkout_zone(name)
- Spree::Zone.find_by(name: name)
+ def checkout_zone_id(name)
+ zone = Spree::Zone.find_by(name: name)
+ zone.nil? ? 0 : zone.id
end
end
end
diff --git a/backend/app/views/spree/admin/stores/_form.html.erb b/backend/app/views/spree/admin/stores/_form.html.erb
index 722bf1b4a1..0be782c36a 100644
--- a/backend/app/views/spree/admin/stores/_form.html.erb
+++ b/backend/app/views/spree/admin/stores/_form.html.erb
@@ -117,7 +117,7 @@
<%= f.error_message_on :supported_currencies %>
<% end %>
<%= f.field_container :checkout_zone_id, class: ['form-group'] do %>
- <%= f.label :checkout_zone_id, Spree.t('zone') %>
+ <%= f.label :checkout_zone_id, Spree.t(:zone) %>
<%= f.select :checkout_zone_id, options_from_collection_for_select(@zones, :id, :name, selected_checkout_zone(@store)), {}, { class: 'select2' } %>
<%= f.label :checkout_zone_id, Spree.t('i18n.checkout_zone_warning_html'), class: 'alert alert-warning col-12' %>
<%= f.error_message_on :checkout_zone_id %>
diff --git a/backend/spec/features/admin/configuration/stores_spec.rb b/backend/spec/features/admin/configuration/stores_spec.rb
index f241c87930..a0d58cbb9d 100644
--- a/backend/spec/features/admin/configuration/stores_spec.rb
+++ b/backend/spec/features/admin/configuration/stores_spec.rb
@@ -3,7 +3,9 @@ require 'spec_helper'
describe 'Stores admin', type: :feature, js: true do
stub_authorization!
- let!(:store) { create(:store) }
+ let!(:store) { create(:store, checkout_zone_id: zone.id) }
+ let!(:zone) { create(:zone, name: 'EU_VAT') }
+ let!(:no_limits) { create(:zone, name: 'No Limits') }
describe 'visiting the stores page' do
it 'is on the stores page' do
@@ -19,6 +21,40 @@ describe 'Stores admin', type: :feature, js: true do
end
describe 'creating store' do
+ context 'with checkout_zone set as preference in spree config file' do
+ let!(:zone) { create(:zone, name: 'Asia') }
+
+ before do
+ store.update(checkout_zone_id: nil)
+ Spree::Config[:checkout_zone] = 'Asia'
+ end
+
+ it 'sets default zone' do
+ visit spree.admin_stores_path
+
+ click_link 'New Store'
+
+ expect(page).to have_current_path(spree.new_admin_store_path)
+ expect(page).to have_selector(:id, 's2id_store_checkout_zone_id', text: 'Asia')
+ end
+ end
+
+ context 'without checkout_zone set as preference in spree config file' do
+ before do
+ store.update(checkout_zone_id: nil)
+ Spree::Config.preference_default(:checkout_zone)
+ end
+
+ it 'sets default zone' do
+ visit spree.admin_stores_path
+
+ click_link 'New Store'
+
+ expect(page).to have_current_path(spree.new_admin_store_path)
+ expect(page).to have_selector(:id, 's2id_store_checkout_zone_id', text: 'No Limits')
+ end
+ end
+
it 'sets default currency value' do
visit spree.admin_stores_path
diff --git a/backend/spec/features/admin/store_spec.rb b/backend/spec/features/admin/store_spec.rb
index 1e7e7732a6..ecbf5525bf 100644
--- a/backend/spec/features/admin/store_spec.rb
+++ b/backend/spec/features/admin/store_spec.rb
@@ -5,6 +5,8 @@ describe 'Stores', type: :feature, js: true do
context 'creating new store' do
before do
+ create(:zone, name: 'No Limits')
+
visit spree.admin_path
click_link 'Configurations'
@@ -54,8 +56,11 @@ describe 'Stores', type: :feature, js: true do
end
context 'editing existing store' do
+ let!(:updated_zone) { create(:zone, name: 'EU_VAT') }
+
before do
- create(:store, name: 'Some existing store')
+ @zone = create(:zone, name: 'No Limits')
+ create(:store, name: 'Some existing store', checkout_zone_id: @zone.id)
visit spree.admin_path
@@ -79,4 +84,70 @@ describe 'Stores', type: :feature, js: true do
expect(page).to have_content('successfully updated!')
end
end
+
+ context 'with checkout_zone preference set in spree config file' do
+ let!(:store) { create(:store, name: 'Some existing store') }
+ let!(:zone) { create(:zone, name: 'Asia') }
+
+ before do
+ Spree::Config[:checkout_zone] = 'Asia'
+
+ visit spree.admin_path
+
+ click_link 'Configurations'
+ click_link 'Stores'
+ end
+
+ it 'edits existing store' do
+ within_row(1) { click_icon :edit }
+ fill_in 'Mail from address', with: '[email protected]'
+ click_button 'Update'
+
+ expect(page).to have_content('successfully updated!')
+ end
+ end
+
+ context 'with checkout_zone_id attribute set for store' do
+ let!(:store) { create(:store, name: 'Some existing store', checkout_zone_id: zone.id) }
+ let!(:zone) { create(:zone, name: 'Asia') }
+
+ before do
+ Spree::Config.preference_default(:checkout_zone)
+
+ visit spree.admin_path
+
+ click_link 'Configurations'
+ click_link 'Stores'
+ end
+
+ it 'edits existing store' do
+ within_row(1) { click_icon :edit }
+ fill_in 'Mail from address', with: '[email protected]'
+ click_button 'Update'
+
+ expect(page).to have_content('successfully updated!')
+ end
+ end
+
+ context 'without checkout_zone_id attribute and checkout_zone preference' do
+ let!(:store) { create(:store, name: 'Some existing store', checkout_zone_id: nil) }
+ let!(:zone) { create(:zone, name: 'No Limits') }
+
+ before do
+ Spree::Config.preference_default(:checkout_zone)
+
+ visit spree.admin_path
+
+ click_link 'Configurations'
+ click_link 'Stores'
+ end
+
+ it 'edits existing store' do
+ within_row(1) { click_icon :edit }
+ fill_in 'Mail from address', with: '[email protected]'
+ click_button 'Update'
+
+ expect(page).to have_content('successfully updated!')
+ end
+ end
end