Magento Freezing on Currency Change

I’ve recently been looking at introducing multi-currency options on a Magento website (so the customer can see the price in pounds, dollars, euros etc). The problem I’ve been finding was that the website would freeze after I made a new choice of currency, and eventually the web server time out the request.

Today I had a chance to see what’s going on…

By adding mysql database logging I could see magento was making repeated SQL statements like this…

SELECT `sales_flat_quote`.* FROM `sales_flat_quote` WHERE (`sales_flat_quote`.`entity_id`='321') AND (store_id IN ('1')) AND (is_active = 1)

In fact there were over 8K requests to the sales_flat* tables in a very short space of time!

Eventually with a bit of googling I narrowed down the problem to a rogue bit of code in a custom module used for quantity based discounts across multiple different colour/size variations of the same configurable product.

The line of code causing the problem was:
if($items = Mage::getSingleton('checkout/session')->getQuote()->getItemsCollection())

This caused an infinite loop where the getting of the items in the collection caused it to get the prices again, which in turn fired this piece of code off once again, and so on…

Changing the code to:

$quoteId = Mage::getSingleton('checkout/session')->getQuoteId();
$quote = Mage::getModel('sales/quote')->load($quoteId);
if($items = $quote->getItemsCollection())

has solved the problem.

9 Replies to “Magento Freezing on Currency Change”

    1. Hi Samantha, it was in the file:

      /app/code/core/Mage/Catalog/Model/Product/Type/Configurable/Price.php

      However the company uses the custom Tridian module which allows tier pricing to work over a configurable product with different child attributes (eg colour/sizes), so in this case was in the file…

      /app/code/local/Tridian/Catalog/Model/Product/Type/Price.php

      best regards,

      David

  1. Hi David, I cant find the code
    if($items = Mage::getSingleton(‘checkout/session’)->getQuote()->getItemsCollection())
    in my price.php file.
    When i select a currency without logging in, it works fine. But if I log in as a customer, and then try to adjust the currency, it infinitely loops until it times out. I have no idea what’s going on with it. Any ideas?

    1. Hi Asim,

      That might be because we use the custom Tridian module for price. When you login is there something persistant already in the basket? It might be worth trying to disable that functionality. Also is there just one store view / store / website?

      best regards,

      David

      1. Hi David,

        Thanks for the reply!
        After further testing I can say this. Only US currency works.
        If I am not logged in and I change the Currency, it works.
        If I ad a product to my cart with that currency, it will add and then continuously try to load something on the same page, and them time out.
        If I login first, and, from the homepage, just change the currency, it will do the same timeout, even if I don’t have a product in the cart.
        There is just one store view also. I imported the rates and reindexed to make sure.
        Thanks!

          1. Hi Asim,

            Do you have anything in the magento exception or system log, or in the apache error log file? If not might be worth trying to turn on mysql query log temporarily to see if you can see some kind of loop,

            best regards,

            David

  2. Hi admin,
    Thanks for this great solution. I had been searching for this problem from many days but could not find that what can be the issue.

    But after checking your solution i change my
    “Mage::getSingleton(‘checkout/session’)->getQuote()->getShippingAmount()” to “$quoteId = Mage::getSingleton(‘checkout/session’)->getQuoteId();
    $quote = Mage::getModel(‘sales/quote’)->load($quoteId); $quote->->getShippingAmount()”

    And my problem fixed! Thank you very much

Leave a Reply

Your email address will not be published. Required fields are marked *