Skip to content

Commit 5f69b0a

Browse files
committed
B2B-2257: availableStores GraphQl query has no cache identity
1 parent afd72c6 commit 5f69b0a

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,16 @@ public function afterGetIdentities(\Magento\Store\Model\Group $subject, array $r
2727
foreach ($storeIds as $storeId) {
2828
$result[] = sprintf('%s_%s', ConfigIdentity::CACHE_TAG, $storeId);
2929
}
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+
);
39+
}
3040
return $result;
3141
}
3242
}

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

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,29 @@ 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-
if ($subject->getOrigData('is_active') !== $subject->getIsActive() && $subject->getIsActive()) {
27+
$origStoreGroupId = $subject->getOrigData('group_id');
28+
$origIsActive = $subject->getOrigData('is_active');
29+
// An existing active store switches store group
30+
if ($origIsActive && $origStoreGroupId != null && $origStoreGroupId != $subject->getStoreGroupId()) {
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+
}
39+
// New active store or newly activated store or an active store switched store group
40+
$storeGroupId = $subject->getStoreGroupId();
41+
$isActive = $subject->getIsActive();
42+
if ($isActive && (
43+
$subject->getOrigData('is_active') !== $isActive
44+
|| ($origStoreGroupId != null && $origStoreGroupId != $storeGroupId)
45+
)
46+
) {
2847
$websiteId = $subject->getWebsiteId();
2948
if ($websiteId !== null) {
3049
$result[] = sprintf('%s_%s', ConfigIdentity::CACHE_TAG, 'website_' . $websiteId);
31-
$storeGroupId = $subject->getStoreGroupId();
3250
if ($storeGroupId !== null) {
3351
$result[] = sprintf(
3452
'%s_%s',
@@ -37,7 +55,6 @@ public function afterGetIdentities(\Magento\Store\Model\Store $subject, array $r
3755
);
3856
}
3957
}
40-
4158
}
4259

4360
return $result;

0 commit comments

Comments
 (0)