联系电话:0755-27515592
最新动态:

zencart教程

zencart网站升级或者改版客户资料转移工具

点击数:558112016-11-04 09:06:23 来源: 外贸网站建设,深圳外贸网站建设,深圳网站建设,外贸商城网站制作-亿恩科技

新闻摘要:zencart网站升级或者改版客户资料转移工具

很久没给大家分享点有用的东西了,今天抽空写了一个zencart客户资料转移合并工具,感觉还是有点用的,就分享给大家
主要的用途就是就一个zencart网站的客户全部迁移到另一个网站
<?php
// +----------------------------------------------------------------------
// | Project:Zencart迁移升级(客户资料导入导出)
// +----------------------------------------------------------------------
// | Explanation:2016-11-1
// +----------------------------------------------------------------------
// | Version: V1.8
// +----------------------------------------------------------------------


header('Content-Type:text/html;charset=UTF-8');
require('includes/application_top.php');


function ez_get_customers_books($customers_id,$customers_default_address_id){
  global $db;
  $books_data=array();
  $books=$db->Execute("SELECT * FROM ".TABLE_ADDRESS_BOOK." WHERE customers_id=".$customers_id);
  while(!$books->EOF){
    $books->fields['primary'] = ($books->fields['address_book_id']==$customers_default_address_id) ? 1 : 0;
    $books_data[]=$books->fields;
    $books->MoveNext();
  }
  return $books_data;
}


function ez_get_customers_info($customers_id){
  global $db;
  $customers_info=$db->Execute("SELECT * FROM ".TABLE_CUSTOMERS_INFO." WHERE customers_info_id=".$customers_id);
  unset($customers_info->fields['customers_info_id']);
  return $customers_info->fields;
}


$customers_data=array();


//导出
if($_GET['toolaction']=='export'){
  $customers = $db->Execute("SELECT * FROM ".TABLE_CUSTOMERS);


  while(!$customers->EOF){
    $customers->fields['books']=ez_get_customers_books($customers->fields['customers_id'],$customers->fields['customers_default_address_id']);
    $customers->fields['customers_info']=ez_get_customers_info($customers->fields['customers_id']);
    $customers_data[$customers->fields['customers_email_address']]=$customers->fields;
    $customers->MoveNext();
  }
  file_put_contents(DIR_FS_SQL_CACHE.'/customers_data.log', json_encode($customers_data));
  echo '导出成功';
  exit;
}

//导入
if($_GET['toolaction']=='import'){
  if(!file_exists(DIR_FS_SQL_CACHE.'/customers_data.log')) {echo '客户资料文件不存在';die;}
  $customers_data_json=file_get_contents(DIR_FS_SQL_CACHE.'/customers_data.log');
  $customers_data=json_decode($customers_data_json,true);
  foreach($customers_data as $email_address => $email_data){


    $check_email_query = "select count(*) as total
                            from " . TABLE_CUSTOMERS . "
                            where customers_email_address = '" . $email_address . "'";
    $check_email = $db->Execute($check_email_query);
    if ($check_email->fields['total'] > 0) continue;  //邮箱已存在跳出


    $book_data=$email_data['books'];
    $customers_info=$email_data['customers_info'];


    unset($email_data['books'],$email_data['customers_id'],$email_data['customers_info']);


    //插入客户表
    zen_db_perform(TABLE_CUSTOMERS, $email_data);
    $customers_id = $db->Insert_ID();


    //插入客户信息表
    $customers_info['customers_info_id']=$customers_id;
    zen_db_perform(TABLE_CUSTOMERS_INFO, $customers_info);


    //插入地址表
    foreach($book_data as $book){
      $book['customers_id']=$customers_id;
      unset($book['address_book_id']);
      $primary= ($book['primary']==1) ? 1 : 0;
      unset($book['primary'],$book['address_book_id']);


      zen_db_perform(TABLE_ADDRESS_BOOK, $book);
      $books_id = $db->Insert_ID();


      //更新客户表默认地址
      if($primary==1)  $db->Execute("UPDATE ".TABLE_CUSTOMERS." SET customers_default_address_id=".$books_id." WHERE customers_id=".$customers_id);
    }
  }
  echo '导入成功';
  exit;
}
?>
<a href="?toolaction=export">导出</a>
<a href="?toolaction=import">导入</a>
使用方法很简单,只用将文件上传到网站根目录,然后浏览器运行http://www.abc.com/customers_populate.php,导出后将cache/customers_data.log转移到另一个站的cache下,然后执行导入
【责任编辑:(Top) 返回页面顶端
贴心
全国7×24小时客服热线
安全
病毒杀除率高于99%
稳定
网站可用性高于99.9%
实力
服务68家上市企业及集团公司
亿恩科技手机站
关注亿恩科技微信

亿恩科技—企业信息化一站式服务专家


Copyright © 2008- 深圳市亿恩科技有限公司版权所有 粤ICP备15056041号

联系我们 | 常见问题 | 在线留言 | 支付方式 | 软件开发 | 我的观点 | 资质荣誉 | 服务流程