Paypal express review in Magento doubling the grand total

A recent query from a client arose when customers were being presented with the right cart totals all the way through the checkout process, but on returning to the site from Paypal, on the review page they were presented with a grand total which was double what they were expecting.

On investigation we spotted that the site’s top cart was collecting the quote totals with this bit of code :

$quote = Mage::getSingleton('checkout/cart')->getQuote();
$quote->collectTotals();
$quote->getShippingAddress()->collectTotals();

Further down the page, though, the quote’s totals were being collected again, resulting in the doubling of the grand total (there was no shipping charge in this instance).

The code above was wrapped in an if clause which excluded it from being run on the cart page, or on Magento’s standard checkout pages, like so :

if (!(Mage::app()->getRequest()->getControllerName()=='onepage') && !(Mage::app()->getRequest()->getControllerName()=='cart')) {

The controller name for the Paypal review page, however, was “express” so the code wasn’t being excluded on the review page, so the totals were being doubled. A quick tweak to the if clause :

if (!(Mage::app()->getRequest()->getControllerName()=='onepage') && !(Mage::app()->getRequest()->getControllerName()=='cart') && !(Mage::app()->getRequest()->getControllerName()=='express')) {

and things were back on track.

Want to talk to us about your project?