Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

UpdateProductfamilyAfterFlushEventSubscriber.php 1.8KB

3 år sedan
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. }