You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 satır
1.8KB

  1. <?php
  2. namespace Lc\CaracoleBundle\EventSubscriber\Product;
  3. use Doctrine\ORM\EntityManagerInterface;
  4. use EasyCorp\Bundle\EasyAdminBundle\Event\AfterEntityUpdatedEvent;
  5. use Lc\CaracoleBundle\Builder\Order\OrderShopBuilder;
  6. use Lc\CaracoleBundle\Container\Product\ProductContainer;
  7. use Lc\CaracoleBundle\Container\Product\ProductFamilyContainer;
  8. use Lc\CaracoleBundle\Model\Product\ProductFamilyInterface;
  9. use Lc\CaracoleBundle\Model\Product\ProductInterface;
  10. use Lc\CaracoleBundle\Model\Reduction\ReductionCatalogInterface;
  11. use Lc\SovBundle\Event\EntityManager\EntityManagerEvent;
  12. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  13. class UpdateProductfamilyAfterFlushEventSubscriber implements EventSubscriberInterface
  14. {
  15. protected EntityManagerInterface $em;
  16. protected ProductFamilyContainer $productFamilyContainer;
  17. protected ProductContainer $productContainer;
  18. protected OrderShopBuilder $orderShopBuilder;
  19. public function __construct(EntityManagerInterface $entityManager, ProductFamilyContainer $productFamilyContainer, ProductContainer $productContainer, OrderShopBuilder $orderShopBuilder)
  20. {
  21. $this->em = $entityManager;
  22. $this->productFamilyContainer = $productFamilyContainer;
  23. $this->productContainer = $productContainer;
  24. $this->orderShopBuilder = $orderShopBuilder;
  25. }
  26. public static function getSubscribedEvents()
  27. {
  28. return [
  29. AfterEntityUpdatedEvent::class => ['processAfterFlushProductFamily'],
  30. ];
  31. }
  32. public function processAfterFlushProductFamily(AfterEntityUpdatedEvent $event)
  33. {
  34. $entity = $event->getEntityInstance();
  35. if ($entity instanceof ProductFamilyInterface) {
  36. $this->orderShopBuilder->updatePriceByProductFamily($entity);
  37. }
  38. }
  39. }