David
David

Reputation: 576

Is there an order state change event in Shopware 6?

Orders in Shopware 6 have these states:

<?php declare(strict_types=1);

namespace Shopware\Core\Checkout\Order;

final class OrderStates
{
    public const STATE_MACHINE = 'order.state';
    public const STATE_OPEN = 'open';
    public const STATE_IN_PROGRESS = 'in_progress';
    public const STATE_COMPLETED = 'completed';
    public const STATE_CANCELLED = 'cancelled';
}

Is it possible to subscribe to the state changes? Is there a state change event or could these states be used as events? If yes, how to get the changed state name?

Upvotes: 2

Views: 2445

Answers (2)

Michael T
Michael T

Reputation: 927

The events are dispatched in the StateMachineRegistry::transition. As you can see in the StateMachineStateChangeEvent, the event name is generated on base of the state which is changed, e.g. state_machine.order_transaction.state_changed

These events are even used in Shopware itself to dispatch special OrderStateMachineStateChangeEvents. The name for these events are generated here, e.g. state_enter.order_transaction.state.paid

Upvotes: 7

Florian Liebig
Florian Liebig

Reputation: 36

You can find all order events in here: https://github.com/shopware/platform/blob/6.2/src/Core/Checkout/Order/OrderEvents.php

ORDER_TRANSACTION_STATE_* or ORDER_WRITTEN_EVENT

Should be the way to go.

After this you can get the Payload of of the EntityEvent: https://github.com/shopware/platform/blob/6.2/src/Core/Framework/DataAbstractionLayer/Event/EntityWrittenEvent.php -> getPayloads()

Upvotes: 2

Related Questions