vendor/wallee/shopware-6/src/Core/Storefront/Account/Subscriber/AccountOrderSubscriber.php line 65

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace WalleePayment\Core\Storefront\Account\Subscriber;
  3. use Psr\Log\LoggerInterface;
  4. use Shopware\Core\Framework\Struct\ArrayStruct;
  5. use Shopware\Storefront\Page\Account\Order\AccountOrderPageLoadedEvent;
  6. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  7. use WalleePayment\Core\Settings\Service\SettingsService;
  8. /**
  9.  * Class AccountOrderSubscriber
  10.  *
  11.  * @package WalleePayment\Core\Storefront\Account\Subscriber
  12.  */
  13. class AccountOrderSubscriber implements EventSubscriberInterface {
  14.     /**
  15.      * @var \Psr\Log\LoggerInterface
  16.      */
  17.     protected $logger;
  18.     /**
  19.      * @var \WalleePayment\Core\Settings\Service\SettingsService
  20.      */
  21.     private $settingsService;
  22.     /**
  23.      * CheckoutSubscriber constructor.
  24.      *
  25.      * @param \WalleePayment\Core\Settings\Service\SettingsService $settingsService
  26.      */
  27.     public function __construct(SettingsService $settingsService)
  28.     {
  29.         $this->settingsService $settingsService;
  30.     }
  31.     /**
  32.      * @param \Psr\Log\LoggerInterface $logger
  33.      * @internal
  34.      * @required
  35.      *
  36.      */
  37.     public function setLogger(LoggerInterface $logger): void
  38.     {
  39.         $this->logger $logger;
  40.     }
  41.     /**
  42.      * @return array
  43.      */
  44.     public static function getSubscribedEvents(): array
  45.     {
  46.         return [
  47.             AccountOrderPageLoadedEvent::class => ['onAccountOrderPageLoaded'1],
  48.         ];
  49.     }
  50.     /**
  51.      * Pass settings to template
  52.      *
  53.      * @param \Shopware\Storefront\Page\Account\Order\AccountOrderPageLoadedEvent $event
  54.      */
  55.     public function onAccountOrderPageLoaded(AccountOrderPageLoadedEvent $event): void
  56.     {
  57.         $walleeSettings = new ArrayStruct();
  58.         $walleeSettings->set(SettingsService::CONFIG_STOREFRONT_INVOICE_DOWNLOAD_ENABLEDfalse);
  59.         try {
  60.             $settings $this->settingsService->getValidSettings($event->getSalesChannelContext()->getSalesChannel()->getId());
  61.             if (is_null($settings)) {
  62.                 $this->logger->notice('Disabling invoice downloads');
  63.             } else {
  64.                 $walleeSettings->set(SettingsService::CONFIG_STOREFRONT_INVOICE_DOWNLOAD_ENABLED$settings->isStorefrontInvoiceDownloadEnabled());
  65.             }
  66.         } catch (\Exception $e) {
  67.             $this->logger->error($e->getMessage());
  68.         }
  69.         $event->getPage()->addExtension('walleeSettings'$walleeSettings);
  70.     }
  71. }