# Trying to wrap my head around Order and Delivery states

**URL:** <https://forum.litium.com/t/trying-to-wrap-my-head-around-order-and-delivery-states/1801>\
**Category:** Questions\
**Created:** [December 8, 2020, 3:11pm UTC](https://forum.litium.com/t/trying-to-wrap-my-head-around-order-and-delivery-states/1801 "2020-12-08T15:11:28Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Artur](https://yyz2.discourse-cdn.com/flex030/user_avatar/forum.litium.com/artur/32/948_2.png) [@Artur](https://forum.litium.com/u/Artur)\
**Post date:** [December 8, 2020, 3:11pm UTC](https://forum.litium.com/t/trying-to-wrap-my-head-around-order-and-delivery-states/1801/1 "2020-12-08T15:11:28Z")

</div>

Hi,

I’m trying to wrap my head around the state manager.  
Using default Litium, when:  
**waitingconfirmation** =\> **confirmed**  
the email about the order is sent. (default).

Then **init** is set in delivery  
there we want to run an integration to TA system that if success it will go to **processing** and await **deliverystart**

**Init** =\> **processing** seems to never trigger for delivery when I use Directpay.

Do i need to add related state? I tried to do with related against orderconfirmed and the delivery state did change to processing for however the **init** =\> **processing** was never executed.

Do I only use relations on the statemanager to trigger said states between **order** and **delivery** or can I trigger specific state from one and other?

I have checked the documentation regarding states:

> **[Working with State Transitions](https://docs.litium.com/documentation/litium-documentation/sales/working_with_state_transitions)**

But still cannot seem to wrap the idea on how it should be done.

Litium version: 7.4.2

---

<div class="post-metadata">

**Author:** ![steve.redstorm](https://yyz2.discourse-cdn.com/flex030/user_avatar/forum.litium.com/steve.redstorm/32/14_2.png) [@steve.redstorm](https://forum.litium.com/u/steve.redstorm)\
**Post date:** [December 8, 2020, 4:00pm UTC](https://forum.litium.com/t/trying-to-wrap-my-head-around-order-and-delivery-states/1801/2 "2020-12-08T16:00:02Z")

</div>

When Order is created and it is in “init” mode then you need to set the Deliverystatus to Processing in order to change the orderstatus to Processing and when Order is delivered then you can choose to set the Deliverystatus to “Delivered/Canceled or ReadyToShip”. So you will need to handle the statuses with changing DeliveryStatus.

---

<div class="post-metadata">

**Author:** ![Artur](https://yyz2.discourse-cdn.com/flex030/user_avatar/forum.litium.com/artur/32/948_2.png) [@Artur](https://forum.litium.com/u/Artur)\
**Post date:** [December 9, 2020, 7:43am UTC](https://forum.litium.com/t/trying-to-wrap-my-head-around-order-and-delivery-states/1801/3 "2020-12-09T07:43:05Z")

</div>

Yeah I understand the basic flow as you explain it, but how can I do it automatically, right now it needs someone in BO to set processing status for delivery.

How can I automatically trigger the init =\> processing step when the order is confirmed? Do I have to define the related state in StateTransitionBuilder?

```auto
stateManager.DeliveryStateMachine.AddRelatedState((short) OrderState.Confirmed, FiniteStateMachineType.Delivery, (short) DeliveryState.Processing)

```

This seemed to set the Delivery for the order automatically to processing. However it did not execute

```auto
 stateMachine.AddStateTransition(
                new State<DeliveryCarrier>((short)DeliveryState.Init, DeliveryState.Init.ToString()), processing,
                (deliveryCarrier, startState, endState, token) =>
                {

```

---

<div class="post-metadata">

**Author:** ![steve.redstorm](https://yyz2.discourse-cdn.com/flex030/user_avatar/forum.litium.com/steve.redstorm/32/14_2.png) [@steve.redstorm](https://forum.litium.com/u/steve.redstorm)\
**Post date:** [December 9, 2020, 1:26pm UTC](https://forum.litium.com/t/trying-to-wrap-my-head-around-order-and-delivery-states/1801/4 "2020-12-09T13:26:44Z")

</div>

You can try to create and a call a method like this:

```auto
private void ChangeDeliveryStatus(short status, Order order)
		{
			foreach (var delivery in order.Deliveries)
			{
				delivery.SetDeliveryStatus(status, Solution.Instance.SystemToken);
			}
		}

```

This should change the related statuses also for the other entities.

---

<div class="post-metadata">

**Author:** ![marten](https://yyz2.discourse-cdn.com/flex030/user_avatar/forum.litium.com/marten/32/11_2.png) [@marten](https://forum.litium.com/u/marten)\
**Post date:** [December 10, 2020, 9:15am UTC](https://forum.litium.com/t/trying-to-wrap-my-head-around-order-and-delivery-states/1801/5 "2020-12-10T09:15:42Z")

</div>

> [@Artur](#):
>
> How can I automatically trigger the init =\> processing step when the order is confirmed? Do I have to define the related state in StateTransitionBuilder?
> 
> ```auto
> stateManager.DeliveryStateMachine.AddRelatedState((short) OrderState.Confirmed, FiniteStateMachineType.Delivery, (short) DeliveryState.Processing)
> 
> ```

Yes, but adjust your related state so that it connects to the OrderStateMachine:

```diff
-stateManager.DeliveryStateMachine.AddRelatedState((short) OrderState.Confirmed, FiniteStateMachineType.Delivery, (short) DeliveryState.Processing)
+stateManager.OrderStateMachine.AddRelatedState((short) OrderState.Confirmed, FiniteStateMachineType.Delivery, (short) DeliveryState.Processing);

```

---

<div class="post-metadata">

**Author:** ![Artur](https://yyz2.discourse-cdn.com/flex030/user_avatar/forum.litium.com/artur/32/948_2.png) [@Artur](https://forum.litium.com/u/Artur)\
**Post date:** [December 15, 2020, 8:25pm UTC](https://forum.litium.com/t/trying-to-wrap-my-head-around-order-and-delivery-states/1801/6 "2020-12-15T20:25:06Z")

</div>

Thank you this one worked perfectly!

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex030/uploads/litium/original/1X/12eddac3b8b661de1db86af10ac8151b571e6fb9.png) [@system](https://forum.litium.com/u/system)\
**Post date:** [January 12, 2021, 8:25pm UTC](https://forum.litium.com/t/trying-to-wrap-my-head-around-order-and-delivery-states/1801/7 "2021-01-12T20:25:09Z")

</div>

Closed on January 12, 2021, 8:25pm UTC

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
