0

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();
  • In which file do you need this code? Custom module ? – aravind Feb 10 at 11:47
  • Yes its in custom module. – Prasad D. Warnakulasuriya Feb 10 at 11:48
  • And ive called Store Manager properly there /** * Store manager * * @var \Magento\Store\Model\StoreManagerInterface */ protected $_storeManager; – Prasad D. Warnakulasuriya Feb 10 at 11:49
  • Have you tried my solution? – aravind Feb 10 at 11:55
  • Yes that didn't work for me – Prasad D. Warnakulasuriya Feb 11 at 3:16
2

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();
|improve this answer|||||
  • $this->_storeManager->getStore()->getCurrentCurrency()->getCode() This worked for me – Prasad D. Warnakulasuriya Feb 11 at 6:34
1

To get store code:

$this->_storeManager->getStore()->getCode();

After your question update, to get current currency code

$this->_storeManager->getStore()->getCurrentCurrency()->getCode(); //EUR
|improve this answer|||||
  • doesn't work for me – Prasad D. Warnakulasuriya Feb 11 at 3:18
  • 1
    to get the store code as you asked, it should work – PЯINCƏ Feb 11 at 13:46
  • Just I needed to get currency code dude – Prasad D. Warnakulasuriya Feb 12 at 4:04
  • 1
    Look your post title and content before update, at no time you are talking about currency – PЯINCƏ Feb 12 at 9:07

Not the answer you're looking for? Browse other questions tagged or ask your own question.