custom/plugins/WabsDigitalProductsExtended/src/Subscriber/ProductPageLoaded.php line 20

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace WabsDigitalProductsExtended\Subscriber;
  3. use Shopware\Core\Framework\Struct\ArrayStruct;
  4. use Shopware\Storefront\Page\PageLoadedEvent;
  5. use Shopware\Storefront\Page\Product\ProductPage;
  6. use Shopware\Storefront\Page\Product\ProductPageLoadedEvent;
  7. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  8. class ProductPageLoaded implements EventSubscriberInterface
  9. {
  10.     public static function getSubscribedEvents(): array
  11.     {
  12.         return [
  13.             ProductPageLoadedEvent::class => 'onProductPageLoaded'
  14.         ];
  15.     }
  16.     public function onProductPageLoaded(PageLoadedEvent $event)
  17.     {
  18.         /** @var ProductPage $page */
  19.         $page $event->getPage();
  20.         $product $page->getProduct();
  21.         $customFields $product->getCustomFields();
  22.         $showDownloads true;
  23.         if (isset($customFields['igm_mbs_digital_content_access'])
  24.             && count($customFields['igm_mbs_digital_content_access']) > 0) {
  25.             $currentCustomerGroup $event->getSalesChannelContext()->getCurrentCustomerGroup()->getName();
  26.             if (!in_array($currentCustomerGroup$customFields['igm_mbs_digital_content_access'])) {
  27.                 $showDownloads false;
  28.             }
  29.         }
  30.         $page->addExtension('digitalProductsExtended', new ArrayStruct(['showProductDownloads' => $showDownloads]));
  31.     }
  32. }