If the product price is $25.00, I want Opencart to AUTOMATICALLY display it without the decimals ($25)
If the product price is not round, $25.30, I want Opencart to display it with two decimals ($25.30)
I'm using 1.4.9.1, and I have Opencart set to 2 decimals in the Admin section.
Does anyone have an idea on how to do that?
Thank you so much!
If the product price is not round, $25.30, I want Opencart to display it with two decimals ($25.30)
I'm using 1.4.9.1, and I have Opencart set to 2 decimals in the Admin section.
Does anyone have an idea on how to do that?
Thank you so much!
Where ever the price is displayed in your templates you would have to wrap the price variable in a php function
example
<?php echo $price; ?>
would become
<?php echo rtrim($price, '.00'); ?>
example
<?php echo $price; ?>
would become
<?php echo rtrim($price, '.00'); ?>
How would you apply it to this?
<?php echo $products[$j]['price']; ?>
Would it be:
<?php echo rtrim($products[$j]['price'], '.00'); ?>
Also, isn't there an easier way to do this, so that it's automated, other than having to replace every single string of code that shows $price manually?
<?php echo $products[$j]['price']; ?>
Would it be:
<?php echo rtrim($products[$j]['price'], '.00'); ?>
Also, isn't there an easier way to do this, so that it's automated, other than having to replace every single string of code that shows $price manually?
You could probably do it at the controller level because that is where the currency/tax gets calculated.
catalog/model/catalog/product.php
catalog/model/catalog/category.php
etc
catalog/model/catalog/product.php
catalog/model/catalog/category.php
etc
I'll do you one better and have you do it at the currency library level as then you only have to do it in once place and it will affect all prices dynamicallyuksitebuilder wrote:You could probably do it at the controller level because that is where the currency/tax gets calculated.
catalog/model/catalog/product.php
catalog/model/catalog/category.php
etc
EDIT: system/library/currency.php
Change:
Code: Select all
return $string;
Code: Select all
return rtrim($string, '.00');
Actually, instead of rtrim, I had to use str_replace:
return str_replace('.00','',$string);
apparently rtrim searches character by character, instead of a full string. So if a price was $170.00, rtrim would replace ALL zeros, including the one in the middle, resulting in this: $17
Thank you again!
return str_replace('.00','',$string);
apparently rtrim searches character by character, instead of a full string. So if a price was $170.00, rtrim would replace ALL zeros, including the one in the middle, resulting in this: $17
Thank you again!
can you tell me please how can i make oc calculate prices with just 2 decimals instead of 4? thanksQphoria wrote:I'll do you one better and have you do it at the currency library level as then you only have to do it in once place and it will affect all prices dynamicallyuksitebuilder wrote:You could probably do it at the controller level because that is where the currency/tax gets calculated.
catalog/model/catalog/product.php
catalog/model/catalog/category.php
etc
EDIT: system/library/currency.php
Change:toCode: Select all
return $string;
return rtrim($string, '.00');Code: Select all
Who is online
Users browsing this forum: No registered users and 72 guests