Magento – Magento 2: How to get full Currency Switcher

currencycustomgeturlmagento2switcher

I want to get the full URL to switch currency to use it as a link, Currency switcher use the widget to change the currency, I don't want to use the widget. For Example:

This is how works now:

<a href="#" data-post="{"action":"http:\/\/localhost\/directory\/currency\/switch\/","data":{"currency":"USD","uenc":"aHR0cDovL3Rlc3RzaG9wLmlvLz9fX19zdG9yZT1kZWZhdWx0Jl9fX2Zyb21fc3RvcmU9ZnI,"}}">Currency</a>

I want something like this:

<a href="http://localhost/directory/currency/switch/USD/uenc/aHR0cDovL3Rlc3RzaG9wLmlvLz9fX19zdG9yZT1kZWZhdWx0Jl9fX2Zyb21fc3RvcmU9ZnI">Currency</a>

Thanks!

NOTE: I'm overriding the directoy module, I already override the template, but can't get the full url

Best Answer

You have to just pass currency full url as like below in your template file:

You have forgotton to pass querystring currency before USD .

Currency

You have to keep above anchor tag to use in your file.

Above url action go to magento module-directory/Controller/Currency/Switch file.

You can check here function execute() getting post data currency as final currency switcher.

Here this file contains main logic for currency switcher.

You have to pass just currency three digit format to pass your main currency.

If you have to convert euro you have to set currency/EUR, if you want to convert British pound then pass currency/GBP in your above url after directory/currency/switch.