solidusio / solidus

🛒 Solidus, the open-source eCommerce framework for industry trailblazers.
https://solidus.io
Other
4.97k stars 1.29k forks source link

Unable to transition order state to an older state via API #1902

Closed gaurav945 closed 7 years ago

gaurav945 commented 7 years ago

What is happening

Lets say the order number "R398140812", is in "confirm" state. I want to transition back to "delivery" state. So, I make a PUT call to "api/checkouts/R398140812", with the body as {"state" : "delivery"}, but the state is getting set to "payment" & not "delivery".

What should happen instead

There's a before_action for next, advance, update & complete, by the name of "update_order_state", which checks, if there is a state parameter in the body of the arguments passed. If there is, it appropriately assigns the state to the order, that was passed as the body. But then, afterwards, the update action gets triggered & that does @order.next!, thereby changing the state to "delivery + 1", meaning "payment". So, instead of that happening, shouldn't it just do @order.save, in some action ?

The actual issue

  1. Is this the right way to change the order state when making use of Solidus APIs ?
  2. If this is the right way, shouldn't "update_order_state" action, should have a respond_with, instead of simply being the before_action of some other actions ?
  3. If it is not the right way to transition order state using APIs, please guide me in the right direction as to, how will I then transition the state using APIs ?

System configuration

Solidus Version: 2.1.0

Extensions in use: No Extensions

gaurav945 commented 7 years ago

@kennyadsl some help, please...

kennyadsl commented 7 years ago

Hey there, I'm not sure this kind of state change is allowed via current API, anyway you could try to workaround this by using the /orders/ endpoint. You can even try to build your own endpoint in the api/checkout controller that does the same as update but without triggering the order.next call.

gaurav945 commented 7 years ago

Thanks for the quick reply, I have a follow up query, which is, then how to handle the following scenario :

Suppose, I have a web app, which uses Solidus APIs & the flow is similar to Solidus's flow. Now, let's say that I am on the confirm your order page, but I would like to go back & change my shipment provider, then how will I do that then, without transitioning the state ?

kennyadsl commented 7 years ago

what about going one step back, for example moving to address if you have to go to address + 1 (delivery)? I think it's better moving this conversation on solidus slack #support channel, ok?

gaurav945 commented 7 years ago

Okay & I am sorry for any inconvenience caused, I am actually new to all this, raising issues on github & such technical stuff, so I didn't know what would be the right place to discuss these kind of things.