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

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\Storefront\Page\Account\Overview\AccountOverviewPageLoadedEvent;
  7. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  8. class AccountPageSubscriber implements EventSubscriberInterface
  9. {
  10.     /**
  11.      * @var DiscountGroupGateway
  12.      */
  13.     private $discountGroupGateway;
  14.     public function __construct(
  15.         DiscountGroupGateway $discountGroupGateway
  16.     ) {
  17.         $this->discountGroupGateway $discountGroupGateway;
  18.     }
  19.     public static function getSubscribedEvents(): array
  20.     {
  21.         return [
  22.             AccountOverviewPageLoadedEvent::class => 'onAccountOverviewPageLoaded'
  23.         ];
  24.     }
  25.     public function onAccountOverviewPageLoaded(AccountOverviewPageLoadedEvent $event): void
  26.     {
  27.         $discountGroupResult $this->discountGroupGateway->getAllDiscountGroups($event->getSalesChannelContext());
  28.         if ($discountGroupResult->count() === 0) {
  29.             return;
  30.         }
  31.         $discountGroupDisplayList = [];
  32.         /** @var DiscountGroupEntity $discountGroup */
  33.         foreach ($discountGroupResult->getElements() as $discountGroup) {
  34.             if( $discountGroup->getAccountDisplay() && $discountGroup->getTranslation('displayText')  != '' )
  35.                 $discountGroupDisplayList[] = $discountGroup->getTranslation('displayText');
  36.         }
  37.         $event->getPage()->addExtension('acris_discount_group', new ArrayEntity([
  38.             'assigned_discount_groups' => $discountGroupDisplayList
  39.         ]));
  40.     }
  41. }