如何在Opncart中更新客户TIN号 [英] How to update customer TIN Number in Opncart

查看:82
本文介绍了如何在Opncart中更新客户TIN号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Opencart MVC 的新功能,我有一个名为my_account.tpl的页面.在此页面中显示客户nametin_number.

Am new in Opencart MVC, I have page called my_account.tpl. In this page am displaying customer name and tin_number.

如果客户要更改其tin_number,只需填写"TIN号"字段并单击保存",它将更新oc_customer表格.

If customers want to change their tin_number just fill the TIN Number field and click save, it will update oc_customer tabel.

我尝试过,但是数据没有更新.

I tried but data's not update.

遵循视图,模型和控制器代码

Following view, model and controller codes

查看:my_account.tpl

<form action="<?php echo $action;?>" method="POST" enctype="multipart/form-data" class="form-horizontal">
            <div class="col-md-9 col-lg-6 col-sm-12">

                <?php foreach($customerData as $customer) { ?>

                <div class="form-group">
                    <label>Name:</label>
                    <input type="text" style="display: none" placeholder="ID" name="id" value="<?php echo $result['tin_number'];?>">
                    <input type="text" name="name" value="<?php echo $customer['name']; ?>" placeholder="Name" class="form-control" disabled>
                </div>

                <div class="form-group">
                    <label>TIN Number:</label>
                    <input type="text" name="tin_number" value="<?php echo $customer['tin_number']; ?>" placeholder="TIN Number" class="form-control">
                </div>

                <?php } ?>
                <div class="form-group">
                    <input type="submit" name="save" value="<?php echo 'Save'; ?>" class="btn btn-primary">
                </div>

            </div>
        </form>

控制器:my_account.php

public function edit() {

        /*form edit my_account*/
         if(isset($_GET['tin_number']))
        {
            $tin_number=$_GET['tin_number'];
        }
        $this->load->model('account/customer');
        $data['delivery_point']=$this->model_account_customer->getcustomerId($tin_number);
        $data['action'] = $this->url->link('account/my_account', '', 'SSL');


        if ($this->request->server['REQUEST_METHOD'] == 'POST')
        {
            $this->model_account_customer->editCustomerTin($this->request->post);
            $this->response->redirect($this->url->link('account/home', '', 'SSL'));
            echo "<script>javascript: alert('test msgbox')></script>";
        }
        /*form edit my_account*/

}

型号:my_account.php

public function editCustomerTin($data)
    {
         $query = $this->db->query("UPDATE " . DB_PREFIX . "customer set tin_number='".$data['tin_number']."' where customer_id=".$data['id']);
    }

推荐答案

我得到了它在另一个函数中起作用的答案,请参见下面的编码

I got the answer it working in another function see below the coding

控制器my_account.php

 public function index() {

        $this->load->language('account/account');
        $this->document->setTitle($this->language->get('heading_title'));

        $data['breadcrumbs'] = array();

        $data['breadcrumbs'][] = array(
            'text' => $this->language->get('Home'),
            'href' => $this->url->link('common/home')
        );

        $data['breadcrumbs'][] = array(
            'text' => $this->language->get('Previous'),
            'href' => $this->url->link('common/home', '', 'SSL')
        );


        if (isset($this->session->data['success'])) {
            $data['success'] = $this->session->data['success'];

            unset($this->session->data['success']);
        } else {
            $data['success'] = '';
        }

        $data['heading_title'] = $this->language->get('heading_title');
        $url = '';

        $this->load->model('account/customer');

        //$data['customerData']=array();
        $results=$this->model_account_customer->getCustomerByTin();


        foreach($results as $result)
        {

        $query1 = $this->db->query("SELECT concat(firstname,' ',lastname) as name,tin_number,invoice_no_overwrite FROM " . DB_PREFIX . "customer where customer_id='".$_COOKIE['customerId']."'");
        $customer_name= $query1->row['name'];
        $tin_number= $query1->row['tin_number'];
        $invoice_no_overwrite= $query1->row['invoice_no_overwrite'];



            $data['customerData'][0] = array(
                'name'      => $customer_name,
                'invoice_no_overwrite'=> $invoice_no_overwrite,
                'tin_number'=>$tin_number
                );
        }

        //var_dump($data['CustomerData']);

        /*form edit my_account*/
        if ($this->request->server['REQUEST_METHOD'] == 'POST')
        {
           $this->model_account_customer->editCustomerTin($this->request->post);
            $this->response->redirect($this->url->link('account/my_account', '', 'SSL'));
        }

        /*form edit my_account*/

        $data['column_left'] = $this->load->controller('common/column_left');
        $data['column_right'] = $this->load->controller('common/column_right');
        $data['content_top'] = $this->load->controller('common/content_top');
        $data['content_bottom'] = $this->load->controller('common/content_bottom');
        $data['footer'] = $this->load->controller('common/footer');
        $data['header'] = $this->load->controller('common/header');

        if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/account/my_account.tpl')) {
            $this->response->setOutput($this->load->view($this->config->get('config_template') . '/template/account/my_account.tpl', $data));
        } else {
            $this->response->setOutput($this->load->view('default/template/account/my_account.tpl', $data));
        }

    }

我不知道它是怎么发生的,谁能教我...?

I don't know how its happen can any one teach me...?

这篇关于如何在Opncart中更新客户TIN号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆