custom/plugins/KlikensteenThemeCustomChanges/src/Subscriber/ProductSubscriber.php line 28

Open in your IDE?
  1. <?php
  2. namespace Klikensteen\ThemeCustomChanges\Subscriber;
  3. use Shopware\Core\Content\Product\ProductEvents;
  4. use Shopware\Core\Framework\Struct\ArrayStruct;
  5. use Shopware\Core\System\SalesChannel\Entity\SalesChannelEntityLoadedEvent;
  6. use Shopware\Core\System\SalesChannel\Entity\SalesChannelRepository;
  7. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  8. use Shopware\Storefront\Page\Product\ProductPageCriteriaEvent;
  9. use Shopware\Core\Content\Product\Events\ProductListingCriteriaEvent;
  10. use Symfony\Component\HttpFoundation\RequestStack;
  11. use Shopware\Core\Content\Product\SalesChannel\Detail\ProductConfiguratorLoader;
  12. use Symfony\Component\DependencyInjection\ContainerInterface;
  13. /**
  14.  * Class AllVariantDetailPage
  15.  *
  16.  * Used to collect the information of the variants
  17.  */
  18. class ProductSubscriber implements EventSubscriberInterface
  19. {
  20.     /**
  21.      * @var ContainerInterface
  22.      */
  23.     protected $container;
  24.     protected $configuratorLoader;
  25.     public function __construct(
  26.         ContainerInterface $container,
  27.         RequestStack $requestStack,
  28.         ProductConfiguratorLoader $configuratorLoader
  29.     )
  30.     {
  31.         $this->container $container;
  32.         $this->currentRequestAttributes $requestStack->getCurrentRequest()->attributes;
  33.         $this->configuratorLoader $configuratorLoader;
  34.     }
  35.     /**
  36.      * @return string[]
  37.      */
  38.     public static function getSubscribedEvents(): array
  39.     {
  40.         return [
  41.             'sales_channel.' ProductEvents::PRODUCT_LOADED_EVENT => 'onProductsLoadedEvents'
  42.            ];
  43.     }
  44.     public function onProductsLoadedEvents(SalesChannelEntityLoadedEvent $event)
  45.     {
  46.         $salesChannelContext  $event->getSalesChannelContext();
  47.         if ($salesChannelContext) {
  48.             foreach ($event->getEntities() as $productEntity) {
  49.                 $parentId $productEntity->getParentId();
  50.                 if($parentId){
  51.                     $productEntity->addExtension('kilkHasParent', new ArrayStruct(['value' => ]));
  52.                 }
  53.             }
  54.         }
  55.     } 
  56. }