Magento: get price in current currency

Magento: get price in current currency

September 7, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Magento: get price in current currency

Magento: Displaying Product Prices in the Current Currency

As an e-commerce developer, ensuring your website’s pricing is displayed accurately in the selected currency is a crucial aspect of providing a seamless shopping experience for your customers. In this guide, we’ll explore how to correctly retrieve and display product prices in Magento when multiple currencies are supported.

Understanding Magento’s Currency Configuration

Magento allows you to manage multiple currencies within your store configuration. To enable this feature:

  1. Go to Stores > Configuration.
  2. Select the Currency Setup section under General.
  3. Set ‘Enabled’ to ‘Yes’.
  4. Add the desired currencies and set their rates.

Once enabled, customers can select their preferred currency from a dropdown menu on the frontend.

The Current Issue: Hardcoding Currency

The provided code shows that the extension is directly fetching the product price using $_product->getPrice(). However, this method returns the base currency’s value. When a customer selects a different currency, the displayed price remains unchanged.

Additionally, the hardcoded use of number_format($price,2) to display the price limits the formatting to two decimal places, which may not always be appropriate for all supported currencies.

Retrieving Prices in the Selected Currency

To display prices in the current customer-selected currency, you need to utilize Magento’s built-in API. Here’s how to modify your code:

$_product = Mage::getModel('catalog/product')->load($_product_id);
$price = $_product->getPrice();
if (Mage::app()->getStore()->isObjectNew()) {
    $storeId = Mage::app()->getStore()->getId();
} else {
    $storeId = Mage::app()->getRequest()->getParam('store');
}
$currency = Mage::app()->getLocale()->currency(Mage::getStoreConfig('currency/options/default'));
$priceInSelectedCurrency = $currency->round($price);
echo '<span class="price">' . $currency->toCurrency($priceInSelectedCurrency, ['display'=>Zend_Currency::NO符号]) . '</span>';

Here’s what the code does:

  • It first retrieves the product using Magento’s model.
  • It then checks if a store ID is passed in the request. If not, it uses the current app store ID.
  • It fetches the active currency configuration.
  • It converts the price to the selected currency and rounds it to two decimal places.
  • Finally, it displays the formatted price.

Best Practices for Currency Display

To ensure optimal performance:

  1. Avoid calling Magento models directly in your custom extensions. Use events or observers instead to hook into existing functionality.
  2. Cache frequently accessed prices to minimize database queries.
  3. Handle edge cases, such as when a customer selects an unsupported currency.
  4. Test the conversion thoroughly for all supported currencies.

Conclusion

Displaying product prices in the selected currency is more than just a technical requirement—it’s a key factor in building trust with your customers and providing a user-friendly shopping experience.

By using Magento’s built-in currency management features and ensuring you convert prices accurately, you can enhance your store’s functionality without compromising on performance or user experience. For more advanced tips on Magento development, check out our comprehensive resources at Laravel Company.

Catalog API Extensions Themes

Our network