zencart动态增加注册项目功能

2012-11-11 23:55 来源:www.chinab4c.com 作者:zencart专家

 zencart动态增加注册项目功能,这个就是我们常见的ecshop的里面很成熟的功能。就是在注册的功能里面。动态的增加注册的项目,在zencart注册的时候,动态注册的内容,可以在注册页面随便的增加注册项目.

 1:增加2个表,控制注册项目以及内容。

    CREATE TABLE `zen_reg_extend_info` (
  `Id` int(10) unsigned NOT NULL auto_increment,
  `user_id` mediumint(8) unsigned NOT NULL,
  `reg_field_id` int(10) unsigned NOT NULL,
  `content` text NOT NULL,
  PRIMARY KEY  (`Id`)
) ENGINE=MyISAM AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;

  CREATE TABLE `zen_reg_fields` (
  `id` tinyint(3) unsigned NOT NULL auto_increment,
  `reg_field_name` varchar(60) NOT NULL,
  `dis_order` tinyint(3) unsigned NOT NULL default '100',
  `display` tinyint(1) unsigned NOT NULL default '1',
  `type` tinyint(1) unsigned NOT NULL default '0',
  `is_need` tinyint(1) unsigned NOT NULL default '1',
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=100 DEFAULT CHARSET=utf8;

  2:增加注册管理

  $reg_field_need = zen_db_prepare_input(($_POST['reg_field_need']));
        $reg_field_display = zen_db_prepare_input(($_POST['reg_field_display']));
        $reg_field_name1 = zen_db_prepare_input($_POST['reg_field_name']);
  
        $display = zen_db_prepare_input($_POST['display']);
  
  $id = zen_db_prepare_input($_POST['id']);
      
      if (strlen($reg_field_name1) < 2) {
          $error = true;
          $reg_field_name = true;
        } else {
          $reg_field_name = false;
        }
    if ($error == false) {

        $sql_data_array = array('is_need' => $reg_field_need,
                                'display' => $reg_field_display,
                                'reg_field_name' => $reg_field_name1,
                                'dis_order' => $display
                             
                                );

       

        zen_db_perform(TABLE_REG_EXTEND, $sql_data_array, 'update', "id = '" . (int)$id . "'");

  3:注册页面增加此功能

  $sql = "select * from  " .TABLE_REG_EXTEND." WHERE  display = 1 ORDER BY dis_order, id";
  $res = $db->Execute($sql);
  $extend_field_str = '';    //生成扩展字段的内容字符串
  while(!$res->EOF){
 
 $extend_field_index = 'extend_field' . $res->fields['id'];
    if(!empty($_POST[$extend_field_index])){
  
           $temp_field_content = strlen($_POST[$extend_field_index]) > 100 ? substr($_POST[$extend_field_index], 0, 99) : $_POST[$extend_field_index];
           $extend_field_str .= " ('" . $_SESSION['customer_id'] . "', '" . $res->fields['id'] . "', '" . $temp_field_content . "'),";
     }
 $res->MoveNext();

  }
   $extend_field_str = substr($extend_field_str, 0, -1);
  
 if ($extend_field_str)      //插入注册扩展数据
     {
               $sql = 'INSERT INTO '. TABLE_REG_EXTEND_INFO . ' (`user_id`, `reg_field_id`, `content`) VALUES' . $extend_field_str;
                $db->Execute($sql);
    }

 来源:http://www.chinab4c.com

来源于香港公司注册管理专家