src/Juki/Bundle/AppBundle/EventListener/ProductEventListener.php line 58

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace Juki\Bundle\AppBundle\EventListener;
  4. use Doctrine\ORM\EntityManagerInterface;
  5. use Doctrine\ORM\Event\LifecycleEventArgs;
  6. use Hitso\Bundle\CatalogBundle\Entity\Product;
  7. use Hitso\Bundle\CatalogBundle\Service\Product\ProductAttributes;
  8. use Hitso\Bundle\CommonBundle\Doctrine\Manager\ManagerCollection;
  9. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  10. /**
  11.  * Class ProductEventListener
  12.  *
  13.  * @package Juki\Bundle\AppBundle\Event
  14.  */
  15. class ProductEventListener implements EventSubscriberInterface
  16. {
  17.     /**
  18.      * @var EntityManagerInterface
  19.      */
  20.     protected $entityManager;
  21.     /**
  22.      * @var ManagerCollection
  23.      */
  24.     protected $managerCollection;
  25.     /**
  26.      * ProductEventListener constructor.
  27.      *
  28.      * @param EntityManagerInterface $entityManager
  29.      * @param ManagerCollection      $managerCollection
  30.      */
  31.     public function __construct(
  32.         EntityManagerInterface $entityManager,
  33.         ManagerCollection $managerCollection
  34.     ) {
  35.         $this->entityManager     $entityManager;
  36.         $this->managerCollection $managerCollection;
  37.     }
  38.     /**
  39.      * @return array
  40.      */
  41.     public static function getSubscribedEvents(): array
  42.     {
  43.         return [
  44.             'preUpdate',
  45.         ];
  46.     }
  47.     /**
  48.      * @param LifecycleEventArgs $eventArgs
  49.      */
  50.     public function preUpdate(LifecycleEventArgs $eventArgs): void
  51.     {
  52. //        if (method_exists($eventArgs, 'getEntity')) {
  53. //            $product = $eventArgs->getEntity();
  54. //            if ($product instanceof Product) {
  55. //                $productAttributes = $product->getAttributes();
  56. //
  57. //                foreach ($productAttributes as $productAttribute) {
  58. //                    if ($productAttribute->getAttribute()->getAttributeGroup()->getCategory() !== $product->getCategory()) {
  59. //                        $this->entityManager->remove($productAttribute);
  60. //                    }
  61. //                }
  62. //                $this->entityManager->flush();
  63. //            }
  64. //        }
  65.     }
  66. }