你现在的位置:首页 > opencart 正文

opencart开发之添加新注册项

在使用opencart的过程中,我们可能需要让用户注册时多出几个注册项,应该怎么办呢?

\

首先在customer表新增两个字段:

1.名称:biey
  类型:TINYINT
  长度:1

2.名称:date_birth
  类型:date
  预设:定义 0000-00-00

1.catalog\controller\account\edit.php
1.1.Search
$this->data['entry_fax'] = $this->language->get('entry_fax');

Add
$this->data['entry_biey'] = $this->language->get('entry_biey');
                $this->data['entry_date_birth'] = $this->language->get('entry_date_birth');

1.2.Search
if (isset($this->request->post['fax'])) {
                        $this->data['fax'] = $this->request->post['fax'];
                } elseif (isset($customer_info)) {
                        $this->data['fax'] = $customer_info['fax'];
                } else {
                        $this->data['fax'] = '';
                }

Add
if (isset($this->request->post['biey'])) {
                        $this->data['biey'] = $this->request->post['biey'];
                } elseif (isset($customer_info)) {
                        $this->data['biey'] = $customer_info['biey'];
                } else {
                        $this->data['biey'] = '';
                }

                if (isset($this->request->post['date_birth'])) {
                        $this->data['date_birth'] = $this->request->post['date_birth'];
                } elseif (isset($customer_info)) {
                        $this->data['date_birth'] = $customer_info['date_birth'];
                } else {
                        $this->data['date_birth'] = '';
                }

 


2.catalog\controller\account\register.php
2.1.Search
$this->data['entry_confirm'] = $this->language->get('entry_confirm');

Add
$this->data['entry_biey'] = $this->language->get('entry_biey');
                $this->data['entry_date_birth'] = $this->language->get('entry_date_birth');

 

2.1.Search
if (isset($this->request->post['company'])) {
                    $this->data['company'] = $this->request->post['company'];
                } else {
                        $this->data['company'] = '';
                }

Add
if (isset($this->request->post['biey'])) {
                    $this->data['biey'] = $this->request->post['biey'];
                } else {
                        $this->data['biey'] = '';
                }        
                
                if (isset($this->request->post['date_birth'])) {
                       $this->data['date_birth'] = $this->request->post['date_birth'];                
                } else {
                        $this->data['date_birth'] = date('2012-01-01');
                }

 

3.语言文件edit.php
3.1.Search
$_['entry_fax']           = ' 传真号码:';

Add
$_['entry_biey']          = '您的性別:';
$_['entry_date_birth']    = '您的生日:';

 

4.语言文件register.php
4.1.Search
$_['entry_confirm']        = '确认密码:';

Add
$_['entry_biey']               = '您的性別:';
$_['entry_date_birth']           = '您的生日:';

 

6.model\account\customer.php
6.1.Search
(int)$data['newsletter'] : 0) .

Add
"', biey = '" . (isset($data['biey']) ? (int)$data['biey'] : 0) . "', date_birth = '" . $this->db->escape($data['date_birth']) .


7.模板edit.tpl
7.1.Search
<span class="error"><?php echo $error_telephone; ?></span>
            <?php } ?></td>
        </tr>

Add
<!--biey and birth model by-kenfang-->
<tr>
          <td><span class="required">*</span> <?php echo $entry_biey; ?></td>
          <td><?php if ($biey == 0) { ?>
                  <input type="radio" name="biey" value="1" />男
                  <input type="radio" name="biey" value="0" checked="checked" />女
            <?php } else { ?>
            <input type="radio" name="biey" value="1" checked="checked" />男
                  <input type="radio" name="biey" value="0"/>女
             <?php } ?></td>
        </tr>
        <tr>
          <td><span class="required">*</span> <?php echo $entry_date_birth; ?></td>
          <td><input type="text" name="date_birth" value="<?php echo $date_birth; ?>" size="12" class="date" /></td>
        </tr>

 

7.2.Search
<?php echo $content_bottom; ?></div>

Add
<script type="text/javascript" src="view/javascript/jquery/ui/jquery-ui-timepicker-addon.js"></script> 
<script type="text/javascript"><!--
$('.date').datepicker({dateFormat: 'yy-mm-dd'});
$('.datetime').datetimepicker({
        dateFormat: 'yy-mm-dd',
        timeFormat: 'h:m'
});
$('.time').timepicker({timeFormat: 'h:m'});
//--></script>

注:这里可以自己选择要將栏位放在哪裡。


8.模板register.tpl
8.1.Search
<span class="error"><?php echo $error_firstname; ?></span>
            <?php } ?></td>
        </tr>

Add
<!--biey and birth model by-kenfang-->
<tr>
          <td><span class="required">*</span> <?php echo $entry_biey; ?></td>
          <td><input type="radio" name="biey" value="1" />男
                  <input type="radio" name="biey" value="0" checked="checked" />女
            </td>
        </tr>
        <tr>
          <td><span class="required">*</span> <?php echo $entry_date_birth; ?></td>
          <td><input type="text" name="date_birth" value="<?php echo $date_birth; ?>" size="12" class="date" /></td>
        </tr>
<!--biey and birth model by-kenfang-->


8.2.Search
<script type="text/javascript"><!--
$('.colorbox').colorbox({
        width: 640,
        height: 480
});
//--></script>

Add
<script type="text/javascript" src="view/javascript/jquery/ui/jquery-ui-timepicker-addon.js"></script> 
<script type="text/javascript"><!--
$('.date').datepicker({dateFormat: 'yy-mm-dd'});
$('.datetime').datetimepicker({
        dateFormat: 'yy-mm-dd',
        timeFormat: 'h:m'
});
$('.time').timepicker({timeFormat: 'h:m'});
//--></script>