你好,我试图检测当一个新的订单进入我的商店使用shopware 6.5
这就是我正在做的:OrderEvents::ORDER_WRITTEN_EVENT => 'OnOrderReceived',
public function OnOrderReceived(EntityWrittenEvent $event) { if ($event->getEntityName() === 'order') {
$writtenEntities = $event->getWriteResults();
foreach ($writtenEntities as $writeResult) {
// Get the entity data from the write result
$entityData = $writeResult->getPayload();
// Get the order ID from the entity data
$orderId = $entityData['id'];
$orderNumber = $entityData['orderNumber'];
// $this->logger->info('Orders is created, the order id is : ' . $orderId . ' and order number : ' . $orderNumber);
}
}
}`
这样我就可以得到订单的ID和编号,但我似乎无法捕捉订单的当前状态,例如“打开”。请问这个怎么做?
1条答案
按热度按时间aurhwmvo1#
OrderEvents::ORDER_WRITTEN_EVENT
是一个相当低级别的技术事件,所以很难得到你需要的信息。您应该更好地收听
\Shopware\Core\Checkout\Cart\Event\CheckoutOrderPlacedEvent
,因为该事件可以让您轻松访问所需的信息: