Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow editing multiple Stores #1282

Merged
merged 3 commits into from
Jan 31, 2017
Merged
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
comparisons. A comparison will fail if the two objects do not use the same
currency. [#1682](https://github.com/solidusio/solidus/pull/1682)

* The "Stores" section of Settings in the admin now supports creating and
editing multiple stores.

* Deprecations

* `cache_key_for_taxons` helper has been deprecated in favour of `cache [I18n.locale, @taxons]`
Expand Down
Original file line number Diff line number Diff line change
@@ -1,34 +1,8 @@
module Spree
module Admin
class GeneralSettingsController < Spree::Admin::BaseController
include Spree::Backend::Callbacks

before_action :set_store

def edit
end

def update
if @store.update_attributes(store_params)
flash[:success] = Spree.t(:successfully_updated, resource: Spree.t(:general_settings))
redirect_to edit_admin_general_settings_path
else
render :edit
end
end

private

def store_params
params.require(:store).permit(permitted_params)
end

def permitted_params
Spree::PermittedAttributes.store_attributes
end

def set_store
@store = current_store
redirect_to admin_stores_path
end
end
end
Expand Down
23 changes: 23 additions & 0 deletions backend/app/controllers/spree/admin/stores_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
module Spree
module Admin
class StoresController < Spree::Admin::ResourceController
def index
if Spree::Store.count == 1
redirect_to edit_admin_store_path(Spree::Store.first)
else
@stores = Spree::Store.all
end
end

private

def store_params
params.require(:store).permit(permitted_params)
end

def permitted_params
Spree::PermittedAttributes.store_attributes
end
end
end
end
6 changes: 3 additions & 3 deletions backend/app/models/spree/backend_configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class BackendConfiguration < Preferences::Configuration
:variants, :product_properties, :taxonomies,
:taxons]
REPORT_TABS ||= [:reports]
CONFIGURATION_TABS ||= [:configurations, :general_settings, :tax_categories,
CONFIGURATION_TABS ||= [:stores, :tax_categories,
:tax_rates, :zones, :countries, :states,
:payment_methods, :shipping_methods,
:shipping_categories, :stock_locations,
Expand Down Expand Up @@ -90,10 +90,10 @@ def menu_items
MenuItem.new(
CONFIGURATION_TABS,
'wrench',
condition: -> { can?(:admin, :general_settings) },
condition: -> { can?(:admin, Spree::Store) },
label: :settings,
partial: 'spree/admin/shared/settings_sub_menu',
url: :edit_admin_general_settings_path
url: :admin_stores_path
),
MenuItem.new(
PROMOTION_TABS,
Expand Down
80 changes: 0 additions & 80 deletions backend/app/views/spree/admin/general_settings/edit.html.erb

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
<% content_for :tabs do %>
<nav>
<ul class="tabs" data-hook="admin_configurations_sidebar_menu">
<% if can?(:edit, :general_settings) %>
<%= settings_tab_item Spree.t(:settings), edit_admin_general_settings_path %>
<% if can?(:edit, Spree::Store) %>
<%= settings_tab_item plural_resource_name(Spree::Store), admin_stores_path %>
<% end %>
</ul>
</nav>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<ul class="admin-subnav" data-hook="admin_settings_sub_tabs">
<% if can?(:edit, :general_settings) %>
<%= tab :general_settings, label: :general, url: spree.edit_admin_general_settings_path, match_path: /\/general_settings/ %>
<% if can?(:admin, Spree::Store) %>
<%= tab :stores, label: :stores, url: spree.admin_stores_path %>
<% end %>

<% if can?(:display, Spree::PaymentMethod) %>
Expand Down
52 changes: 52 additions & 0 deletions backend/app/views/spree/admin/stores/_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<%= f.field_container :name do %>
<%= f.label :name, class: 'required' %>
<%= f.text_field :name, required: true, class: 'fullwidth' %>
<%= f.error_message_on :name %>
<% end %>

<%= f.field_container :code do %>
<%= f.label :code, class: 'required' %>
<%= f.text_field :code, required: true, class: 'fullwidth' %>
<%= f.error_message_on :code %>
<% end %>

<%= f.field_container :seo_title do %>
<%= f.label :seo_title %>
<%= f.field_hint :seo_title %>
<%= f.text_field :seo_title, class: 'fullwidth' %>
<%= f.error_message_on :seo_title %>
<% end %>

<%= f.field_container :meta_keywords do %>
<%= f.label :meta_keywords %>
<%= f.text_field :meta_keywords, class: 'fullwidth' %>
<%= f.error_message_on :meta_keywords %>
<% end %>

<%= f.field_container :meta_description do %>
<%= f.label :meta_description %>
<%= f.text_field :meta_description, class: 'fullwidth' %>
<%= f.error_message_on :meta_description %>
<% end %>

<%= f.field_container :url do %>
<%= f.label :url, class: 'required' %>
<%= f.text_field :url, required: true, class: 'fullwidth' %>
<%= f.error_message_on :url %>
<% end %>

<%= f.field_container :mail_from_address do %>
<%= f.label :mail_from_address, class: 'required' %>
<%= f.text_field :mail_from_address, required: true, class: 'fullwidth' %>
<%= f.error_message_on :mail_from_address %>
<% end %>

<%= f.field_container :cart_tax_country_iso do %>
<%= f.label :cart_tax_country_iso %>
<%= f.field_hint :cart_tax_country_iso %>
<%= f.select :cart_tax_country_iso,
Spree::Country.all.map { |c| [c.name, c.iso] },
{ include_blank: t(".no_cart_tax_country") },
{ class: "select2 fullwidth" } %>
<%= f.error_message_on :cart_tax_country_iso %>
<% end %>
19 changes: 19 additions & 0 deletions backend/app/views/spree/admin/stores/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<%= render 'spree/admin/shared/general_tabs' %>

<% admin_breadcrumb(link_to(plural_resource_name(Spree::Store), admin_stores_path)) %>
<% admin_breadcrumb(@store.name) %>

<% content_for :page_actions do %>
<li>
<%= button_link_to Spree.t(:new_store), new_admin_store_url %>
</li>
<% end %>

<%= form_for [:admin, @store] do |f| %>
<fieldset class="no-border-top">
<%= render 'form', f: f %>
<% if can? :update, @store %>
<%= render 'spree/admin/shared/edit_resource_links' %>
<% end %>
</fieldset>
<% end %>
41 changes: 41 additions & 0 deletions backend/app/views/spree/admin/stores/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<%= render 'spree/admin/shared/general_tabs' %>

<% content_for :page_title do %>
<%= plural_resource_name(Spree::Store) %>
<% end %>

<% content_for :page_actions do %>
<% if can?(:create, Spree::Store) %>
<li>
<%= link_to Spree.t(:new_store), new_admin_store_url, class: 'button' %>
</li>
<% end %>
<% end %>

<table class="index">
<thead>
<tr>
<th>Name</th>
<th>Url</th>
<th class="actions"></th>
</tr>
</thead>
<tbody>
<% @stores.each do |store| %>
<tr>
<td>
<%= store.name %>
<% if store.default? %>
<span class="label label-default">default</span>
<% end %>
</td>
<td><%= store.url %></td>
<td class="actions">
<% if can?(:edit, store) %>
<%= link_to_edit store, :no_text => true %>
<% end %>
</td>
</tr>
<% end %>
</tbody>
</table>
15 changes: 15 additions & 0 deletions backend/app/views/spree/admin/stores/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<%= render 'spree/admin/shared/general_tabs' %>

<% admin_breadcrumb(link_to(plural_resource_name(Spree::Store), admin_stores_path)) %>
<% admin_breadcrumb(Spree.t(:new_store)) %>

<% content_for :page_actions do %>
<% end %>

<%= form_for [:admin, @store] do |f| %>
<%= render 'form', f: f %>

<% if can? :create, @store %>
<%= render 'spree/admin/shared/new_resource_links' %>
<% end %>
<% end %>
3 changes: 2 additions & 1 deletion backend/config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@
end
end

resource :general_settings, only: [:edit, :update]
resource :general_settings, only: :edit
resources :stores, only: [:index, :new, :create, :edit, :update]

resources :return_items, only: [:update]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

context "visiting general store settings" do
it "should have the right content" do
expect(page).to have_content("SettingsStore")
expect(page).to have_field("store_name", with: "Test Store")
expect(page).to have_field("store_url", with: "test.example.org")
expect(page).to have_field("store_mail_from_address", with: "test@example.org")
Expand All @@ -33,7 +32,7 @@
fill_in "store_mail_from_address", with: "spree@example.org"
click_button "Update"

assert_successful_update_message(:general_settings)
expect(page).to have_content "successfully updated"
expect(page).to have_field("store_name", with: "Spree Demo Site99")
expect(page).to have_field("store_mail_from_address", with: "spree@example.org")
end
Expand All @@ -44,18 +43,18 @@
select "Germany", from: "Tax Country for Empty Carts"
click_button "Update"

assert_successful_update_message(:general_settings)
expect(page).to have_content("has been successfully updated")
expect(page).to have_select("Tax Country for Empty Carts", selected: "Germany")
end
end

context "update fails" do
it "should display the error" do
fill_in "Site Name", with: ""
fill_in "Site Name", with: " "
click_button "Update"

expect(page).to have_content("can't be blank")
expect(page).to have_field("Site Name", with: "")
expect(page).to have_field("Site Name", with: " ")
end
end
end
Loading