Class: Spree::Admin::PricesController
- Inherits:
-
ResourceController
- Object
- ApplicationController
- BaseController
- ResourceController
- Spree::Admin::PricesController
- Defined in:
- app/controllers/spree/admin/prices_controller.rb
Instance Method Summary collapse
Methods inherited from ResourceController
belongs_to, #destroy, #edit, #new, #update, #update_positions
Instance Method Details
#create ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'app/controllers/spree/admin/prices_controller.rb', line 6 def create params.require(:vp).permit! params[:vp].each do |variant_id, prices| next unless variant_id variant = parent.variants_including_master.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 spree.admin_product_path(parent) end |