Search code examples
templateslocaleprestashop-1.7

How to get locale object in PrestaShop 1.7 template?


I'm using Tools::displayPrice() function in my template files to display formated price with currency, but documentation of this function in new version (1.7.6.0) says:

* @deprecated Since 1.7.6.0. Please use Locale::formatPrice() instead
* @see PrestaShop\PrestaShop\Core\Localization\Locale

So how do I use Locale object in my template?

-- P.S. PrestaShop official documentation at: https://devdocs.prestashop.com/1.7/ is a mess, so if anyone could share a link to some complete and reliable resource I (and many more) would be extremely grateful


Solution

  • For Google results:

    Context::getContext()->currentLocale->formatPrice(123.45, 'EUR');

    or e.g. in a module

    $this->context->currentLocale->formatPrice($price, $currencyCode);

    from https://devdocs.prestashop.com/1.7/modules/core_updates/1.7.6/