Webkul
Services
Technologies Bagisto QloApps
iOS Android SAP BigCommerce Wix
Trusted by
Samsung Intel Toyota Walmart Disney Nokia Nestlé Decathlon
See all customers
Back to Top
DOC

Convert Price from Current Currency in Magento 2

To convert the price from current currency to base currency can use the following method:

public function convertPrice($amount = 0, $store = null, $currency = null)
{
	$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
	$priceCurrencyObject = $objectManager->get('Magento\Framework\Pricing\PriceCurrencyInterface'); //instance of PriceCurrencyInterface
	$storeManager = $objectManager->get('Magento\Store\Model\StoreManagerInterface'); //instance of StoreManagerInterface
	if ($store == null) {
        $store = $storeManager->getStore()->getStoreId(); //get current store id if store id not get passed
    }
    $rate = $priceCurrencyObject->convert($amount, $store, $currency); //it return price according to current store from base currency

    //If you want it in base currency then use:
    $rate = $priceCurrencyObject->convert($amount, $store) / $amount;
    $amount = $amount / $rate;
	
	return $priceCurrencyObject->round($amount);//You can round off to it or you can return it in its original form
}

Here, $amount is the amount to which you want to convert.

$store is the store id, from which store’s base currency you want to convert.

$currency is the currency to whom  you want to convert, if you passed null then it takes current currency.

I hope this blog will help you with Convert Price from Current Currency in Magento 2. You may also check our wide range of best Magento 2 Extensions.

Please reach out to our team via a support ticket if you have any queries.

Try this and if you have any queries then just comment below 🙂

. . .

Leave a Comment

Your email address will not be published. Required fields are marked*


Be the first to comment.

Back to Top

Message Sent!

If you have more details or questions, you can reply to the received confirmation email.

Back to Home