【问题标题】:Catching order changing events in Shopware 5.4.*在 Shopware 5.4 中捕获订单更改事件。*
【发布时间】:2021-06-08 08:20:25
【问题描述】:

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

  • 订单状态
  • 付款状态

但我需要捕捉以下事件:

  • 更改订单项,例如替换、删除或添加
  • 收货地址和/或帐单地址变更
  • 支付网关等支付信息发生变化。

【问题讨论】:

  • 你找到解决办法了吗?
  • @toesslab 目前没有
  • 您介意分享用于订单状态和付款状态的代码吗?是在插件里面吗?

标签: shopware shopware5


【解决方案1】:

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

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

<?php

namespace <your namespace>;

use Doctrine\Common\EventSubscriber;
use Doctrine\ORM\Event\LifecycleEventArgs;
use Doctrine\ORM\Events;
use Shopware\Models\Order\Detail;

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
        }
    }

}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多