Class: Spree::Admin::Orders::OrderPromotionsController

Inherits:
BaseController
  • Object
show all
Includes:
Spree::Admin::OrderConcern
Defined in:
app/controllers/spree/admin/orders/order_promotions_controller.rb

Instance Method Summary collapse

Methods included from BreadcrumbConcern

#add_breadcrumb_icon_instance_var

Instance Method Details

#createObject

POST /admin/orders/:order_id/order_promotions



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'app/controllers/spree/admin/orders/order_promotions_controller.rb', line 16

def create
  authorize! :update, @order

  @order.coupon_code = params[:coupon_code]

  @handler = Spree::PromotionHandler::Coupon.new(@order)
  @handler.apply

  if @handler.successful?
    flash.now[:success] = @handler.success
    @order.reload
    load_order_items
  else
    flash.now[:error] = @handler.error
  end
end

#destroyObject

DELETE /admin/orders/:order_id/promotions/:id



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'app/controllers/spree/admin/orders/order_promotions_controller.rb', line 34

def destroy
  authorize! :update, @order

  coupon_code = @order_promotion.code.presence || @order_promotion.name

  @handler = Spree::PromotionHandler::Coupon.new(@order)
  @handler.remove(coupon_code)

  if @handler.successful?
    flash.now[:success] = @handler.success
    @order.reload
    load_order_items
  else
    flash.now[:error] = @handler.error
  end
end

#newObject

GET /admin/orders/:order_id/order_promotions/new



13
# File 'app/controllers/spree/admin/orders/order_promotions_controller.rb', line 13

def new; end