首页 > 代码库 > 大型ECShop安装搬家升级错误问题最全攻略

大型ECShop安装搬家升级错误问题最全攻略

【引子】

        最近将ECShop框架网站从租用服务器搬家至阿里云,虽然模块及功能上已经被修改的面目全非了,但基础部分还在。

在这个过程中遇到了很多的WARNING与ERROR,解决方案如下。

【环境】

        服务器环境由PHP5.3+MySQL5.6更新至PHP5.6+MySQL5.7

【数据库】

        利用navicat for mysql工具导入导出,出现异常:Invalid default value for ‘create_time‘,具体可参考上一篇随笔。http://www.cnblogs.com/eDevelop/p/7081061.html

【后台】

打开首页报错,提示:Strict standards: Non-static method cls_image::gd_version() should not be called statically in includes\lib_base.php on line 355

return cls_image::gd_version();

对象可以访问静态方法,使用的是$p->function(),对象访问静态属性采用p::function()形式。

$cimage=new cls_image();return $cimage->gd_version();
类似还有:
Strict standards: Non-static method cls_sql_dump::get_random_name() should not be called statically in admin\database.php on line 64
$smarty->assign(‘sql_name‘, cls_sql_dump::get_random_name() . ‘.sql‘);
修改为:
$csdump=new cls_sql_dump($db,$max_size);
$smarty->assign(‘sql_name‘, $csdump->get_random_name() . ‘.sql‘);
嫌麻烦直接找到function get_random_name()函数,前面加个static完事。

个人设置:

Strict standards: Only variables should be passed by reference in includes\cls_template.php on line 422$tag_sel = array_shift(explode(‘ ‘, $tag));

调用函数传参错误

$p=explode(‘ ‘, $tag);$tag_sel = array_shift($p);

 商品分类:

 Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead inincludes\cls_template.php on line 304 
return preg_replace("/{([^\}\{\n]*)}/e", "\$this->select(‘\\1‘);", $source);

PHP升级5.5之后,摒弃了preg_replace的/e特性。

return preg_replace_callback("/{([^\}\{\n]*)}/", function($func) { return $this->select($func[1]); }, $source);

问题集中在cls_template中。

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in includes\cls_template.php on line 554$val = preg_replace("/\[([^\[\]]*)\]/eis", "‘.‘.str_replace(‘$‘,‘\$‘,‘\\1‘)", $val);修改为:$val = preg_replace_callback(‘/\[([^\[\]]*)\]/is‘,function ($matches) {return ‘.‘.str_replace(‘$‘,‘\$‘,$matches[1]);},$val);
Deprecated
: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in includes\cls_template.php on line 491 $out = "<?php \n" . ‘$k = ‘ . preg_replace("/(\‘\\$[^,]+)/e" , "stripslashes(trim(‘\\1‘,‘\‘‘));", var_export($t, true)) . ";\n";
修改为:
$out = "<?php " . ‘$k = ‘ . preg_replace_callback("/(\‘\\$[^,] )/" , function($match){return stripslashes(trim($match[1],‘\‘‘));},
var_export($t, true)) . ";\n";
Deprecated
: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in includes\cls_template.php on line 1074$pattern = ‘/<!--\s#BeginLibraryItem\s\"\/(.*?)\"\s-->.*?<!--\s#EndLibraryItem\s-->/se‘;$replacement = "‘{include file=‘.strtolower(‘\\1‘). ‘}‘";$source = preg_replace($pattern, $replacement, $source);修改为:
$pattern = ‘/<!--\s#BeginLibraryItem\s\"\/(.*?)\"\s-->.*?<!--\s#EndLibraryItem\s-->/s‘;
$source = preg_replace_callback($pattern, function ($func){return ‘{include file=‘.strtolower($func[1]).‘}‘;},$source);
历史订单:查看->配送方式:编辑
Warning: Illegal string offset ‘free_money‘ in admin\order.php on line 3696
使用$shipping[‘configure‘][‘free_money‘]形式,要求$shipping[‘configure‘]为数组,可以引入IF判断解决if(is_array($shipping[‘configure‘])){...}
Warning
: number_format() expects parameter 1 to be double, string given in includes\lib_common.php on line 1019
虽然ECShop2.7.3对参数$price进行判断是否为空,但配送插件里面的免费额度为0,ec本身的bug导致了$price的值为空值,直接调用number_format出现了错误。
在PHP5.3上报错,但获取到的应该是一个字符串,所以出错,应该这样改:
$price = 0 + $price;//添加这一行,转换成数值

 商店设置:

Strict standards: mktime(): You should be using the time() function instead in admin\sms_url.php on line 31Strict standards: mktime(): You should be using the time() function instead in admin\shop_config.php on line 32mktime()方法不带参数被调用时,会被抛出一个报错提示。$auth=mktime();修改为:$autu=time();

管理员权限与角色管理:

Warning: join(): Invalid arguments passed in admin\privilege.php on line 602Warning: Invalid argument supplied for foreach() in admin\privilege.php on line 604Warning: join(): Invalid arguments passed in admin\role.php on line 217Warning: Invalid argument supplied for foreach() in admin\role.php on line 219
这里与上上个错误类似,数组类型取值才不会警告。使用if(is_array($action_group[‘priv‘])){}将join与foreach代码段包进去。
网上给出方案如下,感觉大同小异。
if(is_array($action_group[‘priv‘])){
$action_group[‘priv‘] = $action_group[‘priv‘];
}else{
$action_group[‘priv‘] = array();
}
自定义导航栏也报错:
Warning: Illegal string offset ‘cat_name‘ in admin\navigator.php on line 383
if(is_array($val)){...}

角色管理与权限管理:只有checkbox选框,没有label文字

锁定privilege_allot.htm与role_info.htm,修改如下:$lang[$priv.action_code]->$lang.$priv.action_code$lang[$list.action_code]->$lang.$list.action_code

数据备份:

Strict standards: Redefining already defined constructor for class cls_sql_dump in admin\includes\cls_sql_dump.php on line 90

类似还有支付方式:

Strict Standards: Redefining already defined constructor for class chinabank in includes/modules/payment/chinabank.php on line 85Strict Standards: Redefining already defined constructor for class paypal_ec in includes/modules/payment/paypal_ec.php on line 96Strict Standards: Redefining already defined constructor for class shenzhou in includes/modules/payment/shenzhou.php on line 81Strict Standards: Redefining already defined constructor for class ips in includes/modules/payment/ips.php on line 82Strict Standards: Redefining already defined constructor for class balance in includes/modules/payment/balance.php on line 79Strict Standards: Redefining already defined constructor for class alipay in includes/modules/payment/alipay.php on line 85Strict Standards: Redefining already defined constructor for class tenpay in includes/modules/payment/tenpay.php on line 83Strict Standards: Redefining already defined constructor for class post in includes/modules/payment/post.php on line 79Strict Standards: Redefining already defined constructor for class paypal in includes/modules/payment/paypal.php on line 82Strict Standards: Redefining already defined constructor for class tenpayc2c in includes/modules/payment/tenpayc2c.php on line 83Strict Standards: Redefining already defined constructor for class cappay in includes/modules/payment/cappay.php on line 81Strict Standards: Redefining already defined constructor for class bank in includes/modules/payment/bank.php on line 79Strict Standards: Redefining already defined constructor for class kuaiqian in includes/modules/payment/kuaiqian.php on line 83Strict Standards: Redefining already defined constructor for class cod in includes/modules/payment/cod.php on line 82

使用和类名相同点函数名作为构造函数是php4时代的写法,php5时代的构造函数是__construct(),ecshop为了兼容老版本的php,所以采用了上面的写法。
但是从php5.4开始,对于这样的两种写法同时出现的情况,要求必须__construct()在前,同名函数在后,所以只需要对调两个函数的位置即可。

如alipay.php,将    function __construct()    {        $this->alipay();    }放到    function alipay()    {    }前面。

首页广告管理:

Strict standards: Only variables should be passed by reference in admin\flashplay.php on line 274传参时赋值,偷懒了。set_flash_data($_CFG[‘flash_theme‘], $error_msg = ‘‘);
修改为:
$error_msg = ‘‘set_flash_data($_CFG[‘flash_theme‘], $error_msg);

后台翻页功能失效,弹出 transport.js /run() error:undefined。

FF调试报错:Uncaught transport.js/parseResult() error: can‘t parse to JSON. 

ECShop把AJAX事件和JSON解析的模块放在common/transport.js之中,在封装JSON各种方法的同时对object的模型进行了重写,跟jQuery冲突!

ECShop论坛上提出了一些办法,不是很好用。

1、首先复制一份 transport.js 改名为 transport.org.js 提供给后台使用2、屏蔽掉transport.js里的toJSON功能,注释掉行数大概在497-737行之间的内容,从if ( ! Object.prototype.toJSONString)开始  修改352行为: legalParams = "JSON=" + $.toJSON(params);  修改408行为:result = $.evalJSON(result);  屏蔽掉global.js里的如下代码(第10-13行):  Object.prototype.extend = function(object)  {    return Object.extend.apply(this, [this, object]);  }3、修改index.js文件44行为:var res = $.evalJSON(result);4、修改common.js文件34行为:Ajax.call(‘flow.php?step=add_to_cart‘, ‘goods=‘ + $.toJSON(goods), addToCartResponse, ‘POST‘, ‘JSON‘);
  修改850行为
:Ajax.call(‘flow.php?step=add_package_to_cart‘, ‘package_info=‘ + $.toJSON(package_info), addPackageToCartResponse, ‘POST‘, ‘JSON‘);
  修改1056行为
:Ajax.call(‘flow.php?step=add_to_cart‘, ‘goods=‘ + $.toJSON(goods), addToCartResponse, ‘POST‘, ‘JSON‘);5、修改compare.js文件49行为: this.data = http://www.mamicode.com/$.evalJSON(cookieValue);  修改67行为: var obj = $.evalJSON(cookieValue);  修改133行为: document.setCookie("compareItems", $.toJSON(this.data));6、修改global.js文件  修改16行函数名 :function $e()  修改114和126行为:var element = $e(element);7、修改后台头部引入transport.js路径
 admin/templates/pageheader.htm 第9行改为: {insert_scripts files="../js/transport.org.js,common.js"}  admin/templates/menu.htm 第151行改为: {insert_scripts files="../js/global.js,../js/utils.js,../js/transport.org.js"}8、修改themes/default/library/page_header.lbi文件在{insert_scripts files=‘transport.js,utils.js‘}上面加上:
  {insert_scripts files
=‘jquery.js,jquery.json.js‘}  jquery.json.js下载9、修改library/comment_list.lbi 188行为:   Ajax.call(‘comment.php‘, ‘cmt=‘ + $.toJSON(cmt), commentResponse, ‘POST‘, ‘JSON‘);10、修改compare.dwt 20行为:  var obj = $.evalJSON(document.getCookie("compareItems"));  24行: document.setCookie("compareItems", $.toJSON(obj));11、修改flow.dwt 138行为:  Ajax.call(‘flow.php?step=add_to_cart‘, ‘goods=‘ + $.toJSON(goods),collect_to_flow_response, ‘POST‘, ‘JSON‘);  199行: Ajax.call(‘flow.php?step=add_to_cart‘, ‘goods=‘ + $.toJSON(goods),fittings_to_flow_response, ‘POST‘, ‘JSON‘);12、修改brand.dwt、brand_list.dwt、category.dwt、exchange_list.dwt、search.dwt文件,增加  {insert_scripts files=‘jquery.js,jquery.json.js‘}  {insert_scripts files=‘common.js,global.js,compare.js‘}
注意:包括其他jquery文件需置顶的dwt文件,jquery.js文件需要在compare.js文件加载前加载

大概思路就是屏蔽ECshop扩展的toJSONString方法,用别的函数代替。

大型ECShop安装搬家升级错误问题最全攻略