custom/plugins/SwagCommercial/src/CustomPricing/Subscriber/CacheKeyEventSubscriber.php line 40

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Shopware\Commercial\CustomPricing\Subscriber;
  3. use Shopware\Commercial\CustomPricing\Domain\CustomPriceExistenceHelper;
  4. use Shopware\Commercial\Licensing\License;
  5. use Shopware\Core\Content\Category\Event\CategoryRouteCacheKeyEvent;
  6. use Shopware\Core\Content\Product\Events\ProductDetailRouteCacheKeyEvent;
  7. use Shopware\Core\Content\Product\Events\ProductListingRouteCacheKeyEvent;
  8. use Shopware\Core\Content\Product\Events\ProductSuggestRouteCacheKeyEvent;
  9. use Shopware\Core\Framework\Adapter\Cache\StoreApiRouteCacheKeyEvent;
  10. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  11. /**
  12.  * @internal
  13.  */
  14. class CacheKeyEventSubscriber implements EventSubscriberInterface
  15. {
  16.     private CustomPriceExistenceHelper $customPrice;
  17.     /**
  18.      * @internal
  19.      */
  20.     public function __construct(
  21.         CustomPriceExistenceHelper $customPrice
  22.     ) {
  23.         $this->customPrice $customPrice;
  24.     }
  25.     public static function getSubscribedEvents(): array
  26.     {
  27.         return [
  28.             CategoryRouteCacheKeyEvent::class => ['disableCache'100],
  29.             ProductDetailRouteCacheKeyEvent::class => ['disableCache'100],
  30.             ProductSuggestRouteCacheKeyEvent::class => ['disableCache'100],
  31.             ProductListingRouteCacheKeyEvent::class => ['disableCache'100],
  32.         ];
  33.     }
  34.     public function disableCache(StoreApiRouteCacheKeyEvent $event): void
  35.     {
  36.         if (!License::get('CUSTOM_PRICES-2356553')) {
  37.             return;
  38.         }
  39.         if (($customer $event->getContext()->getCustomer()) !== null && $this->customPrice->existsForCustomPrice($customer)) {
  40.             $event->disableCaching();
  41.         }
  42.     }
  43. }