Customizing Price Format

If you ever need to go beyond the price formatting available in eCommerce you can customize the pricing display by overriding and modifying the CoreCommercePrice class.

Override the CoreCommercePrice class

Override that class by copying it from /package/core_commerce/libraries/price.php to /libraries/price.php this will prevent your changes from being wiped on the next upgrade.

Modify the CoreCommercePrice::format method

The CoreCommercePrice::format method handles the output for all of the pricing, here are some examples of how you may want to change the formatting.

Examples

These examples will override the options that you set in the dashboard, so those options will no longer function

No cents for prices ending in 00

public static function format($number) {
if(round($number) == $number) {
return '$'.number_format(abs($number), 0, '.', ',');
} else {
return '$'.number_format(abs($number), 2, '.', ',');
}
}

Custom logic to display different price formats based off the locale defined by the internationalization addon.

public static function format($number) {
switch(strtolower(ACTIVE_LOCALE)) {
case 'en_gb':
// displays euro for the uk
return '€'.number_format(abs($number), 2, ',', '.');
break;
default:
return parent::format($number);
}
}