문제

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