diff --git a/backend/app/assets/javascripts/spree/backend/multi_currency.js b/backend/app/assets/javascripts/spree/backend/multi_currency.js index 33b90d0bcfe..7111f1aebc9 100644 --- a/backend/app/assets/javascripts/spree/backend/multi_currency.js +++ b/backend/app/assets/javascripts/spree/backend/multi_currency.js @@ -16,18 +16,8 @@ $(document).ready(function () { .change(function () { var filter = $(this).val() if (filter) { - $(list) - .find('.panel-title:not(:Contains(' + filter + '))') - .parent() - .parent() - .parent() - .hide() - $(list) - .find('.panel-title:Contains(' + filter + ')') - .parent() - .parent() - .parent() - .show() + $(list).find('.panel-title:not(:Contains(' + filter + '))').parent().hide() + $(list).find('.panel-title:Contains(' + filter + ')').parent().show() } else { $(list) .find('.panel') diff --git a/backend/app/controllers/spree/admin/prices_controller.rb b/backend/app/controllers/spree/admin/prices_controller.rb index ca231c093c9..87a64fd2077 100644 --- a/backend/app/controllers/spree/admin/prices_controller.rb +++ b/backend/app/controllers/spree/admin/prices_controller.rb @@ -3,13 +3,17 @@ module Admin class PricesController < ResourceController belongs_to 'spree/product', find_by: :slug + helper_method :supported_currencies_for_all_stores + def create params.require(:vp).permit! params[:vp].each do |variant_id, prices| + next unless variant_id + variant = Spree::Variant.find(variant_id) next unless variant - supported_currencies.each do |currency| + supported_currencies_for_all_stores.each do |currency| price = variant.price_in(currency.iso_code) price.price = (prices[currency.iso_code].blank? ? nil : prices[currency.iso_code]) price.save! if price.new_record? && price.price || !price.new_record? && price.changed? @@ -18,6 +22,17 @@ def create flash[:success] = Spree.t('notice_messages.prices_saved') redirect_to admin_product_path(parent) end + + private + + def supported_currencies_for_all_stores + @supported_currencies_for_all_stores = begin + ( + Spree::Store.pluck(:supported_currencies).map { |c| c.split(',') }.flatten + Spree::Store.pluck(:default_currency) + ). + compact.uniq.map { |code| ::Money::Currency.find(code.strip) } + end + end end end end diff --git a/backend/app/views/spree/admin/prices/_variant_prices.html.erb b/backend/app/views/spree/admin/prices/_variant_prices.html.erb index 8246f346f38..d4c3d9f70a1 100644 --- a/backend/app/views/spree/admin/prices/_variant_prices.html.erb +++ b/backend/app/views/spree/admin/prices/_variant_prices.html.erb @@ -1,28 +1,38 @@ -<% panel_class ||= 'panel-default' %> - -
<%= Spree.t(:options) %> | +<%= Spree.t(:sku) %> | +<%= Spree.t(:currency) %> | +<%= Spree.t(:price) %> | +
---|---|---|---|
+ <%= variant.is_master? ? Spree.t(:master) : variant.options_text.blank? ? Spree.t(:variant) : variant.options_text %> + | +<%= variant.sku %> | +<%= label_tag "vp[#{variant.id}][#{code}]", code %> | ++ <%= text_field_tag "vp[#{variant.id}][#{code}]", (price && price.price ? price.display_amount.money : ''), class: 'form-control' %> + | +