custom/plugins/Confi/src/Subscriber/ProductSubscriber.php line 20

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Su\Confi\Subscriber;
  3. use Shopware\Core\Content\Product\ProductEntity;
  4. use Shopware\Core\Framework\Struct\ArrayEntity;
  5. use Shopware\Core\Framework\DataAbstractionLayer\Event\EntityLoadedEvent;
  6. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  7. use Shopware\Core\Content\Product\ProductEvents;
  8. class ProductSubscriber implements EventSubscriberInterface
  9. {
  10.     public static function getSubscribedEvents(): array
  11.     {
  12.         return [
  13.             ProductEvents::PRODUCT_LOADED_EVENT => 'onProductsLoaded'
  14.         ];
  15.     }
  16.     public function onProductsLoaded(EntityLoadedEvent $event): void
  17.     {
  18.         /** @var ProductEntity $productEntity */
  19.         foreach ($event->getEntities() as $productEntity) {
  20.             $productEntity->addExtension('confi_id', new ArrayEntity(['foo' => 'bar']));
  21.         }
  22.     }
  23. }