سؤال

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