Skip to content

Commit 7079ff5

Browse files
committed
MC-29135: [Forwardport] Throw GraphQL input exception when provided store is not enabled
1 parent 327acbc commit 7079ff5

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

app/code/Magento/StoreGraphQl/Controller/HttpRequestValidator/StoreValidator.php

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,30 @@ public function validate(HttpRequestInterface $request): void
4242
{
4343
$headerValue = $request->getHeader('Store');
4444
if (!empty($headerValue)) {
45-
$storeCode = ltrim(rtrim($headerValue));
46-
$stores = $this->storeManager->getStores(false, true);
47-
if ((!isset($stores[$storeCode]) && strtolower($storeCode) !== 'default')
48-
|| !$stores[$storeCode]->getIsActive()
49-
) {
45+
$storeCode = trim($headerValue);
46+
if (!$this->isStoreActive($storeCode)) {
5047
$this->storeManager->setCurrentStore(null);
5148
throw new GraphQlInputException(__('Requested store is not found'));
5249
}
5350
}
5451
}
52+
53+
/**
54+
* Check if provided store code corresponds to an active store
55+
*
56+
* @param string $storeCode
57+
* @return bool
58+
*/
59+
private function isStoreActive(string $storeCode): bool
60+
{
61+
$stores = $this->storeManager->getStores(false, true);
62+
if (strtolower($storeCode) === 'default') {
63+
return true;
64+
}
65+
if (isset($stores[$storeCode])) {
66+
return (bool)$stores[$storeCode]->getIsActive();
67+
}
68+
69+
return false;
70+
}
5571
}

0 commit comments

Comments
 (0)