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

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 Shopware\Storefront\Page\Account\Overview\AccountOverviewPage;
  9. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  10. class AccountPageSubscriber implements EventSubscriberInterface
  11. {
  12.     private MasterdataService $masterdataService;
  13.     private AccountsCalculationService $accountsCalculationService;
  14.     public function __construct(MasterdataService $masterdataServiceAccountsCalculationService $accountsCalculationService)
  15.     {
  16.         $this->masterdataService $masterdataService;
  17.         $this->accountsCalculationService $accountsCalculationService;
  18.     }
  19.     public static function getSubscribedEvents()
  20.     {
  21.         return [
  22.             StorefrontRenderEvent::class => 'onStorefrontRenderEvent',
  23.             CustomerAclRolesEvent::class => 'onCustomerAclRolesEvent'
  24.         ];
  25.     }
  26.     public function onStorefrontRenderEvent(StorefrontRenderEvent $event)
  27.     {
  28.         $customer $event->getSalesChannelContext()->getCustomer();
  29.         if ($customer) {
  30.             if (key_exists('page'$event->getParameters()) && $event->getParameters()['page'] instanceof AccountOverviewPage) {
  31.                 if ($this->masterdataService->getMasterdatasForCustomer($customer) instanceof EntitySearchResult) {
  32.                     $event->setParameter('masterdata'$this->masterdataService->getMasterdatasForCustomer($customertrue)->first());
  33.                 }
  34.                 $event->setParameter('childBudgets'$this->accountsCalculationService->getChildBudgets());
  35.                 $event->setParameter('totalAccountAmount'$this->accountsCalculationService->calculateTotalAccount($event->getContext()));
  36.                 $event->setParameter('statusAccountAmount'$this->accountsCalculationService->calculateStatusAccountIncludingChildBudgets($event->getContext()));
  37.                 $event->setParameter('useableAccountAmount'$this->accountsCalculationService->calculateUsableAccount($event->getSalesChannelContext()->getContext(), $event->getSalesChannelContext()->getCustomer()));
  38.             }
  39.         }
  40.     }
  41.     public function onCustomerAclRolesEvent(CustomerAclRolesEvent $event)
  42.     {
  43.         // add all in this plugin used customer acl roles
  44.         $event->addRoles([
  45.             [
  46.                 'title' => 'BUDGET_EXPIRE_CALCULATE',
  47.                 'description' => 'Kunde kann Punkte die aktuell in einem ausgewählten Zeitraum verfallen würden ermitteln und ausgeben lassen.'
  48.             ],
  49.             [
  50.                 'title' => 'BUDGET_EXPIRE_EXECUTE_CALCULATED',
  51.                 'description' => 'Kunde kann Punkteverfall ausführen.'
  52.             ]
  53.         ]);
  54.     }
  55. }