Thank you Nuno.
So here's my quick implementation of a price beautifier.A) Removing decimals in prices on PRODUCT PAGESIn 'storefront/view/default/template/pages/product/
product.tpl', after
line 94 (i.e. after the "if ($display_price){}" sandwich),
add:
// Remove decimals for prices ending with ".00", for both special and normal prices.
if (strpos($special,'CHF')) {
$special= str_replace('.00','.–',$special);
} else {
$special = str_replace('.00','',$special);
}
if (strpos($price,'CHF')) {
$price= str_replace('.00','.–',$price);
} else {
$price = str_replace('.00','',$price);
}
How does it workIf the product price contains "CHF" (Swiss Franc), it will replace ".00" by ".–".
For all other currencies, it will replace ".00" by nothing.
This assumes you are only using the dot as separator for the trailing decimals".
Added 2024/02/27
B) Removing decimals in prices for FEATURED PRODUCTSIn 'storefront/view/default/template/blocks/
product_list.tpl', after
line 70:
1. Add
$special = $product['special'];
$price = $product['price'];
2. Copy and paste the aforementioned code that removes the decimals.
3. In the <div class="price"> ... </div> sandwich right after, replace echoed instances of $product['special'] by $special, and $product['price'] by $price.
Added 2024/02/27
C) Removing decimals in prices of products on CATEGORY PAGESIn 'storefront/view/default/template/pages/product/
product_listing.tpl', after
line 63, do the same as above for featured products.
Added 2024/02/27
Requirements For the code above to work you need the decimal delimitor being the dot and not the comma.
Else, you would need to adapt the code.
To set the decimal delimitor:
- Go to "System -> Localization -> Language Definitions"
- In the "Key" field, write "decimal_point" and filter.
- Set the "decimal_point" as "." and save it.
Suggestion for a better implementationA better implementation would be creating an method, or modifying existing method, so that the same code can be re-used for all price formatting.
Another improvement would be adapting the code to deal with the effective decimal delimitor.
@llegrand: Sorry, but my question was about if the ".–" was international or used only in some countries like Switzerland.
Furthermore, setting the decimals to 0 is not what I wanted to do : 99.95 CHF must remain unchanged. Only 99.00 CHF should be displayed as 99.– CHF.