custom/plugins/AbasBecoCustomizations/src/Subscribers/Page/PageSubscriber.php line 36

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace AbasBecoCustomizations\Subscribers\Page;
  3. use Shopware\Core\Checkout\Customer\Event\CustomerRegisterEvent;
  4. use Shopware\Core\Framework\DataAbstractionLayer\EntityRepository;
  5. use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
  6. use Shopware\Core\Framework\Uuid\Uuid;
  7. use Shopware\Storefront\Page\PageLoadedEvent;
  8. use Shopware\Storefront\Page\Product\ProductPageCriteriaEvent;
  9. use Shopware\Storefront\Page\Product\ProductPageLoadedEvent;
  10. use Shopware\Storefront\Pagelet\Footer\FooterPageletLoadedEvent;
  11. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  12. use Symfony\Component\HttpKernel\Event\RequestEvent;
  13. class PageSubscriber implements EventSubscriberInterface
  14. {
  15.     private EntityRepository $customerGroupRepository;
  16.     public function __construct(EntityRepository $customerGroupRepository)
  17.     {
  18.         $this->customerGroupRepository $customerGroupRepository;
  19.     }
  20.     public static function getSubscribedEvents()
  21.     {
  22.         return [
  23.             PageLoadedEvent::class => 'handlePageLoadedEvent',
  24.             ProductPageLoadedEvent::class => 'handlePageLoadedEvent',
  25.             ProductPageCriteriaEvent::class => 'handleProductPageCriteriaEvent'
  26.         ];
  27.     }
  28.     public function handlePageLoadedEvent(PageLoadedEvent $event)
  29.     {
  30.         $context $event->getSalesChannelContext();
  31.         $customer $context->getCustomer();
  32.         if (!is_null($customer)) {
  33.             $customerGroup $this->customerGroupRepository->search((new Criteria([$customer->getGroupId()])), $event->getContext())->first();
  34.             $customer->setGroup($customerGroup);
  35.         }
  36.     }
  37.     public function handleProductPageCriteriaEvent(ProductPageCriteriaEvent $event)
  38.     {
  39.         $event->getCriteria()->addAssociation('abasSupplier.country');
  40.         $event->getCriteria()->addAssociation('abasSupplier.countryState');
  41.         $event->getCriteria()->addAssociation('abasSupplierContact.salutation');
  42.         $event->getCriteria()->addAssociation('abasSupplierContact.country');
  43.         $event->getCriteria()->addAssociation('abasSupplierContact.countryState');
  44.     }
  45. }