custom/plugins/CioPointsFlow/src/Subscriber/AccountPageSubscriber.php line 50

Open in your IDE?
  1. <?php
  2. namespace CioPointsFlow\Subscriber;
  3. use CioCustomerPermissionGroups\Event\CustomerAclRolesEvent;
  4. use CioMasterdata\Service\MasterdataService;
  5. use CioPointsFlow\Service\AccountsCalculationService;
  6. use Shopware\Core\Framework\DataAbstractionLayer\Search\EntitySearchResult;
  7. use Shopware\Storefront\Event\StorefrontRenderEvent;
  8. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  9. class AccountPageSubscriber implements EventSubscriberInterface
  10. {
  11.     private MasterdataService $masterdataService;
  12.     private AccountsCalculationService $accountsCalculationService;
  13.     public function __construct(MasterdataService $masterdataServiceAccountsCalculationService $accountsCalculationService)
  14.     {
  15.         $this->masterdataService $masterdataService;
  16.         $this->accountsCalculationService $accountsCalculationService;
  17.     }
  18.     public static function getSubscribedEvents()
  19.     {
  20.         return [
  21.             StorefrontRenderEvent::class => 'onStorefrontRenderEvent',
  22.             CustomerAclRolesEvent::class => 'onCustomerAclRolesEvent'
  23.         ];
  24.     }
  25.     public function onStorefrontRenderEvent(StorefrontRenderEvent $event)
  26.     {
  27.         $customer $event->getSalesChannelContext()->getCustomer();
  28.         if ($customer) {
  29.             if ($event->getView() === '@CioCustomerPermissionGroups/storefront/page/account/index.html.twig') {
  30.                 if ($this->masterdataService->getMasterdatasForCustomer($customer) instanceof EntitySearchResult) {
  31.                     $event->setParameter('masterdata'$this->masterdataService->getMasterdatasForCustomer($customertrue)->first());
  32.                 }
  33.                 $event->setParameter('totalAccountAmount'$this->accountsCalculationService->calculateTotalAccount($event->getContext()));
  34.                 $event->setParameter('statusAccountAmount'$this->accountsCalculationService->calculateStatusAccount($event->getContext()));
  35.                 $event->setParameter('useableAccountAmount'$this->accountsCalculationService->calculateUsableAccount($event->getSalesChannelContext()->getContext(), $event->getSalesChannelContext()->getCustomer()));
  36.             }
  37.         }
  38.     }
  39.     public function onCustomerAclRolesEvent(CustomerAclRolesEvent $event)
  40.     {
  41.         // add all in this plugin used customer acl roles
  42.         $event->addRoles([
  43.             [
  44.                 'title' => 'BUDGET_EXPIRE_CALCULATE',
  45.                 'description' => 'Kunde kann Punkte die aktuell in einem ausgewählten Zeitraum verfallen würden ermitteln und ausgeben lassen.'
  46.             ],
  47.             [
  48.                 'title' => 'BUDGET_EXPIRE_EXECUTE_CALCULATED',
  49.                 'description' => 'Kunde kann Punkteverfall ausführen.'
  50.             ]
  51.         ]);
  52.     }
  53. }