Shopware 6 中是否有订单状态更改事件?

Is there an order state change event in Shopware 6?

Shopware 6 中的订单具有以下状态:

<?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';
}

是否可以订阅状态变化?是否存在状态更改事件或这些状态是否可以用作事件?如果是,如何获取更改后的状态名称?

您可以在这里找到所有订单事件:https://github.com/shopware/platform/blob/6.2/src/Core/Checkout/Order/OrderEvents.php

ORDER_TRANSACTION_STATE_* 要么 ORDER_WRITTEN_EVENT

应该是这样。

在此之后您可以获得 EntityEvent 的 Payload:https://github.com/shopware/platform/blob/6.2/src/Core/Framework/DataAbstractionLayer/Event/EntityWrittenEvent.php -> getPayloads()

事件在 StateMachineRegistry::transition 中调度。 正如您在 StateMachineStateChangeEvent 中看到的那样,事件名称是根据已更改的状态生成的,例如state_machine.order_transaction.state_changed

这些事件甚至在 Shopware itself to dispatch special OrderStateMachineStateChangeEvents. The name for these events are generated here 中使用,例如state_enter.order_transaction.state.paid