Magento 2 get current store currency code [duplicate]
-
08-04-2021 - |
Вопрос
In Magento 2 I have tried to get the current store code by the below-mentioned code line. But it returns an empty string.
$this->_storeManager->getStore()->getBaseCurrencyCode();
Решение
You can try with following code,
$this->_storeManager->getStore()->getCurrentCurrency()->getCode()
(Or)
public function __construct(
\Magento\Framework\Pricing\PriceCurrencyInterface $priceCurrency,
) {
$this->_priceCurrency = $priceCurrency;
}
public function getCurrentCurrencyCode()
{
return $this->_priceCurrency->getCurrency()->getCurrencyCode();
}
And call this function from your template,
echo $block->getCurrentCurrencyCode();
Другие советы
To get store code:
$this->_storeManager->getStore()->getCode();
After your question update, to get current currency code
$this->_storeManager->getStore()->getCurrentCurrency()->getCode(); //EUR
Не связан с magento.stackexchange