Sha256: cd60f87fb8fa204820cd4edc7ef81469a83deaa4e093f2ed35ec86b3eb1e887e

Contents?: true

Size: 1.69 KB

Versions: 32

Compression:

Stored size: 1.69 KB

Contents

class Spree::Admin::PromotionActionsController < Spree::Admin::BaseController
  before_action :load_promotion, only: [:create, :destroy]
  before_action :validate_promotion_action_type, only: :create

  def create
    @calculators = Spree::Promotion::Actions::CreateAdjustment.calculators
    @promotion_action = @promotion_action_type.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
    requested_type = params[:action_type]
    promotion_action_types = Rails.application.config.spree.promotions.actions
    @promotion_action_type = promotion_action_types.detect do |klass|
      klass.name == requested_type
    end
    if !@promotion_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

32 entries across 32 versions & 1 rubygems

Version Path
solidus_backend-2.3.1 app/controllers/spree/admin/promotion_actions_controller.rb
solidus_backend-2.2.2 app/controllers/spree/admin/promotion_actions_controller.rb
solidus_backend-2.1.1 app/controllers/spree/admin/promotion_actions_controller.rb
solidus_backend-2.0.3 app/controllers/spree/admin/promotion_actions_controller.rb
solidus_backend-1.4.2 app/controllers/spree/admin/promotion_actions_controller.rb
solidus_backend-1.3.2 app/controllers/spree/admin/promotion_actions_controller.rb
solidus_backend-2.3.0 app/controllers/spree/admin/promotion_actions_controller.rb
solidus_backend-2.3.0.rc3 app/controllers/spree/admin/promotion_actions_controller.rb
solidus_backend-2.3.0.rc2 app/controllers/spree/admin/promotion_actions_controller.rb
solidus_backend-2.3.0.rc1 app/controllers/spree/admin/promotion_actions_controller.rb
solidus_backend-2.3.0.beta1 app/controllers/spree/admin/promotion_actions_controller.rb
solidus_backend-2.0.2 app/controllers/spree/admin/promotion_actions_controller.rb
solidus_backend-1.4.1 app/controllers/spree/admin/promotion_actions_controller.rb
solidus_backend-2.2.1 app/controllers/spree/admin/promotion_actions_controller.rb
solidus_backend-2.2.0 app/controllers/spree/admin/promotion_actions_controller.rb
solidus_backend-2.2.0.rc1 app/controllers/spree/admin/promotion_actions_controller.rb
solidus_backend-2.2.0.beta1 app/controllers/spree/admin/promotion_actions_controller.rb
solidus_backend-2.1.0 app/controllers/spree/admin/promotion_actions_controller.rb
solidus_backend-2.1.0.rc1 app/controllers/spree/admin/promotion_actions_controller.rb
solidus_backend-2.0.1 app/controllers/spree/admin/promotion_actions_controller.rb