Skip to content

Commit 35b9aa9

Browse files
committed
Merge remote-tracking branch 'origin/AC-14790' into cia-2.4.9-alpha2-develop-bugfix-07022025
2 parents 43826fc + 6c3231b commit 35b9aa9

File tree

2 files changed

+80
-40
lines changed

2 files changed

+80
-40
lines changed

app/code/Magento/Store/Model/StoreResolver.php

Lines changed: 62 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,59 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2015 Adobe
4+
* All Rights Reserved.
55
*/
6+
67
declare(strict_types=1);
78

89
namespace Magento\Store\Model;
910

11+
use Magento\Framework\App\ObjectManager;
12+
use Magento\Framework\App\Request\Http;
13+
use Magento\Framework\Cache\FrontendInterface;
14+
use Magento\Framework\Exception\NoSuchEntityException;
15+
use Magento\Store\Api\Data\StoreInterface;
16+
use Magento\Store\Api\StoreCookieManagerInterface;
17+
use Magento\Store\Api\StoreRepositoryInterface;
18+
use Magento\Store\Api\StoreResolverInterface;
19+
use Magento\Store\App\Request\StorePathInfoValidator;
20+
use Magento\Framework\Stdlib\CookieManagerInterface;
21+
1022
/**
1123
* Class used to resolve store from url path or get parameters or cookie.
24+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
25+
* @SuppressWarnings(PHPMD.CookieAndSessionMisuse)
1226
*/
13-
class StoreResolver implements \Magento\Store\Api\StoreResolverInterface
27+
class StoreResolver implements StoreResolverInterface
1428
{
1529
/**
1630
* Cache tag
1731
*/
18-
const CACHE_TAG = 'store_relations';
32+
public const CACHE_TAG = 'store_relations';
1933

2034
/**
21-
* @var \Magento\Store\Api\StoreRepositoryInterface
35+
* @var StoreRepositoryInterface
2236
*/
2337
protected $storeRepository;
2438

2539
/**
26-
* @var \Magento\Store\Api\StoreCookieManagerInterface
40+
* @var StoreCookieManagerInterface
2741
*/
2842
protected $storeCookieManager;
2943

3044
/**
3145
* @deprecated 101.0.0
46+
* @see No longer needed
47+
*
48+
* @var FrontendInterface
3249
*/
3350
protected $cache;
3451

3552
/**
3653
* @deprecated 101.0.0
54+
* @see No longer needed
55+
*
56+
* @var StoreResolver\ReaderList
3757
*/
3858
protected $readerList;
3959

@@ -48,7 +68,7 @@ class StoreResolver implements \Magento\Store\Api\StoreResolverInterface
4868
protected $scopeCode;
4969

5070
/**
51-
* @var \Magento\Framework\App\Request\Http
71+
* @var Http
5272
*/
5373
protected $request;
5474

@@ -58,27 +78,34 @@ class StoreResolver implements \Magento\Store\Api\StoreResolverInterface
5878
private $storesData;
5979

6080
/**
61-
* @var \Magento\Store\App\Request\StorePathInfoValidator
81+
* @var StorePathInfoValidator
6282
*/
6383
private $storePathInfoValidator;
6484

6585
/**
66-
* @param \Magento\Store\Api\StoreRepositoryInterface $storeRepository
67-
* @param \Magento\Store\Api\StoreCookieManagerInterface $storeCookieManager
68-
* @param \Magento\Framework\App\Request\Http $request
69-
* @param \Magento\Store\Model\StoresData $storesData
70-
* @param \Magento\Store\App\Request\StorePathInfoValidator $storePathInfoValidator
71-
* @param string|null $runMode
86+
* @var CookieManagerInterface
87+
*/
88+
private $cookieManagerInterface;
89+
90+
/**
91+
* @param StoreRepositoryInterface $storeRepository
92+
* @param StoreCookieManagerInterface $storeCookieManager
93+
* @param Http $request
94+
* @param StoresData $storesData
95+
* @param StorePathInfoValidator $storePathInfoValidator
96+
* @param string $runMode
7297
* @param string|null $scopeCode
98+
* @param CookieManagerInterface|null $cookieManagerInterface
7399
*/
74100
public function __construct(
75-
\Magento\Store\Api\StoreRepositoryInterface $storeRepository,
76-
\Magento\Store\Api\StoreCookieManagerInterface $storeCookieManager,
77-
\Magento\Framework\App\Request\Http $request,
78-
\Magento\Store\Model\StoresData $storesData,
79-
\Magento\Store\App\Request\StorePathInfoValidator $storePathInfoValidator,
101+
StoreRepositoryInterface $storeRepository,
102+
StoreCookieManagerInterface $storeCookieManager,
103+
Http $request,
104+
StoresData $storesData,
105+
StorePathInfoValidator $storePathInfoValidator,
80106
$runMode = ScopeInterface::SCOPE_STORE,
81-
$scopeCode = null
107+
$scopeCode = null,
108+
?CookieManagerInterface $cookieManagerInterface = null
82109
) {
83110
$this->storeRepository = $storeRepository;
84111
$this->storeCookieManager = $storeCookieManager;
@@ -87,6 +114,8 @@ public function __construct(
87114
$this->storesData = $storesData;
88115
$this->runMode = $scopeCode ? $runMode : ScopeInterface::SCOPE_WEBSITE;
89116
$this->scopeCode = $scopeCode;
117+
$this->cookieManagerInterface = $cookieManagerInterface ?:
118+
ObjectManager::getInstance()->get(CookieManagerInterface::class);
90119
}
91120

92121
/**
@@ -95,12 +124,11 @@ public function __construct(
95124
public function getCurrentStoreId()
96125
{
97126
list($stores, $defaultStoreId) = $this->getStoresData();
98-
99127
$storeCode = $this->storePathInfoValidator->getValidStoreCode($this->request);
100128

101129
if (!$storeCode) {
102130
$storeCode = $this->request->getParam(
103-
\Magento\Store\Model\StoreManagerInterface::PARAM_NAME,
131+
StoreManagerInterface::PARAM_NAME,
104132
$this->storeCookieManager->getStoreCodeFromCookie()
105133
);
106134
}
@@ -115,7 +143,9 @@ public function getCurrentStoreId()
115143
if ($storeCode) {
116144
try {
117145
$store = $this->getRequestedStoreByCode($storeCode);
118-
} catch (\Magento\Framework\Exception\NoSuchEntityException $e) {
146+
} catch (NoSuchEntityException $e) {
147+
$this->request->setQueryValue(StoreManagerInterface::PARAM_NAME);
148+
$this->cookieManagerInterface->deleteCookie(StoreCookieManager::COOKIE_NAME);
119149
$store = $this->getDefaultStoreById($defaultStoreId);
120150
}
121151

@@ -143,7 +173,7 @@ protected function getStoresData() : array
143173
*
144174
* @return array
145175
* @deprecated 101.0.0
146-
* @see \Magento\Store\Model\StoreResolver::getStoresData
176+
* @see StoreResolver::getStoresData
147177
*/
148178
protected function readStoresData() : array
149179
{
@@ -154,15 +184,15 @@ protected function readStoresData() : array
154184
* Retrieve active store by code
155185
*
156186
* @param string $storeCode
157-
* @return \Magento\Store\Api\Data\StoreInterface
158-
* @throws \Magento\Framework\Exception\NoSuchEntityException
187+
* @return StoreInterface
188+
* @throws NoSuchEntityException
159189
*/
160-
protected function getRequestedStoreByCode($storeCode) : \Magento\Store\Api\Data\StoreInterface
190+
protected function getRequestedStoreByCode($storeCode) : StoreInterface
161191
{
162192
try {
163193
$store = $this->storeRepository->getActiveStoreByCode($storeCode);
164194
} catch (StoreIsInactiveException $e) {
165-
throw new \Magento\Framework\Exception\NoSuchEntityException(__('Requested store is inactive'));
195+
throw new NoSuchEntityException(__('Requested store is inactive'));
166196
}
167197

168198
return $store;
@@ -172,15 +202,15 @@ protected function getRequestedStoreByCode($storeCode) : \Magento\Store\Api\Data
172202
* Retrieve active store by code
173203
*
174204
* @param int $id
175-
* @return \Magento\Store\Api\Data\StoreInterface
176-
* @throws \Magento\Framework\Exception\NoSuchEntityException
205+
* @return StoreInterface
206+
* @throws NoSuchEntityException
177207
*/
178-
protected function getDefaultStoreById($id) : \Magento\Store\Api\Data\StoreInterface
208+
protected function getDefaultStoreById($id) : StoreInterface
179209
{
180210
try {
181211
$store = $this->storeRepository->getActiveStoreById($id);
182212
} catch (StoreIsInactiveException $e) {
183-
throw new \Magento\Framework\Exception\NoSuchEntityException(__('Default store is inactive'));
213+
throw new NoSuchEntityException(__('Default store is inactive'));
184214
}
185215

186216
return $store;

app/code/Magento/StoreGraphQl/Controller/HttpHeaderProcessor/StoreProcessor.php

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
<?php
2-
32
/**
4-
* Copyright © Magento, Inc. All rights reserved.
5-
* See COPYING.txt for license details.
3+
* Copyright 2017 Adobe
4+
* All Rights Reserved.
65
*/
76

87
declare(strict_types=1);
@@ -16,6 +15,7 @@
1615
use Magento\Framework\App\ObjectManager;
1716
use Magento\Framework\Locale\ResolverInterface;
1817
use Psr\Log\LoggerInterface;
18+
use Magento\Framework\App\Request\Http;
1919

2020
/**
2121
* Process the "Store" header entry
@@ -47,25 +47,33 @@ class StoreProcessor implements HttpHeaderProcessorInterface
4747
*/
4848
private $logger;
4949

50+
/**
51+
* @var Http
52+
*/
53+
private $httpRequest;
54+
5055
/**
5156
* @param StoreManagerInterface $storeManager
5257
* @param HttpContext $httpContext
5358
* @param StoreCookieManagerInterface $storeCookieManager
54-
* @param ResolverInterface $localeResolver
55-
* @param LoggerInterface $logger
59+
* @param ResolverInterface|null $localeResolver
60+
* @param LoggerInterface|null $logger
61+
* @param Http|null $httpRequest
5662
*/
5763
public function __construct(
5864
StoreManagerInterface $storeManager,
5965
HttpContext $httpContext,
6066
StoreCookieManagerInterface $storeCookieManager,
6167
?ResolverInterface $localeResolver = null,
62-
?LoggerInterface $logger = null
68+
?LoggerInterface $logger = null,
69+
?Http $httpRequest = null
6370
) {
6471
$this->storeManager = $storeManager;
6572
$this->httpContext = $httpContext;
6673
$this->storeCookieManager = $storeCookieManager;
6774
$this->localeResolver = $localeResolver ?: ObjectManager::getInstance()->get(ResolverInterface::class);
6875
$this->logger = $logger ?: ObjectManager::getInstance()->get(LoggerInterface::class);
76+
$this->httpRequest = $httpRequest ?: ObjectManager::getInstance()->get(Http::class);
6977
}
7078

7179
/**
@@ -90,8 +98,10 @@ public function processHeaderValue(string $headerValue): void
9098
$this->logger->error($e->getMessage());
9199
}
92100
} elseif (!$this->isAlreadySet()) {
93-
$storeCode = $this->storeCookieManager->getStoreCodeFromCookie()
94-
?: $this->storeManager->getDefaultStoreView()->getCode();
101+
$storeCode = $this->httpRequest->getParam(
102+
StoreManagerInterface::PARAM_NAME,
103+
$this->storeCookieManager->getStoreCodeFromCookie()
104+
) ?: $this->storeManager->getDefaultStoreView()->getCode();
95105
$this->storeManager->setCurrentStore($storeCode);
96106
$this->updateContext($storeCode);
97107
}

0 commit comments

Comments
 (0)