custom/plugins/NxsPayoneModification/src/Communication/Checkout/CheckoutConfirmEventSubscriber.php line 23

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Nxs\NxsPayoneModification\Communication\Checkout;
  3. use Shopware\Storefront\Page\Account\Order\AccountEditOrderPageLoadedEvent;
  4. use Shopware\Storefront\Page\Checkout\Confirm\CheckoutConfirmPageLoadedEvent;
  5. use Shopware\Storefront\Page\PageLoadedEvent;
  6. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  7. class CheckoutConfirmEventSubscriber implements EventSubscriberInterface
  8. {
  9.     private const PAY_ONE_EXTENSION 'payone';
  10.     private const TEMPLATE_PROPERTY 'template';
  11.     public static function getSubscribedEvents()
  12.     {
  13.         return [
  14.             CheckoutConfirmPageLoadedEvent::class => 'checkoutConfirmEventLoader',
  15.             AccountEditOrderPageLoadedEvent::class => 'checkoutConfirmEventLoader',
  16.         ];
  17.     }
  18.     public function checkoutConfirmEventLoader(PageLoadedEvent $event)
  19.     {
  20.         $page $event->getPage();
  21.         if ($page->hasExtension(self::PAY_ONE_EXTENSION)) {
  22.             $payoneExtension $page->getExtension(self::PAY_ONE_EXTENSION);
  23.             $this->assignPayoneTemplateToCustomTemplate($payoneExtension);
  24.         }
  25.     }
  26.     private function assignPayoneTemplateToCustomTemplate($payoneExtension)
  27.     {
  28.         if (!empty($payoneExtension->getVars()[self::TEMPLATE_PROPERTY])) {
  29.             $templateName $payoneExtension->getVars()[self::TEMPLATE_PROPERTY];
  30.             if (strpos($templateName'payolution-invoicing-form') || strpos($templateName'payolution-installment-form')) {
  31.                 $payoneExtension->assign([self::TEMPLATE_PROPERTY => substr_replace($templateName"-fixed", -10) . '.html.twig']);
  32.             }
  33.         }
  34.     }
  35. }