1

I am using Magento's design exceptions to set the theme as mobile for mobile devices.

enter image description here

Since I am not using a separate store view or website, is it possible to provide to the user a 'Switch to Desktop' link? I guess I would need to override a controller somewhere, would appreciate anyone that can help me out with a starting point.

5

The short answer here is no, though, you could drop a javascript cookie called forcedesktop and set it to true. This would be set onclick for the switcher link.

Then rewrite the design exception method to sniff for existence of the cookie:

app/code/local/YourCompany/YourModule/etc/config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <YourCompany_YourModule>
             <version>0.1.0</version>
        </YourCompany_YourModule>
    </modules>
    <global>
        <models>
            <core>
                <rewrite>
                    <design_package>YourCompany_YourModule_Model_Design_Package</design_package>
                </rewrite>
            </core>
        </models>
    </global>
</config>

app/code/local/YourCompany/YourModule/Model/Design/Package.php

<?php

class YourCompany_YourModule_Model_Design_Package extends Mage_Core_Model_Design_Package
{

    protected function _checkUserAgentAgainstRegexps($regexpsConfigPath)
    {
        if(Mage::getModel('core/cookie')->get('forcedesktop')=='true'){
            return false;
        }

        parent::_checkUserAgentAgainstRegexps($regexpsConfigPath);
    }
}
  • 1
    will try it out, cheers. – Francis Kim Oct 22 '13 at 4:12
  • This answer is correct, though there is a return missing before the parent::_checkUserAgentAgainstRegexps($regexpsConfigPath);. Otherwhise it would always show the desktop version when the cookie isn't set. – Schwierig Jan 29 '14 at 9:05
2

Earlier this year we put together a quick module to implement this functionality complete with support for use behind the Enterprise Edition FPC. Since then it's been used on a number of sites we've built. When I saw this question posted I decided to polish it up and publish it on GitHub. @philwinkle beat me to posting an answer though... ;) And it does actually use the same basic technique he mentions. I.e. it sets a cookie which is then used to determine if the design exception should be honored or not.

In this case we are using setcookie and $_COOKIE directly for performance and/or compatibility with the FPC processor which EE uses on a cache hit:

class CLS_DesignSwitcher_Model_Core_Design_Package extends Mage_Core_Model_Design_Package
{
    /**
     * Get regex rules from config and check user-agent against them. We override to
     * determine if the design exception should be ignored based on presence of a cookie.
     * 
     * @param string $regexpsConfigPath
     * @return mixed
     * @see Mage_Core_Model_Design_Package
     */
    protected function _checkUserAgentAgainstRegexps($regexpsConfigPath)
    {
        $ignoreException = null;
        if (isset($_COOKIE[CLS_DesignSwitcher_Helper_Data::FULL_SITE_COOKIE])) {
            $ignoreException = $_COOKIE[CLS_DesignSwitcher_Helper_Data::FULL_SITE_COOKIE];
        }
        return $ignoreException ? false : parent::_checkUserAgentAgainstRegexps($regexpsConfigPath);
    }
}

I'll spare posting the full code for it here, but feel free to take it and use it verbatim or alter to suite what you need… You can grab a copy from here: https://github.com/davidalger/CLS_DesignSwitcher.

  • I used CLS_DesignSwitcher...But it shows error like " <b>Fatal error</b>: Class 'Mage_Cls_Designswitcher_Helper_Data' not found " – Kishore Patra Jan 12 '16 at 14:51

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.