Skip to content

Magento: Create Switch Button from Mobile to Desktop

it’s common issue when you implement separate theme for mobile & desktop version.
make sure you already set the mobile theme (add exception) on backend menu System->Config->General->Design
let say, for trigger switching to desktop or mobile use url below:

/* to desktop */
http://yourmagentourl.com/?switch-view=desktop

 

/* back to mobile */

http://yourmagentourl.com/?switch-view=mobile

 

now edit index.php file, put php script below on first line or before “if (version_compare(phpversion(), ‘5.2.0’, ‘<‘)===true)

 if(isset($_REQUEST[“switch-view”]))
{
/* remove existing cookie */

if(isset($_COOKIE[‘switch’]))
setcookie(“switch”, “desktop”, time()-3600, ‘/’);

/* set cookie*/
if($_REQUEST[“switch-view”]==’desktop’)
setcookie(‘switch’,$_REQUEST[“switch-view”],time() + 36000, ‘/’); // 86400 = 1 day

if($_GET[“switch-view”] == ‘mobile’){
//$_SERVER[‘HTTP_USER_AGENT’] = ‘iphone’;
setcookie(“switch”, “desktop”, time()-3600, ‘/’);
$_SERVER[‘HTTP_USER_AGENT’] = ‘iPhone’;
}

}

if(isset($_COOKIE[‘switch’]))
{

if($_COOKIE[‘switch’] == ‘desktop’)
$_SERVER[‘HTTP_USER_AGENT’] = ‘windows,chrome,firefox’;

if($_COOKIE[‘switch’] == ‘mobile’){
$_SERVER[‘HTTP_USER_AGENT’] = ‘iPhone’;
setcookie(“switch”, “desktop”, time()-3600, ‘/’);
}

}

if(isset($_GET[“switch-view”]))
{

if($_GET[“switch-view”] == ‘desktop’){
$_SERVER[‘HTTP_USER_AGENT’] = ‘windows,chrome,firefox’;
}
if($_GET[“switch-view”] == ‘mobile’){

setcookie(“switch”, “desktop”, time()-3600, ‘/’);
$_SERVER[‘HTTP_USER_AGENT’] = ‘iPhone’;
}
}

 

 

good luck gannn!! 😀

Share

Be First to Comment

Leave a Reply

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