Class: Admin::ShipmentsController

Inherits:
BaseController
  • Object
show all
Defined in:
app/controllers/admin/shipments_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'app/controllers/admin/shipments_controller.rb', line 25

def create
  build_shipment
  assign_inventory_units
  if @shipment.save
    flash[:notice] = flash_message_for(@shipment, :successfully_created)
    #respond_with(@shipment) do |format|
      #ormat.html { redirect_to edit_admin_order_shipment_path(@order, @shipment) }
           render :json => @shipment.to_json, :status => 201

    #end
  else
    respond_with(@object.errors, :status => 422)
 
    #respond_with(@shipment) { |format| format.html { render :action => 'new' } }
  end
end

#destroyObject



71
72
73
74
75
76
# File 'app/controllers/admin/shipments_controller.rb', line 71

def destroy
  @shipment.destroy
  render :json => @shipment.to_json, :status => 201
 
 #respond_with(@shipment) { |format| format.js { render_js_for_destroy } }
end

#editObject



42
43
44
45
46
47
# File 'app/controllers/admin/shipments_controller.rb', line 42

def edit
  @shipment.special_instructions = @order.special_instructions
  #respond_with(@shipment)
 render :json => @shipment.to_json, :status => 201
 
end

#fireObject



78
79
80
81
82
83
84
85
86
87
88
# File 'app/controllers/admin/shipments_controller.rb', line 78

def fire
  if @shipment.send("#{params[:e]}")
    flash.notice = t('shipment_updated')
  else
    flash[:error] = t('cannot_perform_operation')
  end

  #respond_with(@shipment) { |format| format.html { redirect_to :back } }
        render :json => @shipment.to_json, :status => 201

end

#indexObject



8
9
10
11
12
13
# File 'app/controllers/admin/shipments_controller.rb', line 8

def index
  @shipments = @order.shipments
  #respond_with(@shipments)
  render :json => @shipment.to_json, :status => 201
 
end

#newObject



15
16
17
18
19
20
21
22
23
# File 'app/controllers/admin/shipments_controller.rb', line 15

def new
  build_shipment
  @shipment.address ||= @order.ship_address
  @shipment.address ||= Address.new(:country_id => Spree::Config[:default_country_id])
  @shipment.shipping_method = @order.shipping_method
  #respond_with(@shipment)
  render :json => @shipment.to_json, :status => 201
 
end

#updateObject



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'app/controllers/admin/shipments_controller.rb', line 49

def update
  assign_inventory_units
  if @shipment.update_attributes params[:shipment]
    # copy back to order if instructions are enabled
    @order.special_instructions = object_params[:special_instructions] if Spree::Config[:shipping_instructions]
    @order.shipping_method = @order.shipment.shipping_method
    @order.save

    flash[:notice] = flash_message_for(@shipment, :successfully_updated)
    return_path = @order.completed? ? edit_admin_order_shipment_path(@order, @shipment) : admin_order_adjustments_path(@order)
    #respond_with(@object) do |format|
      #format.html { redirect_to return_path }
      render :json => @shipment.to_json, :status => 201
 
    #end
  else
    #respond_with(@shipment) { |format| format.html { render :action => 'edit' } }
    render :json => @shipment.to_json, :status => 201
 
  end
end