custom/plugins/AcrisDiscountGroupCS/src/Storefront/Subscriber/AccountPageSubscriber.php line 37

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Acris\DiscountGroup\Storefront\Subscriber;
  3. use Acris\DiscountGroup\Components\DiscountGroupGateway;
  4. use Acris\DiscountGroup\Custom\DiscountGroupEntity;
  5. use Shopware\Core\Framework\Struct\ArrayEntity;
  6. use Shopware\Core\System\SystemConfig\SystemConfigService;
  7. use Shopware\Storefront\Page\Account\Overview\AccountOverviewPageLoadedEvent;
  8. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  9. class AccountPageSubscriber implements EventSubscriberInterface
  10. {
  11.     /**
  12.      * @var SystemConfigService
  13.      */
  14.     private $systemConfigService;
  15.     /**
  16.      * @var DiscountGroupGateway
  17.      */
  18.     private $discountGroupGateway;
  19.     public function __construct(SystemConfigService $systemConfigServiceDiscountGroupGateway $discountGroupGateway)
  20.     {
  21.         $this->systemConfigService $systemConfigService;
  22.         $this->discountGroupGateway $discountGroupGateway;
  23.     }
  24.     public static function getSubscribedEvents(): array
  25.     {
  26.         return [
  27.             AccountOverviewPageLoadedEvent::class => 'onAccountOverviewPageLoaded'
  28.         ];
  29.     }
  30.     public function onAccountOverviewPageLoaded(AccountOverviewPageLoadedEvent $event): void
  31.     {
  32.         $discountGroupResult $this->discountGroupGateway->getAllDiscountGroups($event->getSalesChannelContext());
  33.         if ($discountGroupResult->count() === 0) {
  34.             return;
  35.         }
  36.         $discountGroupDisplayList = [];
  37.         /** @var DiscountGroupEntity $discountGroup */
  38.         foreach ($discountGroupResult->getElements() as $discountGroup) {
  39.             if( $discountGroup->getAccountDisplay() && $discountGroup->getTranslation('displayText')  != '' )
  40.                 $discountGroupDisplayList[] = $discountGroup->getTranslation('displayText');
  41.         }
  42.         $event->getPage()->addExtension('acris_discount_group', new ArrayEntity([
  43.             'assigned_discount_groups' => $discountGroupDisplayList
  44.         ]));
  45.     }
  46. }