Sha256: cc3e32c0c2ec4914f75f05e53af16c9c384e6f2a46a70532f7bd79832ef5e55a
Contents?: true
Size: 1.38 KB
Versions: 5
Compression:
Stored size: 1.38 KB
Contents
module Spree 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_for_all_stores.each do |currency| price = variant.price_in(currency.iso_code) price.price = (prices[currency.iso_code]['price'].blank? ? nil : prices[currency.iso_code]['price']) price.compare_at_price = (prices[currency.iso_code]['compare_at_price'].blank? ? nil : prices[currency.iso_code]['compare_at_price']) price.save! if price.new_record? && price.price || !price.new_record? && price.changed? end end 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
Version data entries
5 entries across 5 versions & 1 rubygems