|
Where is the best place to apply a price formatting function globally to all prices in Magento?
(I only want it to affect display price output on frontend, not actual numbers in the backend or checkout. For example, I want to format any price such as $68.00 to just $68 but keep decimals in case there are prices such as $33.50. And it should only affect the output as displayed to the visitor.)
I found a function on PHP.net that allows me to do exactly what I want:
// formats money to a whole number or with 2 decimals; includes a dollar sign in front function formatMoney($number, $cents = 1) { // cents: 0=never, 1=if needed, 2=always if (is_numeric($number)) { // a number if (!$number) { // zero $money = ($cents == 2 ? '0.00' : '0'); // output zero } else { // value if (floor($number) == $number) { // whole number $money = number_format($number, ($cents == 2 ? 2 : 0)); // format } else { // cents $money = number_format(round($number, 2), ($cents == 0 ? 0 : 2)); // format } // integer or decimal } // value return $money; } // numeric } // formatMoney
But where should I put this function and how can I apply it to getPriceHtml? I don’t want to have to edit every instance of a price in every template, so it should be global.
|