Skip to content

Commit 407c348

Browse files
committed
Merge remote-tracking branch 'arcticfoxes/B2B-2224' into B2B-2204
2 parents 631c2c3 + 43e4d27 commit 407c348

File tree

2 files changed

+19
-29
lines changed

2 files changed

+19
-29
lines changed

app/code/Magento/DirectoryGraphQl/Controller/HttpHeaderProcessor/CurrencyProcessor.php

Lines changed: 14 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -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

app/code/Magento/DirectoryGraphQl/etc/graphql/di.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,9 @@
1616
</argument>
1717
</arguments>
1818
</type>
19+
<type name="Magento\DirectoryGraphQl\Controller\HttpHeaderProcessor\CurrencyProcessor">
20+
<arguments>
21+
<argument name="session" xsi:type="object">Magento\Framework\Session\Generic\Proxy</argument>
22+
</arguments>
23+
</type>
1924
</config>

0 commit comments

Comments
 (0)