我一直在使用开源的AbanteCart电子商务来销售产品,我想知道是否有人知道有一种方法可以重定向模板以使用移动模板。
我想最简单的方法是挂接所有控制器,并将新变量添加到包含template_text_id的请求(sf)中。。。加上使用cookie模板模式(桌面或手机)。
/**
* redirect to mobile template if we load page in mobile device
**/
public function onAHook_InitEnd() {
if ( $this->_processHooks() ) return;
$device = $this->baseObject->request->getDeviceType();
if ( !empty($device) && empty( $this->baseObject->request->cookie['abantecart_mobile_redirect'] ) ) {
//set flag that redirect was done
setcookie("abantecart_mobile_redirect", "1", time() + 3600*24);
//set template to mobile
$url = $this->baseObject->html->removeQueryVar($_SERVER['REQUEST_URI'], 'sf');
$url .= '&sf=your_mobile_template_text_id';
header ( 'Location: '. $url );
}
}
private function _processHooks(){
return $this->registry->get('config')->get('config_storefront_template') == 'your_mobile_template_text_id';
}
引擎在core/init.php文件中处理的那个变量(sf),并将桌面模板切换到mobile。