ECshop商城导入淘宝数据包出现乱码问题
更新时间:2016-08-03 点击量:2561
Tag关键词: 商城 ecshop模板 ecshop4.0模板 二次开发 ecshop3.6模板 ecshop小程序
部分用户在ecshop导入淘宝数据包的时候出现数据乱码。优易软件在多次测试后,整理出该问题的解决方法,现分享给大家
测试版本 ecshop2.73
利用淘宝助手导出一个数据包(.csv),不要一次全部商品导出,最好是将数据包控制在1M左右,因为ecshop对上传文件有限制。
1、用编辑器打开文件goods_batch.php,文件在admin文件夹下,找到
$data=file($_FILES['file']['tmp_name']);
并将此行注释掉。在下边加上
$data0=mb_convert_encoding(file_get_contents($_FILES['file']['tmp_name']),"utf-8","UTF-16LE");注:utf-8是ecshop的版本编码,如果是gbk则这里是gbk
2、继续添加代码
$data=str_replace("\"\"","\"",$data0); $data=explode('优易软件,$data);
优易软件是店铺的名字,将这个换成你店铺的名字即可。
3、这里开始要特别注意,因为csv文件的开头有一部分说明,所以要针对首行特别处理。
复制代码
if($k==0){ $goods_name_arr = explode('"',$line_list[98]); $goods_name = $goods_name_arr[1]; $shop_price = $line_list[105]; $goods_number = $line_list[107]; $imgsstr = $line_list[126]; $goods_desc =str_replace("\"","'",substr($line_list[118],1,strlen($line_list[118])-2)); }else{$goods_name_arr = explode('"',$line_list[10]); $goods_name = $goods_name_arr[1]; //$goods_name = trim($line_list[10],'"'); $shop_price = $line_list[17]; $goods_number = $line_list[19]; $imgsstr = $line_list[38]; $goods_desc = str_replace("\"","'",substr($line_list[30],1,strlen($line_list[30])-2)); }复制代码
这里的$line_list[]可能会因为店铺商品属性不一样导致数据提取错误,可以先print_r($line_list)然后修改错误的数组下标。
4、到了这里数据的提取基本上完成了,下面就要对提取的数据进行处理并赋值给数组。其实也只是图片的数据需要处理一下,具体如下:
复制代码
$imgasd=str_replace("\"","",$imgsstr); $imgasd=explode(";",$imgasd); foreach($imgasd as $ks=>$vs){ if($ks!=count($imgasd)-1){ $nv=explode("|",$vs); $in=explode(":",$nv[0]); $imgs_u.=$in[0].".jpg;"; } } $arr['original_img'] = $imgs_u;
复制代码
5、最后要处理的数据就是图片的路径。找到
if (!empty($field_arr['original_img']))
的位置,有这里开始注释,一直到//修改商品图这里,然后再注释//添加商品相册图下面的if代码。
如果文章对您有帮助,就打赏一个吧