I am using Magento CE I have a requirement to use ceil on all prices/fees. I am also using product custom options.

It seems that the rounding is not done in a single place. First I modify app\code\core\Mage\Core\Model\Store.php:

public function roundPrice($price)
    return ceil(sprintf('%.2f', $price));

public function formatPrice($price, $includeContainer = true)
    if ($this->getCurrentCurrency()) {
        $roundedPrice = $this->roundPrice($price);
        return $this->getCurrentCurrency()->format($roundedPrice, array(), $includeContainer);
    return $this->roundPrice($price);

But since I am also using catalog price rules, the special price shown in the product page is not being ceil'ed. So I modified the following: app\design\frontend\base\default\template\customoptions\catalog-product-view-options.phtml:

return Math.ceil(prPrice);
return Math.ceil(totalOpPrice);

Since I have product custom options, there are discounts for the product as well as for the options. I realize that the unitPrice (product price + option prices) in the shopping cart is calculated without any rounding. In my test, the unitPrice is $399.2 + $63.2 = $462.4 and in the checkout cart, after the ceiling the unitPrice is shown as $463. However I want the behavior to be that the unitPrice is calculated as: $400 + $64 = $464.

It seems that the row total for each item is calculated without any ceiling. Where should I modify the logic that calculates the row total?

The other question is that it seems that roundPrice is done all over the place. What is the best approach if I just want to change the rounding policy globally?

1 Answer 1


It seems that if I change the following file app\code\core\Mage\CatalogRule\Model\Observer.php:

$key = "$date|$wId|$gId|$pId";
if (!isset($this->_rulePrices[$key])) {
    $rulePrice = Mage::getResourceModel('catalogrule/rule')
            ->getRulePrice($date, $wId, $gId, $pId);
    if ($rulePrice != 0) {
        $this->_rulePrices[$key] = Mage::app()->getStore($storeId)->roundPrice($rulePrice);
    else {
        $this->_rulePrices[$key] = $rulePrice;
    if ($this->_rulePrices[$key]!==false) {
        $finalPrice = min($product->getData('final_price'), $this->_rulePrices[$key]);

I can revert the changes in the above *.phtml and still get the correct unitPrice both in the product page and the checkout cart page.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.