@@ -30,6 +30,7 @@ class CurrencyProcessor implements HttpHeaderProcessorInterface
30
30
31
31
/**
32
32
* @var SessionManagerInterface
33
+ * @deprecated
33
34
*/
34
35
private $ session ;
35
36
@@ -65,37 +66,21 @@ public function __construct(
65
66
public function processHeaderValue (string $ headerValue ) : void
66
67
{
67
68
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
+ );
85
77
} 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 ()]));
98
82
}
83
+ $ this ->httpContext ->setValue (HttpContext::CONTEXT_CURRENCY , $ headerCurrency , $ defaultCode );
99
84
}
100
85
} catch (\Magento \Framework \Exception \NoSuchEntityException $ e ) {
101
86
//skip store not found exception as it will be handled in graphql validation
0 commit comments