Skip to content

Commit 9a83d26

Browse files
committed
B2B-2256: "countries" and "country" GraphQl query has no cache identity
1 parent 4c07348 commit 9a83d26

File tree

2 files changed

+15
-29
lines changed

2 files changed

+15
-29
lines changed

app/code/Magento/DirectoryGraphQl/Model/Cache/Tag/Strategy/CountryConfig.php renamed to app/code/Magento/DirectoryGraphQl/Model/Cache/Tag/Strategy/Config/CountryTagGenerator.php

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,18 @@
55
*/
66
declare(strict_types=1);
77

8-
namespace Magento\DirectoryGraphQl\Model\Cache\Tag\Strategy;
8+
namespace Magento\DirectoryGraphQl\Model\Cache\Tag\Strategy\Config;
99

1010
use Magento\DirectoryGraphQl\Model\Resolver\Country\Identity;
11-
use Magento\Framework\App\Cache\Tag\StrategyInterface;
1211
use Magento\Framework\App\Config\ValueInterface;
1312
use Magento\Store\Model\ScopeInterface;
1413
use Magento\Store\Model\StoreManagerInterface;
14+
use Magento\Store\Model\Config\Cache\Tag\Strategy\TagGeneratorInterface;
1515

1616
/**
17-
* Produce cache tags for country config.
17+
* Generator that generates cache tags for country configuration
1818
*/
19-
class CountryConfig implements StrategyInterface
19+
class CountryTagGenerator implements TagGeneratorInterface
2020
{
2121
/**
2222
* @var string[]
@@ -43,31 +43,23 @@ public function __construct(
4343
/**
4444
* @inheritdoc
4545
*/
46-
public function getTags($object): array
46+
public function generateTags(ValueInterface $config): array
4747
{
48-
if (!is_object($object)) {
49-
throw new \InvalidArgumentException('Provided argument is not an object');
50-
}
51-
52-
if ($object instanceof ValueInterface
53-
&& in_array($object->getPath(), $this->countryConfigPaths)
54-
&& $object->isValueChanged()
55-
) {
56-
if ($object->getScope() == ScopeInterface::SCOPE_WEBSITES) {
57-
$website = $this->storeManager->getWebsite($object->getScopeId());
48+
if (in_array($config->getPath(), $this->countryConfigPaths)) {
49+
if ($config->getScope() == ScopeInterface::SCOPE_WEBSITES) {
50+
$website = $this->storeManager->getWebsite($config->getScopeId());
5851
$storeIds = $website->getStoreIds();
59-
} elseif ($object->getScope() == ScopeInterface::SCOPE_STORES) {
60-
$storeIds = [$object->getScopeId()];
52+
} elseif ($config->getScope() == ScopeInterface::SCOPE_STORES) {
53+
$storeIds = [$config->getScopeId()];
6154
} else {
6255
$storeIds = array_keys($this->storeManager->getStores());
6356
}
64-
$ids = [];
57+
$tags = [];
6558
foreach ($storeIds as $storeId) {
66-
$ids[] = sprintf('%s_%s', Identity::CACHE_TAG, $storeId);
59+
$tags[] = sprintf('%s_%s', Identity::CACHE_TAG, $storeId);
6760
}
68-
return $ids;
61+
return $tags;
6962
}
70-
7163
return [];
7264
}
7365
}

app/code/Magento/DirectoryGraphQl/etc/di.xml

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,8 @@
1212
<item name="currency_tag_generator" xsi:type="object">
1313
Magento\DirectoryGraphQl\Model\Cache\Tag\Strategy\Config\CurrencyTagGenerator
1414
</item>
15-
</argument>
16-
</arguments>
17-
</type>
18-
<type name="Magento\Framework\App\Cache\Tag\Strategy\Factory">
19-
<arguments>
20-
<argument name="customStrategies" xsi:type="array">
21-
<item name="Magento\Framework\App\Config\ValueInterface" xsi:type="object">
22-
Magento\DirectoryGraphQl\Model\Cache\Tag\Strategy\CountryConfig
15+
<item name="country_tag_generator" xsi:type="object">
16+
Magento\DirectoryGraphQl\Model\Cache\Tag\Strategy\Config\CountryTagGenerator
2317
</item>
2418
</argument>
2519
</arguments>

0 commit comments

Comments
 (0)