Вопрос

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
Лицензировано под: CC-BY-SA с атрибуция
Не связан с magento.stackexchange
scroll top