Class: Spree::Api::CheckoutsController
- Inherits:
-
BaseController
- Object
- ActionController::Metal
- BaseController
- Spree::Api::CheckoutsController
show all
- Includes:
- Core::ControllerHelpers::Auth, Core::ControllerHelpers::Order
- Defined in:
- app/controllers/spree/api/checkouts_controller.rb
Instance Attribute Summary
#current_api_user
Instance Method Summary
collapse
#map_nested_attributes_keys, #set_jsonp_format
included
Instance Method Details
#advance ⇒ Object
27
28
29
30
31
32
|
# File 'app/controllers/spree/api/checkouts_controller.rb', line 27
def advance
load_order(true)
authorize! :update, @order, params[:order_token]
while @order.next; end
respond_with(@order, default_template: 'spree/api/orders/show', status: 200)
end
|
#create ⇒ Object
13
14
15
16
|
# File 'app/controllers/spree/api/checkouts_controller.rb', line 13
def create
@order = Order.build_from_api(current_api_user, nested_params)
respond_with(@order, default_template: 'spree/api/orders/show', status: 201)
end
|
#next ⇒ Object
18
19
20
21
22
23
24
25
|
# File 'app/controllers/spree/api/checkouts_controller.rb', line 18
def next
load_order(true)
authorize! :update, @order, params[:order_token]
@order.next!
respond_with(@order, default_template: 'spree/api/orders/show', status: 200)
rescue StateMachine::InvalidTransition
respond_with(@order, default_template: 'spree/api/orders/could_not_transition', status: 422)
end
|
#show ⇒ Object
34
35
36
|
# File 'app/controllers/spree/api/checkouts_controller.rb', line 34
def show
redirect_to(api_order_path(params[:id]), status: 301)
end
|
#update ⇒ Object
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
# File 'app/controllers/spree/api/checkouts_controller.rb', line 38
def update
load_order(true)
authorize! :update, @order, params[:order_token]
order_params = object_params
user_id = order_params.delete(:user_id)
line_items = order_params.delete("line_items_attributes")
if @order.update_attributes(order_params)
@order.update_line_items(line_items)
if current_api_user.has_spree_role?("admin") && user_id.present?
@order.associate_user!(Spree.user_class.find(user_id))
end
return if after_update_attributes
state_callback(:after) if @order.next
respond_with(@order, :default_template => 'spree/api/orders/show')
else
invalid_resource!(@order)
end
end
|