Skip to content
Open
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
29 changes: 29 additions & 0 deletions backend/app/controllers/spree/admin/price_list_items_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# frozen_string_literal: true

module Spree
module Admin
class PriceListItemsController < ResourceController
belongs_to 'spree/price_list', find_by: :id
before_action :set_price_list

def new
@price_list_item = @price_list.price_list_items.build
@price_list_item.build_price
end

private

def set_price_list
@price_list = Spree::PriceList.find(params[:price_list_id])
end

def location_after_save
edit_admin_price_list_path(@price_list)
end

def price_list_item_params
params.require(:price_list_item).permit(:price_list_id, price_attributes: [:amount, :currency, :variant_id])
end
end
end
end
13 changes: 13 additions & 0 deletions backend/app/controllers/spree/admin/price_lists_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# frozen_string_literal: true

module Spree
module Admin
class PriceListsController < ResourceController
private

def location_after_save
edit_admin_price_list_path(@price_list)
end
end
end
end
7 changes: 7 additions & 0 deletions backend/app/controllers/spree/admin/user_groups_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@
module Spree
module Admin
class UserGroupsController < ResourceController
before_action :load_data, except: :index

private

def load_data
@price_list = Spree::PriceList.order(:name)
end
end
end
end
33 changes: 33 additions & 0 deletions backend/app/views/spree/admin/price_list_items/_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<div data-hook="admin_price_list_item_price_fields">
<div data-hook="admin_price_list_item_price_form">
<div data-hook="admin_price_list_item_price_form_variant" class="col-12">
<%= f.label :variant %>
<%= f.collection_select :variant_id, Spree::Variant.all, :id, :descriptive_name,
{ include_blank: true },
{ class: "select2 fullwidth", disabled: !f.object.new_record? } %>
</div>
<div data-hook="admin_price_list_item_price_form_country" class="col-12">
<%= f.label :country %>
<%= f.field_hint :country %>
<%= f.collection_select :country_iso, available_countries(restrict_to_zone: nil), :iso, :name,
{ include_blank: t(:any_country, scope: [:spree, :admin, :prices]), selected: @price_list.try(:country).try(:iso) || nil },
{ class: 'custom-select fullwidth', disabled: true } %>
<%= f.hidden_field :country_iso, value: @price_list.try(:country).try(:iso) || nil %>
</div>
<div data-hook="admin_price_list_item_price_form_amount" class="col-4">
<%= f.label :price %>
<%= render "spree/admin/shared/number_with_currency", f: f, amount_attr: :price, currency_attr: :currency, currency: @price_list.currency %>
<%= f.hidden_field :currency, value: @price_list.currency %>
</div>
<div data-hook="admin_price_list_item_price_form_contain_taxes" class="col-5">
<%= field_container :contain_taxes, class: %w(checkbox) do %>
<label>
<%= f.check_box(:contain_taxes) %>
<%= t('spree.contain_taxes') %>
</label>
<%= error_message_on :price_list, :contain_taxes %>
<% end %>
</div>
</div>
</div>
<div class="clear"></div>
22 changes: 22 additions & 0 deletions backend/app/views/spree/admin/price_list_items/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<% admin_breadcrumb(link_to plural_resource_name(Spree::Product), spree.admin_products_path) %>
<% admin_breadcrumb(link_to(plural_resource_name(Spree::PriceList), spree.admin_price_lists_path)) %>
<% admin_breadcrumb(link_to(@price_list.name, edit_admin_price_list_path(@price_list))) %>

<% admin_breadcrumb(link_to (plural_resource_name(Spree::Price)), edit_admin_price_list_path(@price_list)) %>
<% admin_breadcrumb(t('spree.actions.edit')) %>


<%= form_for [:admin, @price_list, @price_list_item] do |f| %>
<fieldset data-hook="admin_price_list_price_edit_form">
<legend> <%= t('.edit_price') %> </legend>

<%= f.fields_for :price do |price_form| %>
<%= render 'form', f: price_form %>
<% end %>
<div class="form-buttons filter-actions actions" data-hook="buttons">
<%= submit_tag t('spree.actions.update'), class: 'btn btn-primary' %>
<%= link_to t('spree.actions.cancel'), edit_admin_price_list_path(@price_list), class: 'button' %>
</div>

</fieldset>
<% end %>
21 changes: 21 additions & 0 deletions backend/app/views/spree/admin/price_list_items/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<% admin_breadcrumb(link_to plural_resource_name(Spree::Product), spree.admin_products_path) %>
<% admin_breadcrumb(link_to(plural_resource_name(Spree::PriceList), spree.admin_price_lists_path)) %>
<% admin_breadcrumb(link_to(@price_list.name, edit_admin_price_list_path(@price_list))) %>

<% admin_breadcrumb(link_to (plural_resource_name(Spree::Price)), edit_admin_price_list_path(@price_list)) %>
<% admin_breadcrumb(t('spree.actions.new')) %>

<%= form_for [:admin, @price_list, @price_list_item] do |f| %>
<fieldset data-hook="admin_price_list_price_new_form">
<legend><%= t('.new_price') %></legend>

<%= f.fields_for :price do |price_form| %>
<%= render 'form', f: price_form %>
<% end %>
<div class="form-buttons filter-actions actions" data-hook="buttons">
<%= submit_tag t('spree.actions.create'), class: 'btn btn-primary' %>
<%= link_to t('spree.actions.cancel'), edit_admin_price_list_path(@price_list), class: 'button' %>
</div>

</fieldset>
<% end %>
43 changes: 43 additions & 0 deletions backend/app/views/spree/admin/price_lists/_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<div data-hook="admin_price_list_form_fields" class="row">
<div data-hook="admin_price_list_form_name_field" class="col-5">
<%= f.field_container :name do %>
<%= f.label :name, class: 'required' %>
<%= f.text_field :name, class: 'fullwidth' %>
<%= error_message_on :price_list, :name %>
<% end %>
</div>

<div data-hook="admin_price_list_form_country" class="col-5">
<%= f.field_container :country do %>
<%= f.label :country %>
<%= f.field_hint :country %>
<%= f.collection_select :country_iso, available_countries(restrict_to_zone: nil), :iso, :name,
{
include_blank: t(:any_country, scope: [:spree, :admin, :prices])
},
{ class: 'custom-select fullwidth', disabled: !f.object.new_record? } %>
<% end %>
</div>

<div data-hook="admin_price_list_form_currency" class="col-5">
<%= f.field_container :currency do %>
<%= f.label :currency %>
<%= f.field_hint :currency %>
<%= f.select :currency,
Spree::Config.available_currencies.map(&:iso_code),
{ include_blank: true },
{ class: 'custom-select fullwidth' } %>
<%= error_message_on :price_list, :currency %>
<% end %>
</div>

<div data-hook="admin_price_list_form_contain_taxes" class="col-5">
<%= f.field_container :contain_taxes, class: %w(checkbox) do %>
<label>
<%= f.check_box(:contain_taxes) %>
<%= t('spree.contain_taxes') %>
</label>
<%= error_message_on :price_list, :contain_taxes %>
<% end %>
</div>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<% if price_list.prices.any? %>
<fieldset class="no-border-bottom" data-hook="variant_prices_table">
<legend align="center"><%= t(".price_details") %></legend>
<table class="index prices">
<thead data-hook="prices_header">
<tr>
<th><%= Spree::Variant.model_name.human %> </th>
<th><%= Spree::Price.human_attribute_name(:country) %></th>
<th><%= Spree::Price.human_attribute_name(:currency) %></th>
<th><%= Spree::Price.human_attribute_name(:amount) %></th>
<th class="actions"></th>
</tr>
</thead>
<tbody>
<% price_list.price_list_items.each do |price_item| %>
<tr id="<%= spree_dom_id price_item %>" data-hook="prices_row" class="<%= "deleted" if price_item.price.discarded? %>">
<td><%= price_item.price.variant.descriptive_name %></td>
<td><%= price_item.price.display_country %></td>
<td><%= price_item.price.currency %></td>
<td><%= price_item.price.money.to_html %></td>
<td class="actions">
<% if can?(:edit, price_item) %>
<%= link_to_edit_url(edit_admin_price_list_price_list_item_path(price_list, price_item), no_text: true) unless price_item.price.discarded? %>
<% end %>
<% if can?(:destroy, price_item) %>
&nbsp;
<%= link_to_delete(price_item, url: admin_price_list_price_list_item_path(price_list, price_item), no_text: true) unless price_item.price.discarded? %>
<% end %>
</td>
</tr>
<% end %>
</tbody>
</table>
</fieldset>
<% end %>
29 changes: 29 additions & 0 deletions backend/app/views/spree/admin/price_lists/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<% admin_breadcrumb(link_to plural_resource_name(Spree::Product), spree.admin_products_path) %>
<% admin_breadcrumb(link_to plural_resource_name(Spree::PriceList), spree.admin_price_lists_path) %>
<% admin_breadcrumb(@price_list.name) %>

<% content_for :page_actions do %>
<li id="new_price_link">
<%= link_to t(".new_price"), new_admin_price_list_price_list_item_path(price_list_id: @price_list.id), class: 'btn btn-primary' %>
</li>
<% end if can?(:create, Spree::PriceList) %>

<div data-hook="admin_price_list_edit_form_header">
<%= render partial: 'spree/shared/error_messages', locals: { target: @price_list } %>
</div>

<div data-hook="admin_price_list_edit_form">
<%= form_for [:admin, @price_list] do |f| %>
<fieldset class="no-border-top">
<%= render partial: 'form', locals: { f: f } %>

<div class="clear"></div>

<%= render partial: 'price_list_info', locals: { price_list: @price_list } %>

<div data-hook="admin_price_list_edit_form_buttons">
<%= render partial: 'spree/admin/shared/edit_resource_links' %>
</div>
</fieldset>
<% end %>
</div>
54 changes: 54 additions & 0 deletions backend/app/views/spree/admin/price_lists/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<% admin_breadcrumb(link_to plural_resource_name(Spree::Product), spree.admin_products_path) %>
<% admin_breadcrumb(plural_resource_name(Spree::PriceList)) %>

<% content_for :page_actions do %>
<% if can?(:create, Spree::PriceList) %>
<li>
<%= link_to t('spree.new_price_list'), new_object_url, id: 'admin_new_price_list_link', class: 'btn btn-primary' %>
</li>
<% end %>
<% end %>

<% if @price_lists.any? %>
<table class="index" id='listing_price_lists'>
<colgroup>
<col style="width: 40%">
<col style="width: 40%">
<col style="width: 20%">
</colgroup>
<thead>
<tr data-hook="admin_price_lists_index_headers">
<th><%= Spree::PriceList.human_attribute_name(:name) %></th>
<th><%= Spree::UserGroup.model_name.human.pluralize %></th>
<th data-hook="admin_price_lists_index_header_actions" class="actions"></th>
</tr>
</thead>
<tbody>
<% @price_lists.each do |price_list| %>
<tr id="<%= spree_dom_id price_list %>" data-hook="admin_price_lists_index_rows">
<td><%= link_to price_list.try(:name), edit_admin_price_list_path(price_list) %></td>
<td>
<span title="<%= price_list.user_groups.map(&:group_name).join(', ') %>">
<%= price_list.user_groups.count %> <%= Spree::UserGroup.model_name.human.pluralize %>
</span>
</td>
<td data-hook="admin_price_lists_index_row_actions" class="actions">
<% if can?(:update, price_list) %>
<%= link_to_edit price_list, no_text: true %>
<% end %>

<% if can?(:destroy, price_list) %>
<%= link_to_delete price_list, no_text: true %>
<% end %>
</td>
</tr>
<% end %>
</tbody>
</table>
<% else %>
<div class="no-objects-found">
<%= render 'spree/admin/shared/no_objects_found',
resource: Spree::PriceList,
new_resource_url: new_object_url %>
</div>
<% end %>
24 changes: 24 additions & 0 deletions backend/app/views/spree/admin/price_lists/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<% admin_breadcrumb(link_to plural_resource_name(Spree::Product), spree.admin_products_path) %>
<% admin_breadcrumb(link_to plural_resource_name(Spree::PriceList), spree.admin_price_lists_path) %>
<% admin_breadcrumb(t('spree.new_price_list')) %>

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

<div data-hook="admin_price_list_new_form_header">
<%= render partial: 'spree/shared/error_messages', locals: { target: @price_list } %>
</div>

<div data-hook="admin_price_list_new_form">
<%= form_for [:admin, @price_list] do |f| %>
<fieldset class="no-border-top">
<%= render partial: 'form', locals: { f: f } %>

<div class="clear"></div>

<div data-hook="admin_price_list_new_form_buttons">
<%= render partial: 'spree/admin/shared/new_resource_links' %>
</div>
</fieldset>
<% end %>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
<% if can? :admin, Spree::Product %>
<%= tab label: :products, match_path: '/products' %>
<% end %>
<% if can? :admin, Spree::PriceList %>
<%= tab label: :price_lists, match_path: '/price_lists' %>
<% end %>
<% if can? :admin, Spree::OptionType %>
<%= tab label: :option_types, match_path: '/option_types' %>
<% end %>
Expand Down
8 changes: 8 additions & 0 deletions backend/app/views/spree/admin/user_groups/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,12 @@
<%= error_message_on :user_group, :group_name %>
<% end %>
</div>

<div data-hook="admin_user_group_form_price_list_field" class="col-5">
<%= f.field_container :price_list_id do %>
<%= f.label :price_list_id %><br>
<%= f.collection_select :price_list_id, @price_list, :id, :name, { include_blank: true }, { class: "custom-select" } %>
<%= error_message_on :user_group, :price_list_id %>
<% end %>
</div>
</div>
3 changes: 3 additions & 0 deletions backend/app/views/spree/admin/user_groups/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,22 @@
<% if @user_groups.any? %>
<table class="index" id='listing_user_groups'>
<colgroup>
<col style="width: 40%">
<col style="width: 40%">
<col style="width: 20%">
</colgroup>
<thead>
<tr data-hook="admin_user_groups_index_headers">
<th><%= Spree::UserGroup.human_attribute_name(:group_name) %></th>
<th><%= Spree::PriceList.model_name.human %></th>
<th data-hook="admin_user_groups_index_header_actions" class="actions"></th>
</tr>
</thead>
<tbody>
<% @user_groups.each do |user_group| %>
<tr id="<%= spree_dom_id user_group %>" data-hook="admin_user_groups_index_rows">
<td><%= link_to user_group.try(:group_name), edit_admin_user_group_path(user_group) %></td>
<td><%= user_group.price_list.try(:name) %></td>
<td data-hook="admin_user_groups_index_row_actions" class="actions">
<% if can?(:update, user_group) %>
<%= link_to_edit user_group, no_text: true %>
Expand Down
4 changes: 4 additions & 0 deletions backend/config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@

resources :zones

resources :price_lists do
resources :price_list_items, only: [:destroy, :edit, :update, :new, :create]
end

resources :user_groups
resources :tax_categories

Expand Down
7 changes: 7 additions & 0 deletions backend/lib/spree/backend_configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,13 @@ def menu_items
condition: -> { can? :admin, Spree::Product },
match_path: '/products',
),
MenuItem.new(
label: :price_lists,
condition: -> {
can?(:admin, Spree::PriceList)
},
match_path: '/price_lists'
),
MenuItem.new(
label: :option_types,
condition: -> { can? :admin, Spree::OptionType },
Expand Down
Loading