Greg1234 Posted October 30, 2020 Share Posted October 30, 2020 (edited) Hallo, In Tools.php it is written to not use displayPrice() method anymore, and use Locale::formatPrice() instead. But when I want to use it it gives me error: Attempted to call an undefined method named "formatPrice" of class "Locale". Anyone know why is that? Edited October 30, 2020 by Greg1234 (see edit history) Link to comment Share on other sites More sharing options...
knacky Posted October 30, 2020 Share Posted October 30, 2020 $iso_code = Context::getContext()->currency->iso_code; $product = new Product ((int)Tools::getValue ('id_product')); $price = $product->price; $formated_price = Context::getContext()->currentLocale->formatPrice($price, $iso_code); Link to comment Share on other sites More sharing options...
Greg1234 Posted November 2, 2020 Author Share Posted November 2, 2020 Thanks knacky, your code is almost what I need, but instead of $product->price (which in my case displays 0.000) should be $product->getPrice(). But with the main issue you helped me, which was the Locale: This was how I was trying to use it, and it will not work: Locale::formatPrice($price, $iso_code), it has to be done as you wrote: Context::getContext()->currentLocale->formatPrice($price, $iso_code); or in the module: $this->context->currentLocale->formatPrice($price, $iso_code); Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now