0

我一直在使用开源 AbanteCart 电子商务来销售产品,并且想知道是否有人知道有一种方法可以重定向模板以改用移动模板。

4

1 回答 1

0

我想最简单的方法是挂钩所有控制器并将新变量添加到包含 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';
    }

该变量 (sf) 由 core/init.php 文件中的引擎处理,并将桌面模板切换到移动设备。

于 2013-08-16T08:22:41.067 回答