custom/plugins/CioPointsFlow/src/Subscriber/HomepageNoCacheSubscriber.php line 30

Open in your IDE?
  1. <?php
  2. namespace CioPointsFlow\Subscriber;
  3. use CioBudget\Service\SessionService;
  4. use Shopware\Core\Content\Category\Event\CategoryRouteCacheKeyEvent;
  5. use Shopware\Core\Framework\DataAbstractionLayer\EntityRepositoryInterface;
  6. use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
  7. use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\ContainsFilter;
  8. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  9. class HomepageNoCacheSubscriber implements EventSubscriberInterface
  10. {
  11.     private EntityRepositoryInterface $categoryEntityRepository;
  12.     private SessionService $sessionService;
  13.     public function __construct(EntityRepositoryInterface $categoryEntityRepositorySessionService $sessionService)
  14.     {
  15.         $this->categoryEntityRepository $categoryEntityRepository;
  16.         $this->sessionService $sessionService;
  17.     }
  18.     public static function getSubscribedEvents()
  19.     {
  20.         return [
  21.             CategoryRouteCacheKeyEvent::class => 'onCategoryRouteCacheKeyEvent'
  22.         ];
  23.     }
  24.     public function onCategoryRouteCacheKeyEvent(CategoryRouteCacheKeyEvent $event)
  25.     {
  26.         $homeCategories $this->categoryEntityRepository->search((new Criteria())->addFilter(new ContainsFilter('name''Home')), $event->getContext()->getContext())->getIds();
  27.         if (in_array($event->getNavigationId(), $homeCategories)) {
  28.             if ($currentBudgetId $this->sessionService->getCurrentBudgetId()) {
  29.                 $event->addPart($currentBudgetId);
  30.             }
  31.         }
  32.     }
  33. }