Magento mobile switching logic

I went down the path of building a magento mobile phone. I first started using simple magento config theme exceptions to display the mobile theme to visitors with mobile browsers until I realized that I really needed to create a new theme-only store view. There are several extensions that I need to disable using the mobile site.

So I have my mobile site, m.website.no and my main site, www.website.no - I have a code in index.php that launches magento with the store code for a mobile site or main site depending on the software request. It is also redirected to the mobile site if a mobile user agent is detected.

It's all very well now to make a mobile site and redirect visitors to it based on a user agent, but what if they want to look at the desktop? One makes a link to the main site, right? It will go to www.website.no, but then the visitor will loop back to the mobile site ... so the next logical step is to set a variable like this: www.website.no/?desktop=1. If I want it to be inserted, then I have to put that in a session variable or a cookie or something.

My problem is in index.php, magento is not even loaded! So how do I set up a setting or get a session variable using magento (for example Mage::getSingleton('core/session')->setIsDesktop(true);

) before it is loaded? Am I completely wrong about this? Should I extend magento or something that it switches storage if the user specifically requested the main site? Giant headache.

+3


source to share


2 answers


I solved this by creating a new extension and forcing magento to switch storage after initializing it.



-2


source


duplicate your index.php to (for example) index_mobile.php

add the following script to the first index_mobile.php file to force change the user agent as desktop

$_SERVER['HTTP_USER_AGENT'] = 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.66 Safari/537.36';

      



now create a hyperlink to yoursite.com/index_mobile.php

<a href="yoursite.com/index_mobile.php">view desktop site</a>

      

good luck !!: D

+1


source







All Articles