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

Dav*_*vid 2 php events subscriber symfony shopware

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';
}
Run Code Online (Sandbox Code Playgroud)

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

Mic*_*l T 5

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

这些事件甚至在Shopware 本身中用于调度特殊的OrderStateMachineStateChangeEvent。这些事件的名称在此处生成,例如state_enter.order_transaction.state.paid