3

I want to show the cart total value as rounded values i.e., if cart total is 12.62 then it should show 13, and if cart value is 12.15 then it should show 12 only in cart. I have done this in Mage/Sales/Model/Quote/Address/Total/Grand.php file collect() method. The code is as follows

public function collect(Mage_Sales_Model_Quote_Address $address)
{
    $grandTotal     = $address->getGrandTotal();
    $baseGrandTotal = $address->getBaseGrandTotal();

    $store      = $address->getQuote()->getStore();
    $totals     = array_sum($address->getAllTotalAmounts());       
    $totals     = round($totals);
    $baseTotals = array_sum($address->getAllBaseTotalAmounts());        
    $baseTotals = round($baseTotals);

    $address->setGrandTotal($grandTotal+$totals);
    $address->setBaseGrandTotal($baseGrandTotal+$baseTotals);
    return $this;
}

But the issue us that when I place this order using paypal it shows

PayPal gateway has rejected request. The totals of the cart item amounts do not match order amounts (#10413: Transaction refused because of an invalid argument. See additional error messages for details).

error. How can I resolve this problem. I want to use the rounded value for all the operations. How this possible.

1

It is caused by Paypal doing the calculation on its side.

Magento does the calculation (adding items price plus shipping/taxes). That is where you do your rounding.

However, Paypal also receives the details of the items and does the same calculation on its side.

If PayPal notices there is a difference between Magento total and its total, then it fails to process the request.

I reckon the only way of doing it, would be to round the item price instead of the grand total before processing the request.

1

One way to resolve this problem completely is to set Transfer Cart Line Items in the Magento paypal configuration to no. Then only the cart total (no items) is passed to Paypal and there should be no discrepancies in the final total.

1

First, it depends on what you want to achieve. Should your customer really pay the rounded amount in the end? Or should that only be a visual thing? Beside that I cannot imagine why the total should be rounded, there are several possibilities:

1) As @paj noted: Transfer Cart Line Items in PayPal settings could be set to no. PayPal is comparing the summed up item prices with the transferred total, so in your case this crashes. But this won't help for other payment gateways. Also consider fixing the tax and net price accordingly, firstly for your accounting department, secondly it may be that PayPal compares "net price + tax == brut price", I am not quite sure about that.

2) You have to "reverse engineer". In an ideal world you must recalculate shipping costs / shipping taxes, item costs / item taxes and perhaps many more (payment fees, COD fees, discount etc.) based on your rounded total amount. I can tell you that won't be fun! When taking tax settings into account (apply before/after discount, prices saves with/without settings, ...) this will be a huge effort.

3) You could add a discount in the amount of the difference of the actual total and your rounded total. That way Magento does the recalculation itself. But note: that depends on your settings regarding discount calculation (on prices with/without tax, etc.). However, how you want to make the negative discount in case of a ceil plain to your customers, is not obvious to me.

4) If you only want to show a visual rounded price in the cart, than you can either rewrite the cart total block or change the cart total .phtml to only show the rounded value, which would be the easiest solution. But note: this wont change any backend calculations, only the visualization in cart for your customers. (I don't see the benefit of showing the rounded value either)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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