Class: Spree::Api::V1::OrdersController
Instance Attribute Summary
#current_api_user
Instance Method Summary
collapse
#map_nested_attributes_keys
included
Instance Method Details
#address ⇒ Object
31
32
33
34
35
|
# File 'app/controllers/spree/api/v1/orders_controller.rb', line 31
def address
order.build_ship_address(params[:shipping_address]) if params[:shipping_address]
order.build_bill_address(params[:billing_address]) if params[:billing_address]
next!
end
|
#cancel ⇒ Object
48
49
50
51
|
# File 'app/controllers/spree/api/v1/orders_controller.rb', line 48
def cancel
order.cancel!
render :show
end
|
#create ⇒ Object
16
17
18
19
|
# File 'app/controllers/spree/api/v1/orders_controller.rb', line 16
def create
@order = Order.build_from_api(current_api_user, nested_params)
next!(:status => 201)
end
|
#delivery ⇒ Object
37
38
39
40
41
42
43
44
45
46
|
# File 'app/controllers/spree/api/v1/orders_controller.rb', line 37
def delivery
begin
ShippingMethod.find(params[:shipping_method_id])
rescue ActiveRecord::RecordNotFound
render :invalid_shipping_method, :status => 422
else
order.update_attribute(:shipping_method_id, params[:shipping_method_id])
next!
end
end
|
#empty ⇒ Object
53
54
55
56
57
|
# File 'app/controllers/spree/api/v1/orders_controller.rb', line 53
def empty
order.line_items.destroy_all
order.update!
render :text => nil, :status => 200
end
|
#index ⇒ Object
7
8
9
10
11
|
# File 'app/controllers/spree/api/v1/orders_controller.rb', line 7
def index
raise CanCan::AccessDenied unless current_api_user.has_spree_role?("admin")
@orders = Order.ransack(params[:q]).result.page(params[:page]).per(params[:per_page])
end
|
#show ⇒ Object
13
14
|
# File 'app/controllers/spree/api/v1/orders_controller.rb', line 13
def show
end
|
#update ⇒ Object
21
22
23
24
25
26
27
28
29
|
# File 'app/controllers/spree/api/v1/orders_controller.rb', line 21
def update
authorize! :update, Order
if order.update_attributes(nested_params)
order.update!
render :show
else
invalid_resource!(order)
end
end
|