Custom Event Listener wird mehrfach ausgelöst trotz Flag im Custom Field

Hallo zusammen,

ich habe in meinem Plugin einen eigenen Event Listener angelegt. Dieser wird aufgerufen, wenn die Versandkosten einer Bestellung geändert werden. Sobald das Event ausgelöst wird, setze ich das Custom-Feld custom_offer_mail_send auf true, um alle weiteren Event-Dispatches zu verhindern.

Allerdings funktioniert das nicht immer zuverlässig. Es scheint, als würde Shopware den Wert cachen.
Gibt es eine Möglichkeit, das Caching für bestimmte Variablen oder Listener zu deaktivieren?
Oder hat jemand eine andere Idee, warum das Event mehrfach ausgeführt wird?

Hier ist mein Code:

<?php declare(strict_types=1);

namespace ExamplePlugin\Core\Admin\Offer\Listener;

use Psr\Log\LoggerInterface;
use ExamplePlugin\Core\Admin\Offer\Event\ShippingCostUpdated;
use Shopware\Core\Framework\Context;
use Shopware\Core\Framework\DataAbstractionLayer\Event\EntityWrittenEvent;
use Shopware\Core\Checkout\Order\OrderEntity;
use Shopware\Core\Checkout\Customer\CustomerEntity;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
use Shopware\Core\Framework\DataAbstractionLayer\EntityRepository;

class ShippingCostChangedListener
{
    private $logger;
    
    private EventDispatcherInterface $eventDispatcher;
    private EntityRepository $orderRepository;

    public function __construct(LoggerInterface $logger, EventDispatcherInterface $eventDispatcher, EntityRepository $orderRepository)
    {
        $this->logger = $logger;
        $this->eventDispatcher = $eventDispatcher;
        $this->orderRepository = $orderRepository;
    }

    public function onOrderUpdated(EntityWrittenEvent $event): void
    {
        //$this->logger->notice('LoggerEvent: ' . var_export($event, true));

        // Überprüfen, ob das Event für die order_customer-Entität ist
        if ($event->getEntityName() !== 'order_customer') {
            return;
        }

        // Extrahieren der Order-ID aus dem Payload
        $orderId = $event->getPayloads()[0]['orderId'] ?? null;
        if (!$orderId) {
            //$this->logger->error('Order ID not found in the event payload.');
            return;
        }

        // Laden der OrderEntity
        $context = $event->getContext(); 
        $criteria = new Criteria([$orderId]);
        $criteria->addAssociation('deliveries.shippingMethod');
        $criteria->addAssociation('orderCustomer.customer');

        $criteria->setLimit(1); //try to disable caching

        /** @var OrderEntity|null $order */
        $order = $this->orderRepository->search($criteria, $context)->first();
        if (!$order) {
            $this->logger->error('Order not found with ID: ' . $orderId);
            return;
        }

        // Extrahieren der Versandkosten und Versandart
        $shippingCosts = $order->getShippingTotal();
        $shippingMethod = $order->getDeliveries()?->first()?->getShippingMethod()?->getName();
        $shippingMethodTechnicalName = $order->getDeliveries()?->first()?->getShippingMethod()?->getTechnicalName();

        $customFields = $order->getCustomFields();
        $mailSent = isset($customFields['custom_offer_mail_send']) && (bool)$customFields['custom_offer_mail_send'];

        $this->logger->notice('Shipping costs: ' . $shippingCosts);
        $this->logger->notice('Shipping method: ' . $shippingMethod);
        $this->logger->notice('Custom fields: ' . var_export($customFields, true));
        $this->logger->notice('Custom offer mail sent: ' . var_export($mailSent, true));

        /** @var CustomerEntity|null $customer */
        $customer = $order->getOrderCustomer()?->getCustomer();
        if (!$customer) {
            $this->logger->error('Customer not found for order ID: ' . $orderId);
            return;
        }

        if ($mailSent) {
            $this->logger->notice('Custom offer mail already sent. Aborting.');
            return;
        }

        // Hier kannst du deinen Eventaufruf durchführen
        if($shippingMethodTechnicalName == "individuelle_shipping_eu" && $shippingCosts != 0.0) {
            $this->dispatchCustomEvent($context, $order, $customer);

            $this->updateCustomField($orderId, $context);
        }
    }

    private function dispatchCustomEvent(Context $context, OrderEntity $order, CustomerEntity $customer): void
    {
        $this->eventDispatcher->dispatch(
            new ShippingCostUpdated($context, $order, $customer)
        );

        //$this->logger->notice('Custom event dispatched for order ID: ' . $order->getId());
    }

    private function updateCustomField(string $orderId, Context $context): void
    {
        $this->orderRepository->update([
            [
                'id' => $orderId,
                'customFields' => [
                    'custom_offer_mail_send' => true,
                ],
            ],
        ], $context);

        $this->logger->notice('Custom field "offer_mail_send" updated for order ID: ' . $orderId);
    }
}

Vielen Dank für Eure Hilfe.
Viele Grüße
Oskar P.