It’s said “probably” because unlike 1.5.0.9 Prestashop version, the latest 1.5.0.13 version (released on June, 7) has no methods for mobile device detection. Changelog in version 1.5.0.13 says nothing about it while Changelog in version 1.5.0.9 reports:
Improved/changed features:
[*] FO : Add mobile detection and mobile theme dispatcher
Where does the truth lie? We, folks, are confused. Anyways, I really hope that a mobile theme is not ready yet and developers will be given a nice present with a final version release.
So let’s see how methods worked in Prestashop 1.5.0.9.
A new config/defines_uri.inc.php file has appeared with the following code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
/* For mobile devices */ if (file_exists(_PS_THEME_DIR_.'mobile/')) { define('_PS_THEME_MOBILE_DIR_', _PS_THEME_DIR_.'mobile/'); define('_THEME_MOBILE_DIR_', _THEMES_DIR_._THEME_NAME_.'/mobile/'); } else { define('_PS_THEME_MOBILE_DIR_', _PS_ROOT_DIR_.'/themes/default/mobile/'); define('_THEME_MOBILE_DIR_', __PS_BASE_URI__.'themes/default/mobile/'); } define('_THEME_MOBILE_IMG_DIR_', _THEME_MOBILE_DIR_.'img/'); define('_THEME_MOBILE_CSS_DIR_', _THEME_MOBILE_DIR_.'css/'); define('_THEME_MOBILE_JS_DIR_', _THEME_MOBILE_DIR_.'js/'); /* For touch pad devices */ define('_PS_THEME_TOUCHPAD_DIR_', _PS_THEME_DIR_.'touchpad/'); define('_THEME_TOUCHPAD_DIR_', _THEMES_DIR_._THEME_NAME_.'/touchpad/'); define('_THEME_TOUCHPAD_CSS_DIR_', _THEME_MOBILE_DIR_.'css/'); define('_THEME_TOUCHPAD_JS_DIR_', _THEME_MOBILE_DIR_.'js/'); |
This code above suggests that the theme should be available on FTP at «_PS_THEME_DIR_.’mobile/’» or «_PS_ROOT_DIR_.’/themes/default/mobile/» addresses to work properly. In addition, «img/», «css/», «js/» directories are provided for mobile themes.
Context::getMobileDevice() function is in charge of mobile device identification.
1 2 3 4 5 6 7 8 9 10 11 12 |
public function getMobileDevice() { if (is_null($this->mobile_device)) { $this->mobile_device = false; if ($this->checkMobileContext()) if (preg_match('/(alcatel|amoi|android|avantgo|blackberry|benq|cell|cricket|docomo|elaine|htc|iemobile|iphone|ipaq|ipod|j2me|java|midp|mini|mmp|mobi\s|motorola|nec-|nokia|palm|panasonic|philips|phone|sagem|sharp|sie-|smartphone|sony|symbian|t-mobile|telus|up\.browser|up\.link|vodafone|wap|webos|wireless|xda|zte)/i', $_SERVER['HTTP_USER_AGENT'], $out)) $this->mobile_device = $out[0]; } return $this->mobile_device; } |
The identification of whether this device is mobile will be conducted after comparing «HTTP_USER_AGENT» with a predefined pattern that contains header parts of the majority of mobile devices.
Let’s see where «getMobileDevice» function is used:
grep -rH “getMobileDevice” ./classes
./classes/controller/FrontController.php: ‘mobile_device’ => $this->context->getMobileDevice(),
./classes/controller/FrontController.php: if ($this->context->getMobileDevice() != false)
./classes/controller/FrontController.php: if ($this->context->getMobileDevice() != false)
./classes/controller/FrontController.php: if ($this->context->getMobileDevice() != false)
./classes/controller/FrontController.php: if ($this->context->getMobileDevice() == false)
./classes/controller/FrontController.php: if ($this->context->getMobileDevice() == false && Tools::isSubmit(‘live_edit’))
./classes/controller/FrontController.php: if ($this->context->getMobileDevice() != false || file_exists(_PS_THEME_DIR_.’layout.tpl’))
./classes/controller/FrontController.php: $template_dir = ($this->context->getMobileDevice() == true ? _PS_THEME_MOBILE_DIR_ : _PS_THEME_DIR_);
./classes/controller/FrontController.php: if ($this->context->getMobileDevice() != false)
./classes/controller/FrontController.php: if ($this->context->getMobileDevice() != false)
./classes/Context.php: public function getMobileDevice()
This function is mainly used in classes/controller/FrontController.php:
1 2 3 4 5 6 7 8 9 10 11 12 |
… /** * This is overrided to manage is behaviour * if a customer access to the site with mobile device. */ public function setTemplate($template) { if ($this->context->getMobileDevice() != false) $this->setMobileTemplate($template); else parent::setTemplate($template); } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
/** * Specific medias for mobile device. */ public function setMobileMedia() { $this->addCSS(_THEME_MOBILE_CSS_DIR_.'global.css', 'all'); $this->addCSS(_THEME_MOBILE_CSS_DIR_.'jqm-docs.css', 'all'); $this->addJS(_THEME_MOBILE_JS_DIR_.'jqm-docs.js'); $this->addJS(_PS_JS_DIR_.'tools.js'); $this->addJS(_THEME_MOBILE_JS_DIR_.'global.js'); $this->addjqueryPlugin('fancybox'); } public function setMedia() { // if website is accessed by mobile device // @see FrontControllerCore::setMobileMedia() if ($this->context->getMobileDevice() != false) { $this->setMobileMedia(); return true; } $this->addCSS(_THEME_CSS_DIR_.'global.css', 'all'); $this->addjquery(); $this->addjqueryPlugin('easing'); $this->addJS(_PS_JS_DIR_.'tools.js'); … |
Context:: getTouchPadDevice() function may also seem pretty interesting:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
protected function getTouchPadDevice() { if (is_null($this->touchpad_device)) { $this->touchpad_device = false; if ($this->checkMobileContext()) { if (preg_match('/(xoom|ipad)/i', $_SERVER['HTTP_USER_AGENT'], $out)) $this->touchpad_device = $out[0]; if (strpos(strtolower($_SERVER['HTTP_USER_AGENT']), 'android') && !strpos(strtolower($_SERVER['HTTP_USER_AGENT']), 'mobile')) $this->touchpad_device = 'android'; // for Galaxy tab if (strpos(strtolower($_SERVER['HTTP_USER_AGENT']), 'android') && (strpos(strtolower($_SERVER['HTTP_USER_AGENT']), 'sch-i800') || strpos(strtolower($_SERVER['HTTP_USER_AGENT']), 'gt-p1000'))) $this->touchpad_device = 'android'; } } return $this->touchpad_device; } |
This function returns the type of the touchpad device. We can expect that Prestashop will probably distinguish mobile devices form touchpad ones.
Unfortunately, I haven’t found where this function is used. Perhaps, it will be applied somehow in the future.
Hi Pegen,
Thanks for your comment. It makes sense.
Hi Alex,
you can activate the mobile-theme by adding ‘PS_ALLOW_MOBILE_DEVICE’ = 1 to the configuration table. Make sure you got the template-files: /theme/default/mobile/
.. or patch the getMobileDevice()-function on line 118 (/classes/Context.php) change:
return $this->mobile_device; to return ‘iphone’;
regards,
Pegen