2

I'm currently using the 1.9.1 RWD theme, and having issues with the currency-switcher that shoes up in the footer.

The currency-swticher in the header works fine, but the one in the footer has the following issue.

Say for example I have 3 currencies set up. £, € and $ (Pounds, Euros and Dollars). When I load up the page on a mobile (or resized in a browser) the default selected value is always my default currency (Pounds in this case). If I select Euros, it will change the pages currency to Euros, however when I go to select another currency - the selected currency is still pounds. Meaning that I am unable to swap the currency back to pounds.

Any thoughts as, as far as I can tell - it should be the same bit of code no?

Update: I've tried moving the currency-selector that works in the header to the footer, and the same issue happens.

Doing some further research by using $this->getCurrentCurrencyCode() throughout the page. While in the header, this variable holds the correct information, but somehow by the time it reaches the footer - it is no longer this value, and is instead what appears to be the websites default value.

2 Answers 2

1

I spent a few hours investigating this. I agree it is the same code due to

file: magento/app/design/frontend/rwd/default/layout/directory.xml
    <default>
        <reference name="head">
            <block type="core/template" name="optional_zip_countries" as="optional_zip_countries" template="directory/js/optional_zip_countries.phtml" />
        </reference>

        <reference name="header">
            <block type="directory/currency" name="currency" as="currency_switcher" template="directory/currency.phtml"/>
        </reference>

        <reference name="footer">
            <block type="directory/currency" name="footer_currency" after="footer_store_language" template="directory/currency.phtml"/>
        </reference>
    </default>

The big difference is that the footer block is cached. You can make the footer currency changeer show the correct currency if you refresh the BLOCK_HTML cache in the Magento admin and then refresh the front page in your browser.

The RWD development team seem to have missed this in its test phase. I think you have uncovered a genuine bug in the RWD theme.

How to fix it?

Well I am not a Magento expert for sure and I would have thought adjusting

<?php echo $this->getChildHtml() ?>

to

<?php echo $this->getChildHtml('',false,true) ?>

in

file: magento/app/design/fromtend/rwd/default/template/page/html/footer.phtml

and

<?php echo $this->getChildHtml('footer') ?>

to

<?php echo $this->getChildHtml('footer',false,true) ?>

in

file: magento/app/design/frontend/rwd/default/template/page/3columns.phtml

with reference to:

file: magento/app/code/core/Mage/Page/Block/Html/Footer.php
    public function getChildHtml($name='', $useCache=true, $sorted=true)
    {
        return parent::getChildHtml($name, $useCache, $sorted);
    }

would have solved it (by requesting the childHtml not be built from the cache). But Magento cacheing remains an enigma to me. Maybe you know more about it and can resolve this by .phtml file manipulation alone.

The solution I have for you is to extend the class Mage_Page_Block_Html_Footer (file magento/app/code/core/Mage/Page/Block/Html/Footer.php) and rewrite the function getCacheKeyInfo() to add a currency code to the cache key. This has the advantage that you can continue to benefit from the speed enhancement of the Magento cache:

file: magento/app/code/core/Mage/Page/Block/Html/Footer.php
    /**
     * Get cache key informative items
     *
     * @return array
     */
    public function getCacheKeyInfo()
    {
        return array(
            'PAGE_FOOTER',
            Mage::app()->getStore()->getId(),
            (int)Mage::app()->getStore()->isCurrentlySecure(),
            Mage::getDesign()->getPackageName(),
            Mage::getDesign()->getTheme('template'),
            Mage::getSingleton('customer/session')->isLoggedIn(),
            //an extra line for when the currency switcher is in the footer:
            Mage::app()->getStore()->getCurrentCurrency()->getCode()
        );
    }

Are you familiar with creating your own module and rewriting classes? - That is the way to put this new cache key into your theme rather than editing the core class file.

0

I found the accepted answer had issues on mobiles and tablets with Magento 1.9.2.3. 404 errors occurred and redirects to the homepage whenever I changed the currency. Disabling caching in the footer was the easiest solution and I didn't notice any difference in speed. Copy app/code/core/Mage/Page/Block/Html/Footer.php and place it in app/code/local/Mage/Page/Block/Html/Footer.php. Then comment out lines 40 to 45.

protected $_copyright;

protected function _construct()
{/*
    $this->addData(array('cache_lifetime' => false));
    $this->addCacheTag(array(
        Mage_Core_Model_Store::CACHE_TAG,
        Mage_Cms_Model_Block::CACHE_TAG
    ));*/
}

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.