<?php
declare(strict_types=1);
namespace Acris\Promotion\Subscriber;
use Shopware\Core\Framework\Adapter\Cache\CacheInvalidator;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class ClearCache implements EventSubscriberInterface
{
private const PRODUCT_CACHE_TAG = 'config.core.listing.hideCloseoutProductsWhenOutOfStock';
/**
* @var CacheInvalidator
*/
private $cacheInvalidator;
public function __construct(CacheInvalidator $cacheInvalidator)
{
$this->cacheInvalidator = $cacheInvalidator;
}
public static function getSubscribedEvents(): array
{
return [
'promotion.written' => 'clearCache',
'promotion_discount.written' => 'clearCache'
];
}
public function clearCache()
{
$this->cacheInvalidator->invalidate([self::PRODUCT_CACHE_TAG]);
}
}