<?php
declare(strict_types=1);
namespace Juki\Bundle\AppBundle\EventListener;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Event\LifecycleEventArgs;
use Hitso\Bundle\CatalogBundle\Entity\Product;
use Hitso\Bundle\CatalogBundle\Service\Product\ProductAttributes;
use Hitso\Bundle\CommonBundle\Doctrine\Manager\ManagerCollection;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
/**
* Class ProductEventListener
*
* @package Juki\Bundle\AppBundle\Event
*/
class ProductEventListener implements EventSubscriberInterface
{
/**
* @var EntityManagerInterface
*/
protected $entityManager;
/**
* @var ManagerCollection
*/
protected $managerCollection;
/**
* ProductEventListener constructor.
*
* @param EntityManagerInterface $entityManager
* @param ManagerCollection $managerCollection
*/
public function __construct(
EntityManagerInterface $entityManager,
ManagerCollection $managerCollection
) {
$this->entityManager = $entityManager;
$this->managerCollection = $managerCollection;
}
/**
* @return array
*/
public static function getSubscribedEvents(): array
{
return [
'preUpdate',
];
}
/**
* @param LifecycleEventArgs $eventArgs
*/
public function preUpdate(LifecycleEventArgs $eventArgs): void
{
// if (method_exists($eventArgs, 'getEntity')) {
// $product = $eventArgs->getEntity();
// if ($product instanceof Product) {
// $productAttributes = $product->getAttributes();
//
// foreach ($productAttributes as $productAttribute) {
// if ($productAttribute->getAttribute()->getAttributeGroup()->getCategory() !== $product->getCategory()) {
// $this->entityManager->remove($productAttribute);
// }
// }
// $this->entityManager->flush();
// }
// }
}
}