Skip to content

Commit f54491b

Browse files
committed
B2B-2257: availableStores GraphQl query has no cache identity
1 parent 1e35ddd commit f54491b

File tree

3 files changed

+472
-26
lines changed

3 files changed

+472
-26
lines changed

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

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,17 @@ class Group
2424
public function afterGetIdentities(\Magento\Store\Model\Group $subject, array $result): array
2525
{
2626
$storeIds = $subject->getStoreIds();
27-
foreach ($storeIds as $storeId) {
28-
$result[] = sprintf('%s_%s', ConfigIdentity::CACHE_TAG, $storeId);
29-
}
30-
$origWebsiteId = $subject->getOrigData('website_id');
31-
// An existing store group switches website
32-
if ($origWebsiteId != null && $origWebsiteId != $subject->getWebsiteId()) {
33-
$result[] = sprintf('%s_%s', ConfigIdentity::CACHE_TAG, 'website_' . $origWebsiteId);
34-
$result[] = sprintf(
35-
'%s_%s',
36-
ConfigIdentity::CACHE_TAG,
37-
'website_' . $origWebsiteId . 'group_' . $subject->getId()
38-
);
27+
if (count($storeIds) > 0) {
28+
foreach ($storeIds as $storeId) {
29+
$result[] = sprintf('%s_%s', ConfigIdentity::CACHE_TAG, $storeId);
30+
}
31+
$origWebsiteId = $subject->getOrigData('website_id');
32+
$websiteId = $subject->getWebsiteId();
33+
if ($origWebsiteId != $websiteId) { // Add or switch to a new website
34+
$result[] = sprintf('%s_%s', ConfigIdentity::CACHE_TAG, 'website_' . $websiteId);
35+
}
3936
}
37+
4038
return $result;
4139
}
4240
}

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

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,28 +24,16 @@ class Store
2424
public function afterGetIdentities(\Magento\Store\Model\Store $subject, array $result): array
2525
{
2626
$result[] = sprintf('%s_%s', ConfigIdentity::CACHE_TAG, $subject->getId());
27-
$origStoreGroupId = $subject->getOrigData('group_id');
28-
$origIsActive = $subject->getOrigData('is_active');
29-
// An existing active store switches store group
30-
if ($origIsActive && $this->isStoreGroupSwitched($subject)) {
31-
$origWebsiteId = $subject->getOrigData('website_id');
32-
$result[] = sprintf('%s_%s', ConfigIdentity::CACHE_TAG, 'website_' . $origWebsiteId);
33-
$result[] = sprintf(
34-
'%s_%s',
35-
ConfigIdentity::CACHE_TAG,
36-
'website_' . $origWebsiteId . 'group_' . $origStoreGroupId
37-
);
38-
}
3927

40-
// New active store or newly activated store or an active store switched store group
41-
$storeGroupId = $subject->getStoreGroupId();
4228
$isActive = $subject->getIsActive();
29+
// New active store or newly activated store or an active store switched store group
4330
if ($isActive
4431
&& ($subject->getOrigData('is_active') !== $isActive || $this->isStoreGroupSwitched($subject))
4532
) {
4633
$websiteId = $subject->getWebsiteId();
4734
if ($websiteId !== null) {
4835
$result[] = sprintf('%s_%s', ConfigIdentity::CACHE_TAG, 'website_' . $websiteId);
36+
$storeGroupId = $subject->getStoreGroupId();
4937
if ($storeGroupId !== null) {
5038
$result[] = sprintf(
5139
'%s_%s',

0 commit comments

Comments
 (0)