Skip to content

Instantly share code, notes, and snippets.

@saravanak
Last active October 9, 2018 18:31
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save saravanak/1c7ff7e9f5fae6bb3bc1f22945b095d7 to your computer and use it in GitHub Desktop.
Save saravanak/1c7ff7e9f5fae6bb3bc1f22945b095d7 to your computer and use it in GitHub Desktop.
The updated checkouts decorator for working around spree/issue/8569
# app/controllers/spree/api/v1/checkouts_controller_decorator.rb
Spree::Api::V1::CheckoutsController.class_eval do
def update
authorize! :update, @order, order_token
if @order.update_from_params(params, permitted_checkout_attributes, request.headers.env)
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
should_stagnate = params.has_key?(:stagnate) and params[:stagnate]
if should_stagnate
respond_with(@order, default_template: 'spree/api/v1/orders/show')
return
end
if @order.completed? || @order.next
state_callback(:after)
respond_with(@order, default_template: 'spree/api/v1/orders/show')
else
respond_with(@order, default_template: 'spree/api/v1/orders/could_not_transition', status: 422)
end
else
invalid_resource!(@order)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment