Class: Spree::Api::ShipmentsController
Instance Attribute Summary
#current_api_user
Instance Method Summary
collapse
#map_nested_attributes_keys, #permitted_line_item_attributes, #set_jsonp_format
included
Instance Method Details
#add ⇒ Object
54
55
56
57
58
59
60
61
|
# File 'app/controllers/spree/api/shipments_controller.rb', line 54
def add
variant = Spree::Variant.find(params[:variant_id])
quantity = params[:quantity].to_i
@shipment.order.contents.add(variant, quantity, nil, @shipment)
respond_with(@shipment, default_template: :show)
end
|
#create ⇒ Object
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
# File 'app/controllers/spree/api/shipments_controller.rb', line 8
def create
unless @order.present?
@order = Spree::Order.find_by!(number: params[:shipment][:order_id])
authorize! :read, @order
end
authorize! :create, Shipment
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.save!
respond_with(@shipment.reload, default_template: :show)
end
|
#ready ⇒ Object
36
37
38
39
40
41
42
43
44
45
|
# File 'app/controllers/spree/api/shipments_controller.rb', line 36
def ready
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
|
#remove ⇒ Object
63
64
65
66
67
68
69
70
|
# File 'app/controllers/spree/api/shipments_controller.rb', line 63
def remove
variant = Spree::Variant.find(params[:variant_id])
quantity = params[:quantity].to_i
@shipment.order.contents.remove(variant, quantity, @shipment)
@shipment.reload if @shipment.persisted?
respond_with(@shipment, default_template: :show)
end
|
#ship ⇒ Object
47
48
49
50
51
52
|
# File 'app/controllers/spree/api/shipments_controller.rb', line 47
def ship
unless @shipment.shipped?
@shipment.ship!
end
respond_with(@shipment, default_template: :show)
end
|
#update ⇒ Object
25
26
27
28
29
30
31
32
33
34
|
# File 'app/controllers/spree/api/shipments_controller.rb', line 25
def update
if @order.present?
@shipment = @order.shipments.accessible_by(current_ability, :update).find_by!(number: params[:id])
else
@shipment = Spree::Shipment.accessible_by(current_ability, :update).readonly(false).find_by!(number: params[:id])
end
@shipment.update_attributes_and_order(shipment_params)
respond_with(@shipment.reload, default_template: :show)
end
|