Class: Admin::ShipmentsController

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

Instance Method Summary collapse

Instance Method Details

#createObject



21
22
23
24
25
26
27
28
29
30
31
32
# File 'app/controllers/admin/shipments_controller.rb', line 21

def create
  build_shipment
  assign_inventory_units
  if @shipment.save
    flash[:notice] = flash_message_for(@shipment, :successfully_created)
    respond_with(@shipment) do |format|
      format.html { redirect_to edit_admin_order_shipment_path(@order, @shipment) }
    end
  else
    respond_with(@shipment) { |format| format.html { render :action => 'new' } }
  end
end

#destroyObject



57
58
59
60
# File 'app/controllers/admin/shipments_controller.rb', line 57

def destroy
  @shipment.destroy
  respond_with(@shipment) { |format| format.js { render_js_for_destroy } }
end

#editObject



34
35
36
37
# File 'app/controllers/admin/shipments_controller.rb', line 34

def edit
  @shipment.special_instructions = @order.special_instructions
  respond_with(@shipment)
end

#fireObject



62
63
64
65
66
67
68
69
70
# File 'app/controllers/admin/shipments_controller.rb', line 62

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 } }
end

#indexObject



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

def index
  @shipments = @order.shipments
  respond_with(@shipments)
end

#newObject



13
14
15
16
17
18
19
# File 'app/controllers/admin/shipments_controller.rb', line 13

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)
end

#updateObject



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'app/controllers/admin/shipments_controller.rb', line 39

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 }
    end
  else
    respond_with(@shipment) { |format| format.html { render :action => 'edit' } }
  end
end