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.

[SD-1372] Add the ability to create a new store from store selector drop-down (#11154)

Matthew Kennedy811df489fc27
diff --git a/backend/app/controllers/spree/admin/stores_controller.rb b/backend/app/controllers/spree/admin/stores_controller.rb
index b74d8c7d32..a3ed2b2515 100644
--- a/backend/app/controllers/spree/admin/stores_controller.rb
+++ b/backend/app/controllers/spree/admin/stores_controller.rb
@@ -40,7 +40,7 @@ module Spree
if @store.save
flash[:success] = flash_message_for(@store, :successfully_created)
- redirect_to spree.admin_stores_path
+ redirect_to @store.formatted_url + spree.admin_stores_path
else
flash[:error] = "#{Spree.t('store_errors.unable_to_create')}: #{@store.errors.full_messages.join(', ')}"
render :new
diff --git a/backend/app/views/spree/admin/shared/_store_switcher.html.erb b/backend/app/views/spree/admin/shared/_store_switcher.html.erb
index 170cfe135a..be3336bc87 100644
--- a/backend/app/views/spree/admin/shared/_store_switcher.html.erb
+++ b/backend/app/views/spree/admin/shared/_store_switcher.html.erb
@@ -12,5 +12,12 @@
<% @stores.each do |store| %>
<%= store_switcher_link(store) %>
<% end %>
+
+ <% if can?(:create, Spree::Store) %>
+ <div class="dropdown-divider m-0"></div>
+ <%= link_to spree.new_admin_store_path, class: 'text-dark p-3 dropdown-item', id: 'addNewStoreLink' do %>
+ <%= svg_icon name: "add.svg", width: '18', height: '18' %> <%= Spree.t(:add_new_store) %>
+ <% end %>
+ <% end %>
</div>
<% end %>
diff --git a/backend/spec/controllers/spree/admin/stores_controller_spec.rb b/backend/spec/controllers/spree/admin/stores_controller_spec.rb
index e6c7164673..9d20cc9864 100644
--- a/backend/spec/controllers/spree/admin/stores_controller_spec.rb
+++ b/backend/spec/controllers/spree/admin/stores_controller_spec.rb
@@ -11,13 +11,30 @@ describe Spree::Admin::StoresController do
it 'renders index' do
get :index
- expect(response).to have_http_status(200)
+ expect(response).to have_http_status(:ok)
+ end
+ end
+
+ describe '#create' do
+ it 'redirects to stores index page using the newly created store URL' do
+ post :create, params: {
+ store: { name: 'New Test Store',
+ code: 'NTSS',
+ mail_from_address: '[email protected]',
+ url: 'http://test-new-store.lvh.me',
+ default_locale: 'en',
+ default_currency: 'USD',
+ supported_currencies: ['USD,GBP'],
+ supported_locales: ['en'] }
+ }
+
+ expect(response).to redirect_to('http://test-new-store.lvh.me/admin/stores')
end
end
context 'update' do
it 'can update logo' do
- put :update, params: { id: store.to_param, store: { logo: image_file }}
+ put :update, params: { id: store.to_param, store: { logo: image_file } }
expect(store.reload.logo.blob.filename).to eq(image_file.original_filename)
end
diff --git a/backend/spec/features/admin/configuration/stores_spec.rb b/backend/spec/features/admin/configuration/stores_spec.rb
index d2a581225a..63c49fb53d 100644
--- a/backend/spec/features/admin/configuration/stores_spec.rb
+++ b/backend/spec/features/admin/configuration/stores_spec.rb
@@ -1,6 +1,6 @@
require 'spec_helper'
-describe 'Stores admin', type: :feature, js: true do
+describe 'Stores admin', type: :feature do
stub_authorization!
let(:store) { Spree::Store.default }
@@ -9,7 +9,7 @@ describe 'Stores admin', type: :feature, js: true do
before { store.update!(checkout_zone: zone) }
- describe 'visiting the stores page' do
+ describe 'visiting the stores page', js: true do
before do
I18n.backend.store_translations(:fr,
spree: {
@@ -41,7 +41,7 @@ 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
+ context 'with checkout_zone set as preference in spree config file', js: true do
let!(:zone) { create(:zone, name: 'Asia') }
before do
@@ -59,7 +59,7 @@ describe 'Stores admin', type: :feature, js: true do
end
end
- context 'without checkout_zone set as preference in spree config file' do
+ context 'without checkout_zone set as preference in spree config file', js: true do
before do
store.update(checkout_zone_id: nil)
Spree::Config.preference_default(:checkout_zone)
@@ -75,7 +75,7 @@ describe 'Stores admin', type: :feature, js: true do
end
end
- it 'sets default currency value' do
+ it 'sets default currency value', js: true do
visit spree.admin_stores_path
click_link 'New Store'
@@ -87,26 +87,28 @@ describe 'Stores admin', type: :feature, js: true do
it 'saving store' do
visit spree.admin_stores_path
- click_link 'New Store'
+ within '#contentHeaderRow' do
+ click_link 'New Store'
+ end
page.fill_in 'store_name', with: 'Spree Example Test'
page.fill_in 'store_url', with: 'test.localhost'
page.fill_in 'store_code', with: 'spree'
page.fill_in 'store_mail_from_address', with: '[email protected]'
page.fill_in 'store_customer_support_email', with: '[email protected]'
- select2 'EUR', from: 'Default currency'
- select2_clear from: 'Supported Currencies'
- select2_search 'GBP', from: 'Supported Currencies'
- select2_select 'GBP', from: 'Supported Currencies'
+ select 'EUR', from: 'Default currency'
+ select 'GBP', from: 'Supported Currencies'
+ unselect 'USD', from: 'Supported Currencies'
+ select 'GBP', from: 'Supported Currencies'
- select2 'English (US)', from: 'Default locale'
+ select 'English (US)', from: 'Default locale'
click_button 'Create'
expect(page).to have_current_path spree.admin_stores_path
- expect(page).to have_content('successfully created!')
+ expect(page).to have_content('Spree Example Test (spree)')
row_count = page.all(:css, 'table tr').size
- expect(row_count).to eq 3
+ expect(row_count).to eq 2
expect(Spree::Store.count).to eq 2
store = Spree::Store.last
@@ -117,7 +119,7 @@ describe 'Stores admin', type: :feature, js: true do
end
end
- describe 'updating store' do
+ describe 'updating store', js: true do
let(:updated_name) { 'New Store Name' }
let(:new_currency) { 'EUR' }
@@ -182,7 +184,7 @@ describe 'Stores admin', type: :feature, js: true do
end
end
- describe 'deleting store' do
+ describe 'deleting store', js: true do
let!(:second_store) { create(:store) }
it 'updates store in lifetime stats' do
@@ -197,7 +199,7 @@ describe 'Stores admin', type: :feature, js: true do
end
end
- describe 'setting default store' do
+ describe 'setting default store', js: true do
let!(:store1) { create(:store, default: false) }
it 'sets a store as default' do
diff --git a/backend/spec/features/admin/store_selector_spec.rb b/backend/spec/features/admin/store_selector_spec.rb
index 654a956e3b..8e27bca061 100644
--- a/backend/spec/features/admin/store_selector_spec.rb
+++ b/backend/spec/features/admin/store_selector_spec.rb
@@ -36,4 +36,24 @@ describe 'Admin store switcher', type: :feature, js: true do
expect(page).to have_selector(:css, "a[href*='#{store_three.formatted_url}:#{port}/admin/products']")
end
end
+
+ context 'can add new store using + Add New Store link' do
+ before do
+ visit spree.admin_path
+ end
+
+ it 'displays the link in the store selector dropdown' do
+ find('a#storeSelectorDropdown').click
+ expect(page).to have_selector(:css, "a[href*='#{spree.new_admin_store_path(@user)}']")
+ end
+
+ it 'takes you to the add new store page when clicked' do
+ expect(page).not_to have_text('Stores / New Store')
+
+ find('a#storeSelectorDropdown').click
+ find('a#addNewStoreLink').click
+
+ expect(page).to have_text('Stores / New Store')
+ end
+ end
end
diff --git a/backend/spec/features/admin/store_spec.rb b/backend/spec/features/admin/store_spec.rb
index 359e6bdacd..18a762042f 100644
--- a/backend/spec/features/admin/store_spec.rb
+++ b/backend/spec/features/admin/store_spec.rb
@@ -1,6 +1,6 @@
require 'spec_helper'
-describe 'Stores', type: :feature, js: true do
+describe 'Stores', type: :feature do
stub_authorization!
context 'creating new store' do
@@ -11,9 +11,13 @@ describe 'Stores', type: :feature, js: true do
click_link 'Configurations'
click_link 'Stores'
- click_link 'New Store'
+ within '#contentHeaderRow' do
+ click_link 'New Store'
+ end
end
+ after { Capybara.app_host = nil }
+
it 'has required fields' do
expect(page).to have_field(id: 'store_name')
expect(page).to have_field(id: 'store_code')
@@ -37,18 +41,22 @@ describe 'Stores', type: :feature, js: true do
it 'creates a new store' do
fill_in 'Name', with: 'Store name'
fill_in 'Code', with: 'example_store'
- fill_in 'URL', with: 'store.example.com'
+ fill_in 'URL', with: 'http://another-store.lvh.me'
fill_in 'Mail from address', with: '[email protected]'
click_button 'Create'
- expect(page).to have_content('successfully created!')
+ Capybara.app_host = 'http://another-store.lvh.me'
+
+ expect(page).to have_content('http://another-store.lvh.me')
+ expect(page).to have_content('example_store')
+ expect(page).to have_content('Stores')
end
it 'creates a new store with footer and seo data' do
fill_in 'Name', with: 'Store name'
fill_in 'Code', with: 'example_store'
- fill_in 'URL', with: 'store.example.com'
+ fill_in 'URL', with: 'http://one-another-store.lvh.me'
fill_in 'Mail from address', with: '[email protected]'
fill_in 'Description', with: 'New store description'
fill_in 'Address', with: 'New store address 123, City 123'
@@ -61,11 +69,14 @@ describe 'Stores', type: :feature, js: true do
click_button 'Create'
- expect(page).to have_content('successfully created!')
+ Capybara.app_host = 'http://one-another-store.lvh.me'
+
+ expect(page).to have_content('http://one-another-store.lvh.me')
+ expect(page).to have_content('Stores')
end
end
- context 'editing existing store' do
+ context 'editing existing store', js: true do
let!(:updated_zone) { create(:zone, name: 'EU_VAT') }
before do
@@ -95,7 +106,7 @@ describe 'Stores', type: :feature, js: true do
end
end
- context 'with checkout_zone preference set in spree config file' do
+ context 'with checkout_zone preference set in spree config file', js: true do
let!(:store) { create(:store, name: 'Some existing store') }
let!(:zone) { create(:zone, name: 'Asia') }
@@ -117,7 +128,7 @@ describe 'Stores', type: :feature, js: true do
end
end
- context 'with checkout_zone_id attribute set for store' do
+ context 'with checkout_zone_id attribute set for store', js: true do
let!(:store) { create(:store, name: 'Some existing store', checkout_zone_id: zone.id) }
let!(:zone) { create(:zone, name: 'Asia') }
@@ -139,7 +150,7 @@ describe 'Stores', type: :feature, js: true do
end
end
- context 'without checkout_zone_id attribute and checkout_zone preference' do
+ context 'without checkout_zone_id attribute and checkout_zone preference', js: true do
let!(:store) { create(:store, name: 'Some existing store', checkout_zone_id: nil) }
before do
diff --git a/core/config/locales/en.yml b/core/config/locales/en.yml
index a8e6c9f5d9..f6c6fa1b8c 100644
--- a/core/config/locales/en.yml
+++ b/core/config/locales/en.yml
@@ -646,6 +646,7 @@ en:
you_have_no_menus: You have no Menus, click the Add New Menu button to create your first Menu.
this_link_takes_you_to_your_stores_home_page: This link takes you to your stores home page.
administration: Administration
+ add_new_store: Add New Store
advertise: Advertise
agree_to_privacy_policy: Agree to Privacy Policy
agree_to_terms_of_service: Agree to Terms of Service