ecshop 手机模板的定制化改造

更新日期: 2016-10-19 阅读次数: 10496 分类: ecshop

ecshop 这个圈子真是太乱了,网上查到的资料几乎没有可信度,还是的一点一点自己摸索。

手机模板的触发逻辑

项目根目录 index.php

$ua = strtolower($_SERVER['HTTP_USER_AGENT']);

$uachar = "/(nokia|sony|ericsson|mot|samsung|sgh|lg|philips|panasonic|alcatel|lenovo|cldc|midp|mobile|android|iphone)/i";

if(($ua == '' || preg_match($uachar, $ua))&& !strpos(strtolower($_SERVER['REQUEST_URI']),'wap'))
{
    $Loaction = 'mobile/';

    if (!empty($Loaction))
    {
        ecs_header("Location: $Loaction\n");

        exit;
    }

}

不知道是什么时候的代码,android, iphone 并没有提及,我手动加上的。

修改哪里的代码

从手机模板的触发逻辑看,就知道对应的代码在根目录的 mobile 下。

从网上下载了一个 ecshop 京东的手机自适应模板,解压之后就是一个 mobile 文件夹,说明就是这个目录。

比较不方便的地方是,mobile 模板并不能像 PC 主题一样在管理后台随意切换,只能代码覆盖,非常不友好。 如果想保留多套手机模板,只能使用软链接的方式了,这算是一个折中方案。

根目录下的 WAP 与 mobile 有什么区别呢

mobile 是 ecshop WAP 的进化版,增加了购物流程。可以理解为 WAP 已经被废弃,使用 mobile 即可。

Warning: Invalid argument supplied for foreach() in ../mobile/index.php on line 81

使用 get_categories_tree_home 替换掉 get_categories_tree

function get_categories_tree_home($cat_id = 0)
{
    if ($cat_id > 0)
    {
        $sql = 'SELECT parent_id FROM ' . $GLOBALS['ecs']->table('category') . " WHERE cat_id = '$cat_id'";
        $parent_id = $GLOBALS['db']->getOne($sql);
    }
    else
    {
        $parent_id = 0;
    }
    /*
     判断当前分类中全是是否是底级分类,
     如果是取出底级分类上级分类,
     如果不是取当前分类及其下的子分类
    */
    $sql = 'SELECT count(*) FROM ' . $GLOBALS['ecs']->table('category') . " WHERE parent_id = '$parent_id' AND is_show = 1 ";
    if ($GLOBALS['db']->getOne($sql) || $parent_id == 0)
    {
        /* 获取当前分类及其子分类 */
			$sql = 'SELECT cat_id,cat_name ,parent_id,is_show ' .
					'FROM ' . $GLOBALS['ecs']->table('category') .
					"WHERE parent_id = '$parent_id' AND is_show = 1 ORDER BY sort_order ASC, cat_id ASC";

        $res = $GLOBALS['db']->getAll($sql);

        foreach ($res AS $row)
        {
            if ($row['is_show'])
            {
                $cat_arr[$row['cat_id']]['id']   = $row['cat_id'];
                $cat_arr[$row['cat_id']]['name'] = $row['cat_name'];
                $cat_arr[$row['cat_id']]['url']  = build_uri('category', array('cid' => $row['cat_id']), $row['cat_name']);

                if (isset($row['cat_id']) != NULL)
                {
                    $cat_arr[$row['cat_id']]['cat_id'] = get_child_tree($row['cat_id']);
                }
            }
        }
    }
    if(isset($cat_arr))
    {
        return $cat_arr;
    }
}

首页幻灯片广告 banner 不显示

js 报错

(index):48 Uncaught SyntaxError: missing ) after argument list

作者比较脑残,直接把整个 banner 效果重写即可。 因为这里是写死的两个轮播图。

ecshop 京东模板轮播 banner

Warning: Invalid argument supplied for foreach() in ../mobile/category.php on line 24

依旧是使用 get_categories_tree_home 替换掉 get_categories_tree.

common.js:34 Uncaught TypeError: goods.toJSONString is not a function(…)

// TODO

关于作者 🌱

我是来自山东烟台的一名开发者,有敢兴趣的话题,或者软件开发需求,欢迎加微信 zhongwei 聊聊, 查看更多联系方式