-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Updating order through API returns order to ADDRESS state #8569
Comments
I have added a repo which replicates the case of updating the address while the order is in state Observations:
EDIT If we need to disable the |
@saravanak thank you so much! Do you know if I can use the |
@vitutc , If you use the The
So we can get something like what you want by customizing the #app/controllers/spree/api/v1/checkouts_controller.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
# Modified here
if params[:stagnate] and @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 You could then use the |
@vitutc, there are minor changes in the approach as described above. Refer this gist. The above replicator repo has been updated with the required specs too! |
When updating an order through the OrderUpdateAPI, using Spree 3.2.7.
https://guides.spreecommerce.org/api/checkouts.html#updating-an-order
It causes the order to return to the ADDRESS state. Since there is no documentation regarding this, I would like to know if it's intended or a bug.
Context
I would like to use order update API to update order contents without necessarily changing state.
For example: when in PAYMENT state, I would like to change my address (shipping rate fixed) but would like the order continue in the PAYMENT state. Or while in PAYMENT state, I would like to change my payment method to a different one before continuing.
The problem is that regardless of what I updated and of the state of the order, using the OrderUpdateAPI always causes the order to return to the ADDRESS state automatically.
Expected Behavior
The documentation is not clear, but I expect the order state to remain the same when an update does not contain anything critical.
Actual Behavior
Upon update, the order returns to ADDRESS state.
Possible Fix
I did some digging but all I could find is this, which mentions that
order would transition to address state on confirm failure
.https://github.com/spree/spree/blob/master/core/app/models/spree/order.rb#L212
But I could not find any traces in the source to indicate where this is done.
Steps to Reproduce
PUT /api/v1/orders/:number.json?order_token=abcdef123456
to insert a payment method to the order without advancing it to the next.Your Environment
The text was updated successfully, but these errors were encountered: