vendor/boldr/simple-price-provider/src/EventSubscriber/EaEventSubscriber.php line 27

Open in your IDE?
  1. <?php
  2. namespace Boldr\Shop\SimplePriceProviderBundle\EventSubscriber;
  3. use Symfony\Contracts\Cache\TagAwareCacheInterface;
  4. use Boldr\Shop\ShopBundle\Entity\Product;
  5. use EasyCorp\Bundle\EasyAdminBundle\Event\AfterEntityUpdatedEvent;
  6. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  7. class EaEventSubscriber implements EventSubscriberInterface
  8. {
  9. private TagAwareCacheInterface $cache;
  10. public static function getSubscribedEvents(): array
  11. {
  12. return [
  13. AfterEntityUpdatedEvent::class => ['onAfterEntityUpdated']
  14. ];
  15. }
  16. public function __construct(TagAwareCacheInterface $cache)
  17. {
  18. $this->cache = $cache;
  19. }
  20. public function onAfterEntityUpdated(AfterEntityUpdatedEvent $event)
  21. {
  22. $entityInstance = $event->getEntityInstance();
  23. if ($entityInstance instanceof Product)
  24. {
  25. // Invalidate product prices
  26. $tags = [
  27. 'boldr_simple_price_provider.product.'. $entityInstance->getId()
  28. ];
  29. // Invalidate product variant prices
  30. foreach ($entityInstance->getVariants() as $variant)
  31. {
  32. $tags[] = 'boldr_simple_price_provider.product_variant.'. $variant->getId();
  33. }
  34. $this->cache->invalidateTags($tags);
  35. }
  36. }
  37. }