VirtueMart Forum

VirtueMart 2 + 3 + 4 => Templating & Layouts => Topic started by: kratzi on January 21, 2016, 23:31:23 PM

Title: Mobile page for shop with Mobile Detect
Post by: kratzi on January 21, 2016, 23:31:23 PM
Hi I am setting up my new shop under J 3.4.8 an VM 3.0.12

Since I could imagine this would be interesting for some others I will describe it more thoroughly.

I was looking for some time for a solution to offer my customers a desktop site and a mobile site under the same domain. I was not very much interested in a responsive template nor in http://domain.com and http://m.domain.com.
Also all available plugins had some issues and I found Mobile Detect "http://mobiledetect.net/" which detects if the user comes with a mobile device or not. There is also a Plugin from Yagendoo which uses this script.

Basically with this bit you can control your code:

<?php
if(MobileDetector::isMobile() === true)

?>


First I was looking for some code howto load a completely different template depending on the device but could not find any solution. Unfortunately my php skills are quite limited so if you would know a code how to control the template to load please let me know.

The only solution which I see at the moment is to control it the following:
For CSS

<?php
if(MobileDetector::isMobile() === false)
{
echo "<link rel='stylesheet' href='templates/template/css/template.css' type='text/css' />";
} else {
echo "<link rel='stylesheet' href='templates/template/css/mobile.css' type='text/css' />";
}
?>


For the <body> of the page in index.php


<?php
if(MobileDetector::isMobile() === false)

include (
"templates/template/template.php");
} else {
include (
"templates/template/mobile.php");
?>




So basically I load two different bodies in the index.php depending on the device.

My question is now if by this solution I could have any disadvantages with my site speed or possible any security issues. This is something I care about most.

Thank you

kratzi
Title: Re: Mobile page for shop with Mobile Detect
Post by: GJC Web Design on January 22, 2016, 00:18:49 AM
I see no reasons for security or load speed concerns

as another variation you could load the css separately and just swap two different parts of the template in the template index.php

why not responsive?  I am happy with my site designs incl. cart at all resolutions and only use responsive techniques..
My worry with mobile detect scripts is they can go out of date very easily where as screen sizes are screen sizes..
Title: Re: Mobile page for shop with Mobile Detect
Post by: kratzi on January 22, 2016, 15:22:47 PM
Thanks.

I understand your concerns however as I understood this script is updated regularly at the moment and also is not only detecting the screen size but has a huge list of mobile devices registered.

kratzi
Title: Re: Mobile page for shop with Mobile Detect
Post by: PRO on January 22, 2016, 17:09:50 PM
browser detection etc is standard in joomla

https://www.spiralscripts.co.uk/Joomla-Tips/browser-detection-in-joomla-3.html
https://api.joomla.org/cms-3/classes/JBrowser.html

&&   unless you are a very large company like wal mart, staples etc. which can overcome google problems easier. I would go with responsive design.

Title: Re: Mobile page for shop with Mobile Detect
Post by: Spiros Petrakis on January 22, 2016, 18:54:07 PM
Hi kratzi,

i use this script in my templates and they have several thousands installations with no issues reported so far , just make sure to update it when needed.