捕捉Shopware 5.4中的订单更改事件



在Shopware 5.4中,我能够捕捉到变化的事件:

  • 订单状态
  • <
  • 支付状态/gh>

但是我需要捕获事件:

  • 更改订单项,如替换,删除或添加
  • 运输和/或账单地址变更
  • 更改支付信息,如支付网关等

最好的解决方案是添加一个DoctrineCommonEventSubscriber:使用Symfony DI标签doctrine.event_subscriber

这将解决通过后端或api的所有更改,因为它们是基于原则的。没有原则的改变很难追踪。

<?php
namespace <your namespace>;
use DoctrineCommonEventSubscriber;
use DoctrineORMEventLifecycleEventArgs;
use DoctrineORMEvents;
use ShopwareModelsOrderDetail;
class Doctrine implements EventSubscriber
{
/**
* @inheritDoc
*/
public function getSubscribedEvents()
{
return [
Events::preRemove,
Events::postUpdate
];
}
/**
* @param LifecycleEventArgs $args
*/
public function preRemove(LifecycleEventArgs $args)
{
if($args->getEntity() instanceof Detail)
{
// order detail has removed
}
}
/**
* @param LifecycleEventArgs  $eventArgs
*/
public function postUpdate(LifecycleEventArgs $eventArgs)
{
$enity = $eventArgs->getEntity();
if ($enity instanceof Detail) {
// order detail has changed
}
}
}

最新更新