11
11
use Magento \Framework \App \RequestInterface ;
12
12
use Magento \Framework \Exception \NoSuchEntityException ;
13
13
use Magento \Framework \Exception \NotFoundException ;
14
+ use Magento \Framework \Session \SessionManagerInterface ;
14
15
use Magento \Store \Api \Data \StoreInterface ;
15
16
use Magento \Store \Api \StoreCookieManagerInterface ;
16
17
use Magento \Store \Model \ScopeInterface ;
23
24
class Context
24
25
{
25
26
/**
26
- * @var \Magento\Framework\Session\ SessionManagerInterface
27
+ * @var SessionManagerInterface
27
28
*/
28
29
protected $ session ;
29
30
30
31
/**
31
- * @var \Magento\Framework\App\Http\Context
32
+ * @var HttpContext
32
33
*/
33
34
protected $ httpContext ;
34
35
35
36
/**
36
- * @var \Magento\Store\Model\ StoreManagerInterface
37
+ * @var StoreManagerInterface
37
38
*/
38
39
protected $ storeManager ;
39
40
@@ -43,15 +44,15 @@ class Context
43
44
protected $ storeCookieManager ;
44
45
45
46
/**
46
- * @param \Magento\Framework\Session\ SessionManagerInterface $session
47
- * @param \Magento\Framework\App\Http\Context $httpContext
48
- * @param \Magento\Store\Model\ StoreManagerInterface $storeManager
47
+ * @param SessionManagerInterface $session
48
+ * @param HttpContext $httpContext
49
+ * @param StoreManagerInterface $storeManager
49
50
* @param StoreCookieManagerInterface $storeCookieManager
50
51
*/
51
52
public function __construct (
52
- \ Magento \ Framework \ Session \ SessionManagerInterface $ session ,
53
- \ Magento \ Framework \ App \ Http \ Context $ httpContext ,
54
- \ Magento \ Store \ Model \ StoreManagerInterface $ storeManager ,
53
+ SessionManagerInterface $ session ,
54
+ HttpContext $ httpContext ,
55
+ StoreManagerInterface $ storeManager ,
55
56
StoreCookieManagerInterface $ storeCookieManager
56
57
) {
57
58
$ this ->session = $ session ;
@@ -80,7 +81,7 @@ public function beforeDispatch(
80
81
81
82
/** @var string|array|null $storeCode */
82
83
$ storeCode = $ request ->getParam (
83
- \ Magento \ Store \ Model \ StoreManagerInterface::PARAM_NAME ,
84
+ StoreManagerInterface::PARAM_NAME ,
84
85
$ this ->storeCookieManager ->getStoreCodeFromCookie ()
85
86
);
86
87
if (is_array ($ storeCode )) {
@@ -106,13 +107,13 @@ public function beforeDispatch(
106
107
* Take action in case of invalid store requested.
107
108
*
108
109
* @param RequestInterface $request
109
- * @param \Throwable |null $previousException
110
+ * @param NoSuchEntityException |null $previousException
110
111
* @return void
111
112
* @throws NotFoundException
112
113
*/
113
114
private function processInvalidStoreRequested (
114
115
RequestInterface $ request ,
115
- \ Throwable $ previousException = null
116
+ NoSuchEntityException $ previousException = null
116
117
) {
117
118
$ store = $ this ->storeManager ->getStore ();
118
119
$ this ->updateContext ($ request , $ store );
@@ -137,27 +138,25 @@ private function updateContext(RequestInterface $request, StoreInterface $store)
137
138
{
138
139
switch (true ) {
139
140
case $ store ->isUseStoreInUrl ():
140
- $ defaultStoreCode = $ store-> getCode () ;
141
+ $ defaultStore = $ store ;
141
142
break ;
142
143
case ScopeInterface::SCOPE_STORE == $ request ->getServerValue (StoreManager::PARAM_RUN_TYPE ):
143
144
$ defaultStoreCode = $ request ->getServerValue (StoreManager::PARAM_RUN_CODE );
145
+ $ defaultStore = $ this ->storeManager ->getStore ($ defaultStoreCode );
144
146
break ;
145
147
default :
146
148
$ defaultStoreCode = $ this ->storeManager ->getDefaultStoreView ()->getCode ();
149
+ $ defaultStore = $ this ->storeManager ->getStore ($ defaultStoreCode );
147
150
break ;
148
151
}
149
152
$ this ->httpContext ->setValue (
150
153
StoreManagerInterface::CONTEXT_STORE ,
151
154
$ store ->getCode (),
152
- $ defaultStoreCode
155
+ $ defaultStore -> getCode ()
153
156
);
154
-
155
- /** @var StoreInterface $defaultStore */
156
- $ defaultStore = $ this ->storeManager ->getWebsite ()->getDefaultStore ();
157
157
$ this ->httpContext ->setValue (
158
158
HttpContext::CONTEXT_CURRENCY ,
159
- $ this ->session ->getCurrencyCode ()
160
- ?: $ store ->getDefaultCurrencyCode (),
159
+ $ this ->session ->getCurrencyCode () ?: $ store ->getDefaultCurrencyCode (),
161
160
$ defaultStore ->getDefaultCurrencyCode ()
162
161
);
163
162
}
0 commit comments