How to update customer TIN Number in Opncart

被刻印的时光 ゝ 提交于 2019-12-10 12:03:00

问题


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

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

View: 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>

controller: 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*/

}

Model: 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']);
    }

回答1:


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

controller 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...?



来源:https://stackoverflow.com/questions/43109347/how-to-update-customer-tin-number-in-opncart

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!