Post by reynierpm » Tue Nov 29, 2011 6:14 am

Hi every:
This is a hot topic in this days and I need to build a template based on jQuery Mobile for my site. Build the template isn't the problem but show when someone navigate trough mobile devices is. I know I need to change some codes in OC core in order to do that but need some advice or help on this. First the place where the template is loaded is /system/engine/controller.php. This is the function:

Code: Select all

protected function render() {
		foreach ($this->children as $child) {
			$this -> data[basename($child)] = $this -> getChild($child);
		}

		if (file_exists(DIR_TEMPLATE . $this -> template)) {
			extract($this -> data);
			ob_start();
			require (DIR_TEMPLATE . $this -> template);
			$this -> output = ob_get_contents();
			ob_end_clean();
			return $this -> output;
		} else {
			exit('Error: Could not load template ' . DIR_TEMPLATE . $this -> template . '!');
		}
	}
Then I have a function called mobile_device_detect() that returns TRUE if device is mobile or FALSE otherwise. In the code above how I must call this function and then load another template folder and not default or the one that I have setup via admin? Any help on this?

Cheers and thanks in advance

User avatar
Active Member

Posts

Joined
Tue Jan 12, 2010 9:51 pm

Post by reynierpm » Tue Nov 29, 2011 7:18 am

Ok, I manage in how to deal to check if User Agent is Mobile Device or not and this is the result:

Code: Select all

protected function render() {
		foreach ($this->children as $child) {
			$this -> data[basename($child)] = $this -> getChild($child);
		}

		//--------- ADDED -------------------------------------------------
		if ($this -> config -> get('mobile_status') == 1) {
			if (($this -> isMobile() && $this -> config -> get('autodetect') == 'true') || $this -> session -> data['ismobile'] == 1) {
				$mobile_template = $this -> config -> get('mobile_template_name');
				if ($mobile_template != '') {
					if (!function_exists('is_dir') || (function_exists('is_dir') && is_dir(DIR_TEMPLATE . $mobile_template))) {
						$this -> template = $mobile_template . "/";
					}
				}
			}
		}
		//--------- ADDED -------------------------------------------------

		echo DIR_TEMPLATE . $this -> template;

		if (file_exists(DIR_TEMPLATE . $this -> template)) {
			extract($this -> data);
			ob_start();
			require (DIR_TEMPLATE . $this -> template);
			$this -> output = ob_get_contents();
			ob_end_clean();
			return $this -> output;
		} else {
			exit('Error: Could not load template ' . DIR_TEMPLATE . $this -> template . '!');
		}
	}
Now when I try to acces using a Mobile User Agent I get this error:
D:\Webserver\htdocs\portal/catalog/view/theme/libcommerce_mobile/Warning: require(D:\Webserver\htdocs\portal\catalog\view\theme\libcommerce_mobile) [function.require]: failed to open stream: Permission denied in D:\Webserver\htdocs\portal\system\engine\controller.php on line 77
Fatal error: require() [function.require]: Failed opening required 'D:\Webserver\htdocs\portal/catalog/view/theme/libcommerce_mobile/' (include_path='.;D:\Webserver\php\PEAR') in D:\Webserver\htdocs\portal\system\engine\controller.php on line 77
But surprise the directory exists and it's readable, any help on this? What I'm doing wrong?
Cheers one more time

User avatar
Active Member

Posts

Joined
Tue Jan 12, 2010 9:51 pm
Who is online

Users browsing this forum: Amazon [Bot], Bing [Bot] and 17 guests