Sha256: b0b43ccbab448d1b37363a370f24af3c6bcdb8e385954227c5dd168a564fe58b

Contents?: true

Size: 1.62 KB

Versions: 57

Compression:

Stored size: 1.62 KB

Contents

class Spree::Admin::PromotionActionsController < Spree::Admin::BaseController
  before_filter :load_promotion, :only => [:create, :destroy]
  before_filter :validate_promotion_action_type, :only => :create

  def create
    @calculators = Spree::Promotion::Actions::CreateAdjustment.calculators
    @promotion_action = params[:action_type].constantize.new(params[:promotion_action])
    @promotion_action.promotion = @promotion
    if @promotion_action.save
      flash[:success] = Spree.t(:successfully_created, :resource => Spree.t(:promotion_action))
    end
    respond_to do |format|
      format.html { redirect_to spree.edit_admin_promotion_path(@promotion)}
      format.js   { render :layout => false }
    end
  end

  def destroy
    @promotion_action = @promotion.promotion_actions.find(params[:id])
    if @promotion_action.destroy
      flash[:success] = Spree.t(:successfully_removed, :resource => Spree.t(:promotion_action))
    end
    respond_to do |format|
      format.html { redirect_to spree.edit_admin_promotion_path(@promotion)}
      format.js   { render :layout => false }
    end
  end

  private

  def load_promotion
    @promotion = Spree::Promotion.find(params[:promotion_id])
  end

  def validate_promotion_action_type
    valid_promotion_action_types = Rails.application.config.spree.promotions.actions.map(&:to_s)
    if !valid_promotion_action_types.include?(params[:action_type])
      flash[:error] = Spree.t(:invalid_promotion_action)
      respond_to do |format|
        format.html { redirect_to spree.edit_admin_promotion_path(@promotion)}
        format.js   { render :layout => false }
      end
    end
  end
end

Version data entries

57 entries across 57 versions & 1 rubygems

Version Path
spree_backend-2.3.13 app/controllers/spree/admin/promotion_actions_controller.rb
spree_backend-2.2.14 app/controllers/spree/admin/promotion_actions_controller.rb
spree_backend-2.3.12 app/controllers/spree/admin/promotion_actions_controller.rb
spree_backend-2.2.13 app/controllers/spree/admin/promotion_actions_controller.rb
spree_backend-2.3.11 app/controllers/spree/admin/promotion_actions_controller.rb
spree_backend-2.2.12 app/controllers/spree/admin/promotion_actions_controller.rb
spree_backend-2.3.10 app/controllers/spree/admin/promotion_actions_controller.rb
spree_backend-2.3.9 app/controllers/spree/admin/promotion_actions_controller.rb
spree_backend-2.2.11 app/controllers/spree/admin/promotion_actions_controller.rb
spree_backend-2.2.10 app/controllers/spree/admin/promotion_actions_controller.rb
spree_backend-2.3.8 app/controllers/spree/admin/promotion_actions_controller.rb
spree_backend-2.3.7 app/controllers/spree/admin/promotion_actions_controller.rb
spree_backend-2.2.9 app/controllers/spree/admin/promotion_actions_controller.rb
spree_backend-2.1.12 app/controllers/spree/admin/promotion_actions_controller.rb
spree_backend-2.3.6 app/controllers/spree/admin/promotion_actions_controller.rb
spree_backend-2.2.8 app/controllers/spree/admin/promotion_actions_controller.rb
spree_backend-2.1.11 app/controllers/spree/admin/promotion_actions_controller.rb
spree_backend-2.3.5 app/controllers/spree/admin/promotion_actions_controller.rb
spree_backend-2.2.7 app/controllers/spree/admin/promotion_actions_controller.rb
spree_backend-2.1.10 app/controllers/spree/admin/promotion_actions_controller.rb