@@ -30,6 +30,7 @@ class CurrencyProcessor implements HttpHeaderProcessorInterface
3030
3131 /**
3232 * @var SessionManagerInterface
33+ * @deprecated
3334 */
3435 private $ session ;
3536
@@ -65,37 +66,21 @@ public function __construct(
6566 public function processHeaderValue (string $ headerValue ) : void
6667 {
6768 try {
68- if (!empty ($ headerValue )) {
69- $ headerCurrency = strtoupper (ltrim (rtrim ($ headerValue )));
70- /** @var \Magento\Store\Model\Store $currentStore */
71- $ currentStore = $ this ->storeManager ->getStore ();
72- if (in_array ($ headerCurrency , $ currentStore ->getAvailableCurrencyCodes (true ))) {
73- $ currentStore ->setCurrentCurrencyCode ($ headerCurrency );
74- } else {
75- /** @var \Magento\Store\Model\Store $store */
76- $ store = $ this ->storeManager ->getStore () ?? $ this ->storeManager ->getDefaultStoreView ();
77- //skip store not found exception as it will be handled in graphql validation
78- $ this ->logger ->warning (__ ('Currency not allowed for store %1 ' , [$ store ->getCode ()]));
79- $ this ->httpContext ->setValue (
80- HttpContext::CONTEXT_CURRENCY ,
81- $ headerCurrency ,
82- $ store ->getDefaultCurrency ()->getCode ()
83- );
84- }
69+ $ currentStore = $ this ->storeManager ->getStore ();
70+ $ defaultCode = $ currentStore ->getDefaultCurrency ()->getCode ();
71+ if (empty ($ headerValue )) {
72+ $ this ->httpContext ->setValue (
73+ HttpContext::CONTEXT_CURRENCY ,
74+ $ currentStore ->getCurrentCurrency ()->getCode (),
75+ $ defaultCode
76+ );
8577 } else {
86- if ($ this ->session ->getCurrencyCode ()) {
87- /** @var \Magento\Store\Model\Store $currentStore */
88- $ currentStore = $ this ->storeManager ->getStore () ?? $ this ->storeManager ->getDefaultStoreView ();
89- $ currentStore ->setCurrentCurrencyCode ($ this ->session ->getCurrencyCode ());
90- } else {
91- /** @var \Magento\Store\Model\Store $store */
92- $ store = $ this ->storeManager ->getStore () ?? $ this ->storeManager ->getDefaultStoreView ();
93- $ this ->httpContext ->setValue (
94- HttpContext::CONTEXT_CURRENCY ,
95- $ store ->getCurrentCurrency ()->getCode (),
96- $ store ->getDefaultCurrency ()->getCode ()
97- );
78+ $ headerCurrency = strtoupper (trim ($ headerValue ));
79+ if (!in_array ($ headerCurrency , $ currentStore ->getAvailableCurrencyCodes (true ))) {
80+ //skip store not found exception as it will be handled in graphql validation
81+ $ this ->logger ->warning (__ ('Currency not allowed for store %1 ' , [$ currentStore ->getCode ()]));
9882 }
83+ $ this ->httpContext ->setValue (HttpContext::CONTEXT_CURRENCY , $ headerCurrency , $ defaultCode );
9984 }
10085 } catch (\Magento \Framework \Exception \NoSuchEntityException $ e ) {
10186 //skip store not found exception as it will be handled in graphql validation
0 commit comments