Skip to content

Commit 9b48cb6

Browse files
committed
B2B-2257: availableStores GraphQl query has no cache identity
1 parent 2699e65 commit 9b48cb6

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

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

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,30 +33,33 @@ public function __construct(StoreManagerInterface $storeManager)
3333
public function getIdentities(array $resolvedData): array
3434
{
3535
$ids = [];
36-
$storeGroups = [];
36+
$storeGroupIds = [];
3737
$store = null;
38+
$storeGroupCount = 0;
3839
foreach ($resolvedData as $storeConfig) {
3940
$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;
41+
if ($storeGroupCount < 2) {
42+
try {
43+
// Record store groups
44+
$store = $this->storeManager->getStore($storeConfig['id']);
45+
$storeGroupId = $store->getStoreGroupId();
46+
if ($storeGroupId !== null && !in_array($storeGroupId, $storeGroupIds)) {
47+
$storeGroupIds[] = $storeGroupId;
48+
$storeGroupCount ++;
49+
}
50+
} catch (NoSuchEntityException $e) {
51+
// Do nothing
52+
;
4653
}
47-
} catch (NoSuchEntityException $e) {
48-
// Do nothing
49-
;
5054
}
5155
}
52-
$storeGroupCount = count($storeGroups);
5356
if ($storeGroupCount > 1) { // the resolved stores for any store groups in a website
5457
$ids[] = sprintf('%s_%s', StoreConfigIdentity::CACHE_TAG, 'website_' . $store->getWebsiteId());
5558
} elseif ($storeGroupCount == 1) { // the resolved stores for a particular store group in a website
5659
$ids[] = sprintf(
5760
'%s_%s',
5861
StoreConfigIdentity::CACHE_TAG,
59-
'website_' . $store->getWebsiteId() . 'group_' . array_keys($storeGroups)[0]
62+
'website_' . $store->getWebsiteId() . 'group_' . $storeGroupIds[0]
6063
);
6164
}
6265

0 commit comments

Comments
 (0)