Class: Spree::Admin::LineItemsController

Inherits:
BaseController show all
Defined in:
app/controllers/spree/admin/line_items_controller.rb

Instance Method Summary collapse

Methods included from Core::ControllerHelpers

included

Instance Method Details

#createObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'app/controllers/spree/admin/line_items_controller.rb', line 10

def create
  variant = Variant.find(params[:line_item][:variant_id])
  @line_item = @order.add_variant(variant, params[:line_item][:quantity].to_i)

  if @order.save
    respond_with(@line_item) do |format|
      format.html { render :partial => 'spree/admin/orders/form', :locals => { :order => @order.reload }, :layout => false }
    end
  else
    respond_with(@line_item) do |format|
      format.js { render :action => 'create', :locals => { :order => @order.reload }, :layout => false }
    end
  end
end

#destroyObject



25
26
27
28
29
30
31
32
33
34
35
# File 'app/controllers/spree/admin/line_items_controller.rb', line 25

def destroy
  if @line_item.destroy
    respond_with(@line_item) do |format|
      format.html { render :partial => 'spree/admin/orders/form', :locals => { :order => @order.reload }, :layout => false }
    end
  else
    respond_with(@line_item) do |format|
      format.html { render :partial => 'spree/admin/orders/form', :locals => { :order => @order.reload }, :layout => false }
    end
  end
end

#load_line_itemObject



59
60
61
# File 'app/controllers/spree/admin/line_items_controller.rb', line 59

def load_line_item
  @line_item = @order.line_items.find params[:id]
end

#load_orderObject



55
56
57
# File 'app/controllers/spree/admin/line_items_controller.rb', line 55

def load_order
  @order = Order.find_by_number! params[:order_id]
end

#newObject



37
38
39
40
41
# File 'app/controllers/spree/admin/line_items_controller.rb', line 37

def new
  respond_with do |format|
    format.html { render :action => :new, :layout => false }
  end
end

#updateObject



43
44
45
46
47
48
49
50
51
52
53
# File 'app/controllers/spree/admin/line_items_controller.rb', line 43

def update
  if @line_item.update_attributes(params[:line_item])
    respond_with(@line_item) do |format|
      format.html { render :partial => 'spree/admin/orders/form', :locals => { :order => @order.reload }, :layout => false}
    end
  else
    respond_with(@line_item) do |format|
      format.html { render :partial => 'spree/admin/orders/form', :locals => { :order => @order.reload }, :layout => false}
    end
  end
end