Class: Spree::Api::ShipmentsController

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

Instance Attribute Summary

Attributes inherited from BaseController

#current_api_user

Instance Method Summary collapse

Methods inherited from BaseController

#map_nested_attributes_keys, #set_jsonp_format

Methods included from ControllerSetup

included

Instance Method Details

#addObject



61
62
63
64
65
66
67
68
# File 'app/controllers/spree/api/shipments_controller.rb', line 61

def add
  variant = Spree::Variant.find(params[:variant_id])
  quantity = params[:quantity].to_i

  @order.contents.add(variant, quantity, nil, @shipment)

  respond_with(@shipment, :default_template => :show)
end

#createObject



9
10
11
12
13
14
15
16
17
18
19
# File 'app/controllers/spree/api/shipments_controller.rb', line 9

def create
  variant = Spree::Variant.find(params[:variant_id])
  quantity = params[:quantity].to_i
  @shipment = @order.shipments.create(:stock_location_id => params[:stock_location_id])
  @order.contents.add(variant, quantity, nil, @shipment)

  @shipment.refresh_rates
  @shipment.save!

  respond_with(@shipment.reload, :default_template => :show)
end

#readyObject



41
42
43
44
45
46
47
48
49
50
51
# File 'app/controllers/spree/api/shipments_controller.rb', line 41

def ready
  authorize! :read, Shipment
  unless @shipment.ready?
    if @shipment.can_ready?
      @shipment.ready!
    else
      render "spree/api/shipments/cannot_ready_shipment", :status => 422 and return
    end
  end
  respond_with(@shipment, :default_template => :show)
end

#removeObject



70
71
72
73
74
75
76
77
# File 'app/controllers/spree/api/shipments_controller.rb', line 70

def remove
  variant = Spree::Variant.find(params[:variant_id])
  quantity = params[:quantity].to_i

  @order.contents.remove(variant, quantity, @shipment)
  @shipment.reload if @shipment.persisted?
  respond_with(@shipment, :default_template => :show)
end

#shipObject



53
54
55
56
57
58
59
# File 'app/controllers/spree/api/shipments_controller.rb', line 53

def ship
  authorize! :read, Shipment
  unless @shipment.shipped?
    @shipment.ship!
  end
  respond_with(@shipment, :default_template => :show)
end

#updateObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'app/controllers/spree/api/shipments_controller.rb', line 21

def update
  authorize! :read, Shipment
  @shipment = @order.shipments.find_by_number!(params[:id])

  unlock = params[:shipment].delete(:unlock)

  if unlock == 'yes'
    @shipment.adjustment.open
  end

  @shipment.update_attributes(params[:shipment])

  if unlock == 'yes'
    @shipment.adjustment.close
  end

  @shipment.reload
  respond_with(@shipment, :default_template => :show)
end