<?php declare(strict_types=1);
namespace EmovaProductPlugin\Subscriber;
use Shopware\Core\Framework\DataAbstractionLayer\Event\EntityLoadedEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Shopware\Core\Content\Product\ProductEvents;
use Shopware\Core\Framework\Adapter\Monolog\ShopwareLogger;
use Psr\Log\LoggerInterface;
class EmovaProductSubscriber implements EventSubscriberInterface
{
/**
* @var ShopwareLogger
*/
private LoggerInterface $logger;
public function __construct(
LoggerInterface $logger
) {
$this->logger = $logger;
$this->logger->warning('EmovaProductPlugin: constructor was called.');
}
public static function getSubscribedEvents(): array
{
// Return the events to listen to as array like this: <event to listen to> => <method to execute>
return [
ProductEvents::PRODUCT_LOADED_EVENT => 'onProductsLoaded'
];
}
public function onProductsLoaded(EntityLoadedEvent $event)
{
// Do something
// E.g. work with the loaded entities: $event->getEntities()
$this->logger->warning('EmovaProductPlugin: onProdLoaded was called.');
}
}