@@ -66,30 +66,20 @@ public function __construct(
66
66
public function processHeaderValue (string $ headerValue ) : void
67
67
{
68
68
try {
69
+ $ currentStore = $ this ->storeManager ->getStore ();
70
+ $ defaultCode = $ currentStore ->getDefaultCurrency ()->getCode ();
69
71
if (!empty ($ headerValue )) {
70
72
$ headerCurrency = strtoupper (ltrim (rtrim ($ headerValue )));
71
- /** @var \Magento\Store\Model\Store $currentStore */
72
- $ currentStore = $ this ->storeManager ->getStore ();
73
- if (in_array ($ headerCurrency , $ currentStore ->getAvailableCurrencyCodes (true ))) {
74
- $ currentStore ->setCurrentCurrencyCode ($ headerCurrency );
75
- } else {
76
- /** @var \Magento\Store\Model\Store $store */
77
- $ store = $ this ->storeManager ->getStore () ?? $ this ->storeManager ->getDefaultStoreView ();
73
+ if (!in_array ($ headerCurrency , $ currentStore ->getAvailableCurrencyCodes (true ))) {
78
74
//skip store not found exception as it will be handled in graphql validation
79
- $ this ->logger ->warning (__ ('Currency not allowed for store %1 ' , [$ store ->getCode ()]));
80
- $ this ->httpContext ->setValue (
81
- HttpContext::CONTEXT_CURRENCY ,
82
- $ headerCurrency ,
83
- $ store ->getDefaultCurrency ()->getCode ()
84
- );
75
+ $ this ->logger ->warning (__ ('Currency not allowed for store %1 ' , [$ currentStore ->getCode ()]));
85
76
}
77
+ $ this ->httpContext ->setValue (HttpContext::CONTEXT_CURRENCY , $ headerCurrency , $ defaultCode );
86
78
} else {
87
- /** @var \Magento\Store\Model\Store $store */
88
- $ store = $ this ->storeManager ->getStore () ?? $ this ->storeManager ->getDefaultStoreView ();
89
79
$ this ->httpContext ->setValue (
90
80
HttpContext::CONTEXT_CURRENCY ,
91
- $ store ->getCurrentCurrency ()->getCode (),
92
- $ store -> getDefaultCurrency ()-> getCode ()
81
+ $ currentStore ->getCurrentCurrency ()->getCode (),
82
+ $ defaultCode
93
83
);
94
84
}
95
85
} catch (\Magento \Framework \Exception \NoSuchEntityException $ e ) {
0 commit comments