Search code examples
phpsymfonyeventsshopwaresubscriber

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?


Solution

  • 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()