@@ -66,30 +66,20 @@ public function __construct(
6666 public function processHeaderValue (string $ headerValue ) : void
6767 {
6868 try {
69+ $ currentStore = $ this ->storeManager ->getStore ();
70+ $ defaultCode = $ currentStore ->getDefaultCurrency ()->getCode ();
6971 if (!empty ($ headerValue )) {
7072 $ 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 ))) {
7874 //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 ()]));
8576 }
77+ $ this ->httpContext ->setValue (HttpContext::CONTEXT_CURRENCY , $ headerCurrency , $ defaultCode );
8678 } else {
87- /** @var \Magento\Store\Model\Store $store */
88- $ store = $ this ->storeManager ->getStore () ?? $ this ->storeManager ->getDefaultStoreView ();
8979 $ this ->httpContext ->setValue (
9080 HttpContext::CONTEXT_CURRENCY ,
91- $ store ->getCurrentCurrency ()->getCode (),
92- $ store -> getDefaultCurrency ()-> getCode ()
81+ $ currentStore ->getCurrentCurrency ()->getCode (),
82+ $ defaultCode
9383 );
9484 }
9585 } catch (\Magento \Framework \Exception \NoSuchEntityException $ e ) {
0 commit comments