Class: Spree::Admin::PromotionsController

Inherits:
ResourceController
  • Object
show all
Defined in:
lib/controllers/backend/spree/admin/promotions_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/controllers/backend/spree/admin/promotions_controller.rb', line 14

def create
  @promotion = Spree::Promotion.new(permitted_resource_params)
  @promotion.codes.new(value: params[:single_code]) if params[:single_code].present?

  if params[:promotion_code_batch]
    @promotion_code_batch = @promotion.promotion_code_batches.new(promotion_code_batch_params)
  end

  if @promotion.save
    @promotion_code_batch.process if @promotion_code_batch
    flash[:success] = t('spree.promotion_successfully_created')
    redirect_to location_after_save
  else
    flash[:error] = @promotion.errors.full_messages.to_sentence
    render action: 'new'
  end
end

#showObject



10
11
12
# File 'lib/controllers/backend/spree/admin/promotions_controller.rb', line 10

def show
  redirect_to action: :edit
end