Sha256: 778bb8c651bb6b290cdd7383b79bc4ae04d4fb01c74e011b397aadaea2edefa9

Contents?: true

Size: 1.77 KB

Versions: 77

Compression:

Stored size: 1.77 KB

Contents

class Spree::Admin::PromotionRulesController < Spree::Admin::BaseController
  helper 'spree/promotion_rules'

  before_action :load_promotion, only: [:create, :destroy]
  before_action :validate_promotion_rule_type, only: :create

  def create
    # Remove type key from this hash so that we don't attempt
    # to set it when creating a new record, as this is raises
    # an error in ActiveRecord 3.2.
    promotion_rule_type = params[:promotion_rule].delete(:type)
    @promotion_rule = promotion_rule_type.constantize.new(params[:promotion_rule])
    @promotion_rule.promotion = @promotion
    if @promotion_rule.save
      flash[:success] = Spree.t(:successfully_created, :resource => Spree.t(:promotion_rule))
    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_rule = @promotion.promotion_rules.find(params[:id])
    if @promotion_rule.destroy
      flash[:success] = Spree.t(:successfully_removed, :resource => Spree.t(:promotion_rule))
    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_rule_type
    valid_promotion_rule_types = Rails.application.config.spree.promotions.rules.map(&:to_s)
    if !valid_promotion_rule_types.include?(params[:promotion_rule][:type])
      flash[:error] = Spree.t(:invalid_promotion_rule)
      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

77 entries across 77 versions & 3 rubygems

Version Path
goca-spree-backend-3.1.14.rails.5.0 app/controllers/spree/admin/promotion_rules_controller.rb
spree_backend-3.1.14 app/controllers/spree/admin/promotion_rules_controller.rb
spree_backend-3.1.13 app/controllers/spree/admin/promotion_rules_controller.rb
spree_backend-3.1.12 app/controllers/spree/admin/promotion_rules_controller.rb
solidus_backend-1.2.3 app/controllers/spree/admin/promotion_rules_controller.rb
solidus_backend-1.1.4 app/controllers/spree/admin/promotion_rules_controller.rb
solidus_backend-1.0.7 app/controllers/spree/admin/promotion_rules_controller.rb
spree_backend-3.1.11 app/controllers/spree/admin/promotion_rules_controller.rb
spree_backend-3.1.10 app/controllers/spree/admin/promotion_rules_controller.rb
spree_backend-3.1.9 app/controllers/spree/admin/promotion_rules_controller.rb
spree_backend-3.1.8 app/controllers/spree/admin/promotion_rules_controller.rb
spree_backend-3.1.7 app/controllers/spree/admin/promotion_rules_controller.rb
spree_backend-3.1.6 app/controllers/spree/admin/promotion_rules_controller.rb
spree_backend-3.1.5 app/controllers/spree/admin/promotion_rules_controller.rb
spree_backend-3.1.4 app/controllers/spree/admin/promotion_rules_controller.rb
spree_backend-3.1.3 app/controllers/spree/admin/promotion_rules_controller.rb
spree_backend-3.1.2 app/controllers/spree/admin/promotion_rules_controller.rb
spree_backend-3.0.10 app/controllers/spree/admin/promotion_rules_controller.rb
spree_backend-3.1.1 app/controllers/spree/admin/promotion_rules_controller.rb
spree_backend-3.1.0 app/controllers/spree/admin/promotion_rules_controller.rb