custom/plugins/AcrisProductDownloadsCS/src/Storefront/Subscriber/ProductPageSubscriber.php line 28

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Acris\ProductDownloads\Storefront\Subscriber;
  3. use Acris\ProductDownloads\Components\ProductDownloadService;
  4. use Acris\ProductDownloads\Custom\ProductDownloadCollection;
  5. use Shopware\Storefront\Page\Product\ProductPageCriteriaEvent;
  6. use Shopware\Storefront\Page\Product\ProductPageLoadedEvent;
  7. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  8. class ProductPageSubscriber implements EventSubscriberInterface
  9. {
  10.     private ProductDownloadService $productDownloadService;
  11.     public function __construct(ProductDownloadService $productDownloadService)
  12.     {
  13.         $this->productDownloadService $productDownloadService;
  14.     }
  15.     public static function getSubscribedEvents(): array
  16.     {
  17.         return [
  18.             ProductPageCriteriaEvent::class => 'onProductPageCriteriaLoaded',
  19.             ProductPageLoadedEvent::class => 'onProductPageLoaded'
  20.         ];
  21.     }
  22.     public function onProductPageCriteriaLoaded(ProductPageCriteriaEvent $event): void
  23.     {
  24.         $this->productDownloadService->addProductAssociationCriteria($event->getCriteria());
  25.         $this->productDownloadService->addProductLinkAssociationCriteria($event->getCriteria());
  26.     }
  27.     public function onProductPageLoaded(ProductPageLoadedEvent $event):void
  28.     {
  29.         $languageId $event->getContext()->getLanguageId();
  30.         if($event->getPage() && $event->getPage()->getProduct()) {
  31.             $this->productDownloadService->checkLanguageForProduct($event->getPage()->getProduct(), $languageId$event->getSalesChannelContext());
  32.             $this->productDownloadService->checkLanguageForProductLinks($event->getPage()->getProduct(), $languageId$event->getSalesChannelContext());
  33.         }
  34.     }
  35. }