Sha256: 0266c9d14dee217152719e9f763d52034d6f8a7ca239c0e48b411f0f92fed298

Contents?: true

Size: 1.75 KB

Versions: 129

Compression:

Stored size: 1.75 KB

Contents

# frozen_string_literal: true

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 = Rails.application.config.spree.calculators.promotion_actions_create_adjustments
    @promotion_action = @promotion_action_type.new(params[:promotion_action])
    @promotion_action.promotion = @promotion
    if @promotion_action.save
      flash[:success] = t('spree.successfully_created', resource: t('spree.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.discard
      flash[:success] = t('spree.successfully_removed', resource: t('spree.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] = t('spree.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

129 entries across 129 versions & 2 rubygems

Version Path
solidus_backend-2.11.12 app/controllers/spree/admin/promotion_actions_controller.rb
solidus_backend-3.0.3 app/controllers/spree/admin/promotion_actions_controller.rb
solidus_backend-3.1.3 app/controllers/spree/admin/promotion_actions_controller.rb
solidus_backend-3.1.2 app/controllers/spree/admin/promotion_actions_controller.rb
solidus_backend-3.1.1 app/controllers/spree/admin/promotion_actions_controller.rb
solidus_backend-3.1.0 app/controllers/spree/admin/promotion_actions_controller.rb
solidus_backend-2.11.11 app/controllers/spree/admin/promotion_actions_controller.rb
solidus_backend-3.0.2 app/controllers/spree/admin/promotion_actions_controller.rb
solidus_backend-2.10.5 app/controllers/spree/admin/promotion_actions_controller.rb
solidus_backend-2.11.10 app/controllers/spree/admin/promotion_actions_controller.rb
solidus_backend-3.0.1 app/controllers/spree/admin/promotion_actions_controller.rb
solidus_backend-3.0.0 app/controllers/spree/admin/promotion_actions_controller.rb
solidus_backend-2.11.9 app/controllers/spree/admin/promotion_actions_controller.rb
solidus_backend-2.11.8 app/controllers/spree/admin/promotion_actions_controller.rb
solidus_backend-2.11.7 app/controllers/spree/admin/promotion_actions_controller.rb
solidus_backend-2.11.6 app/controllers/spree/admin/promotion_actions_controller.rb
solidus_backend-3.0.0.rc2 app/controllers/spree/admin/promotion_actions_controller.rb
solidus_backend-2.11.5 app/controllers/spree/admin/promotion_actions_controller.rb
solidus_backend-2.11.4 app/controllers/spree/admin/promotion_actions_controller.rb
solidus_backend-2.11.3 app/controllers/spree/admin/promotion_actions_controller.rb