Skip to content

Commit 207c170

Browse files
committed
B2B-2257: availableStores GraphQl query has no cache identity
1 parent ab794e4 commit 207c170

File tree

3 files changed

+686
-1
lines changed

3 files changed

+686
-1
lines changed

app/code/Magento/StoreGraphQl/Model/Resolver/Stores/ConfigIdentity.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,57 @@
77

88
namespace Magento\StoreGraphQl\Model\Resolver\Stores;
99

10+
use Magento\Framework\Exception\NoSuchEntityException;
1011
use Magento\Framework\GraphQl\Query\Resolver\IdentityInterface;
12+
use Magento\Store\Model\StoreManagerInterface;
1113
use Magento\StoreGraphQl\Model\Resolver\Store\ConfigIdentity as StoreConfigIdentity;
1214

1315
class ConfigIdentity implements IdentityInterface
1416
{
17+
/**
18+
* @var StoreManagerInterface
19+
*/
20+
private $storeManager;
21+
22+
/**
23+
* @param StoreManagerInterface $storeManager
24+
*/
25+
public function __construct(StoreManagerInterface $storeManager)
26+
{
27+
$this->storeManager = $storeManager;
28+
}
29+
1530
/**
1631
* @inheritDoc
1732
*/
1833
public function getIdentities(array $resolvedData): array
1934
{
2035
$ids = [];
36+
$storeGroups = [];
37+
$store = null;
2138
foreach ($resolvedData as $storeConfig) {
2239
$ids[] = sprintf('%s_%s', StoreConfigIdentity::CACHE_TAG, $storeConfig['id']);
40+
try {
41+
// Record store groups
42+
$store = $this->storeManager->getStore($storeConfig['id']);
43+
$storeGroupId = $store->getStoreGroupId();
44+
if ($storeGroupId !== null) {
45+
$storeGroups[$storeGroupId] = true;
46+
}
47+
} catch (NoSuchEntityException $e) {
48+
// Do nothing
49+
;
50+
}
51+
}
52+
$storeGroupCount = count($storeGroups);
53+
if ($storeGroupCount > 1 && $store !== null) {
54+
$ids[] = sprintf('%s_%s', StoreConfigIdentity::CACHE_TAG, 'website_' . $store->getWebsiteId());
55+
} elseif ($storeGroupCount == 1 && $store !== null) {
56+
$ids[] = sprintf(
57+
'%s_%s',
58+
StoreConfigIdentity::CACHE_TAG,
59+
'website_' . $store->getWebsiteId() . 'group_' . array_keys($storeGroups)[0]
60+
);
2361
}
2462

2563
return empty($ids) ? [] : array_merge([StoreConfigIdentity::CACHE_TAG], $ids);

app/code/Magento/StoreGraphQl/Plugin/Store.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,23 @@ class Store
2323
*/
2424
public function afterGetIdentities(\Magento\Store\Model\Store $subject, array $result): array
2525
{
26-
return array_merge($result, [sprintf('%s_%s', ConfigIdentity::CACHE_TAG, $subject->getId())]);
26+
$result[] = sprintf('%s_%s', ConfigIdentity::CACHE_TAG, $subject->getId());
27+
if ($subject->isObjectNew()) {
28+
$websiteId = $subject->getWebsiteId();
29+
if ($websiteId !== null) {
30+
$result[] = sprintf('%s_%s', ConfigIdentity::CACHE_TAG, 'website_' . $websiteId);
31+
$storeGroupId = $subject->getStoreGroupId();
32+
if ($storeGroupId !== null) {
33+
$result[] = sprintf(
34+
'%s_%s',
35+
ConfigIdentity::CACHE_TAG,
36+
'website_' . $websiteId . 'group_' . $storeGroupId
37+
);
38+
}
39+
}
40+
41+
}
42+
43+
return $result;
2744
}
2845
}

0 commit comments

Comments
 (0)