cancel
Showing results for 
Search instead for 
Did you mean: 

order state and status

order state and status

Hi everyone,

 

In Magento 2, we can see that there are default order statuses that are assigned to "groups", which are order states.  For example, the "pending" order status is part of the "new" order state group.

 

Technically speaking or business wise - for and order created programmatically - could it be an issue to assign the order to a sate and status that are not linked by default?

 

For example would it be an issue to create an order with state "new" and status "processing"?

If it's an issue (I'm hoping it's not), what kind of consequences could it have?

 

Thanks a lot for your answers.

 

5 REPLIES 5

Re: order state and status

It would have to be assigned to a status that was assigned to a certain state.  Magento requires that limit and there are strict rules over how the state of an order is updated. You could have similarly named order statuses and assign one to each order state that you're interested in.

----
If you've found one of my answers useful, please give "Kudos" or "Accept as Solution" as appropriate. Thanks!

Re: order state and status

thank you very much for your answer. Unfortunately I'm not sure to understand clearly what you mean. Are you saying it's an issue to assign a status to a state it doesn't initially belong to?

If yes, what kind of issue are we talking about?

 

I am asking this question because Magento is allowing me to set any state and any status to an order without throwing errors back.

 

If it was a problem to assign a status and a state this status doesn't initially belong to, shouldn't we have warnings saying "you can't do this, the order status is assigned to the wrong order state" ?

Re: order state and status

The problem is assigning a status to an order when the order is in a state that that status isn't available on. Magento will not allow this through the interface. Doing this programatically, even if you manage to succeed, could lead to strange results. 


I don't know the background on why you need to have the same status in two different order states. That's why my suggestion was to create two statuses that mean that same thing, assigning one as available on one order state, and the other assigned to another order state.

----
If you've found one of my answers useful, please give "Kudos" or "Accept as Solution" as appropriate. Thanks!

Re: order state and status

my problem is I've heard a couple of times some developers say "it could" create issues, but I haven't found a single resource on the web explaining why and how it could be a problem.

 

In M2, orders allow to use $order->setState() and $order->setStatus() without any restriction or warning. It just works and this is unusual for something that should not be done.

 

It would be really be helpful to have some insight explaining precisely what kind of side effects we are talking about.

 

Here is one example blog explaining how to do it in another way:

https://gielberkers.com/set-order-status-new-orders-magento/

 

For specific orders created programmatically, why couldn't we assign statuses to states that the statuses don't belong to by default, especially if any other custom status can be assigned to the same states.

Re: order state and status

The reservation from developers will because it isn't standard Magento approach and given it restricts admins from doing this, orders could end up in unexpected states. So without specific experience doing so, it's wise for them to advise a level of risk. 

 

If you've tested it and works though, that's fair enough and you can continue until you run into it. I wasn't sure if Magento would throw an exception when you tried to do that. 

 

For instance, one side effect could be: You programmatically set state, then the order gets moved to another state temporarily in admin (maybe on hold), you will not be able to manually set it back to the original state in admin should you need to because that status isn't assigned to that state through Magento configuration.

----
If you've found one of my answers useful, please give "Kudos" or "Accept as Solution" as appropriate. Thanks!