-
Notifications
You must be signed in to change notification settings - Fork 1
/
SwagHidePrices.php
60 lines (48 loc) · 1.6 KB
/
SwagHidePrices.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php
/**
* (c) shopware AG <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace SwagHidePrices;
use Shopware\Components\Plugin;
use Shopware\Components\Plugin\Context\ActivateContext;
use Shopware\Components\Plugin\Context\InstallContext;
class SwagHidePrices extends Plugin
{
public const NO_CACHE_CONTROLLERS_KEY = 'noCacheControllers';
public const DO_NOT_CACHE_PRICE_TAG = 'frontend/detail price';
public function install(InstallContext $context): void
{
$this->installNoCacheTag();
}
public function activate(ActivateContext $context): void
{
$context->scheduleClearCache(ActivateContext::CACHE_LIST_DEFAULT);
}
private function installNoCacheTag(): void
{
$configWriter = $this->container->get('config_writer');
$configValue = $configWriter->get(self::NO_CACHE_CONTROLLERS_KEY);
$configValueArray = \explode(\PHP_EOL, $configValue);
if ($this->hasTag($configValueArray)) {
return;
}
$configValueArray[] = self::DO_NOT_CACHE_PRICE_TAG;
$configValue = \implode(\PHP_EOL, $configValueArray);
$configWriter->save(self::NO_CACHE_CONTROLLERS_KEY, $configValue);
}
/**
* @param string[] $configValueArray
*/
private function hasTag(array $configValueArray): bool
{
foreach ($configValueArray as $value) {
if ($value === self::DO_NOT_CACHE_PRICE_TAG) {
return true;
}
}
return false;
}
}