Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

UpdateProductfamilyAfterFlushEventSubscriber.php 1.8KB

3 anos atrás
12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. }