custom/plugins/MolliePayments/src/Subscriber/CartConvertedSubscriber.php line 20

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace Kiener\MolliePayments\Subscriber;
  4. use Kiener\MolliePayments\Service\CustomFieldsInterface;
  5. use Shopware\Core\Checkout\Cart\Order\CartConvertedEvent;
  6. use Shopware\Core\Framework\Struct\ArrayStruct;
  7. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  8. final class CartConvertedSubscriber implements EventSubscriberInterface
  9. {
  10.     public static function getSubscribedEvents()
  11.     {
  12.         return [
  13.             CartConvertedEvent::class => 'savePayPalExpressData',
  14.         ];
  15.     }
  16.     public function savePayPalExpressData(CartConvertedEvent $event): void
  17.     {
  18.         $cart $event->getCart();
  19.         $cartExtension $cart->getExtension(CustomFieldsInterface::MOLLIE_KEY);
  20.         if (! ($cartExtension instanceof ArrayStruct)) {
  21.             return;
  22.         }
  23.         $paypalExpressAuthenticateId $cartExtension[CustomFieldsInterface::PAYPAL_EXPRESS_AUTHENTICATE_ID] ?? null;
  24.         if ($paypalExpressAuthenticateId === null) {
  25.             return;
  26.         }
  27.         $convertedCart $event->getConvertedCart();
  28.         $convertedCart['customFields'][CustomFieldsInterface::MOLLIE_KEY][CustomFieldsInterface::PAYPAL_EXPRESS_AUTHENTICATE_ID] = $paypalExpressAuthenticateId;
  29.         $event->setConvertedCart($convertedCart);
  30.     }
  31. }