|
7 | 7 |
|
8 | 8 | namespace Magento\StoreGraphQl\Model\Resolver\Stores;
|
9 | 9 |
|
| 10 | +use Magento\Framework\Exception\NoSuchEntityException; |
10 | 11 | use Magento\Framework\GraphQl\Query\Resolver\IdentityInterface;
|
| 12 | +use Magento\Store\Model\StoreManagerInterface; |
11 | 13 | use Magento\StoreGraphQl\Model\Resolver\Store\ConfigIdentity as StoreConfigIdentity;
|
12 | 14 |
|
13 | 15 | class ConfigIdentity implements IdentityInterface
|
14 | 16 | {
|
| 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 | + |
15 | 30 | /**
|
16 | 31 | * @inheritDoc
|
17 | 32 | */
|
18 | 33 | public function getIdentities(array $resolvedData): array
|
19 | 34 | {
|
20 | 35 | $ids = [];
|
| 36 | + $storeGroups = []; |
| 37 | + $store = null; |
21 | 38 | foreach ($resolvedData as $storeConfig) {
|
22 | 39 | $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 | + ); |
23 | 61 | }
|
24 | 62 |
|
25 | 63 | return empty($ids) ? [] : array_merge([StoreConfigIdentity::CACHE_TAG], $ids);
|
|
0 commit comments