在Opencart 1.5.x中将customer_id更改为传真

时间:2016-10-20 11:33:34

标签: php mysql opencart

我已更改了表格" customer_rewards"与Opencart 1.5.x中的奖励相关的其他一些东西。

现在在表格#34; customer_rewards" customer_id 列包含传真的客户。

我刚刚更改了 customer_id 的内容,现在它包含传真字段(我用它来存储折扣卡代码)但列也命名为 customer_id

我认为我也可以编辑一些查询并简单地将customer_id替换为传真,但它无法正常工作:(

然后我添加了一些功能,但也没有正常工作,我已经进入 customer_id 列null,0,1但没有传真字段。

试图编辑:

/admin/controller/sale/customer.php
/admin/model/sale/customer.php

查询以获取用户的传真(尝试从其他模型获取后尝试此操作):

$fax = $this->db->query("SELECT fax FROM " . DB_PREFIX . "customer WHERE customer_id = '" . (int)$customer_id . "'");

所有代码都没有我的编辑。

模型的某些部分:

...
$customer_id = $this->db->getLastId();
...
public function addReward($customer_id, $description = '', $points = '', $order_id = 0) {
        $customer_info = $this->getCustomer($customer_id);

        if ($customer_info) { 
            $this->db->query("INSERT INTO " . DB_PREFIX . "customer_reward SET customer_id = '" . (int)$customer_id . "', order_id = '" . (int)$order_id . "', points = '" . (int)$points . "', description = '" . $this->db->escape($description) . "', date_added = NOW()");

            $this->language->load('mail/customer');

            if ($order_id) {
                $this->load->model('sale/order');

                $order_info = $this->model_sale_order->getOrder($order_id);

                if ($order_info) {
                    $store_name = $order_info['store_name'];
                } else {
                    $store_name = $this->config->get('config_name');
                }   
            } else {
                $store_name = $this->config->get('config_name');
            }       

            $message  = sprintf($this->language->get('text_reward_received'), $points) . "\n\n";
            $message .= sprintf($this->language->get('text_reward_total'), $this->getRewardTotal($customer_id));

            $mail = new Mail();
            $mail->protocol = $this->config->get('config_mail_protocol');
            $mail->parameter = $this->config->get('config_mail_parameter');
            $mail->hostname = $this->config->get('config_smtp_host');
            $mail->username = $this->config->get('config_smtp_username');
            $mail->password = $this->config->get('config_smtp_password');
            $mail->port = $this->config->get('config_smtp_port');
            $mail->timeout = $this->config->get('config_smtp_timeout');
            $mail->setTo($customer_info['email']);
            $mail->setFrom($this->config->get('config_email'));
            $mail->setSender($store_name);
            $mail->setSubject(html_entity_decode(sprintf($this->language->get('text_reward_subject'), $store_name), ENT_QUOTES, 'UTF-8'));
            $mail->setText(html_entity_decode($message, ENT_QUOTES, 'UTF-8'));
            $mail->send();
        }
    }

    public function deleteReward($order_id) {
        $this->db->query("DELETE FROM " . DB_PREFIX . "customer_reward WHERE order_id = '" . (int)$order_id . "'");
    }

    public function getRewards($customer_id, $start = 0, $limit = 10) {
        $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "customer_reward WHERE customer_id = '" . (int)$customer_id . "' ORDER BY date_added DESC LIMIT " . (int)$start . "," . (int)$limit);

        return $query->rows;
    }

    public function getTotalRewards($customer_id) {
        $query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "customer_reward WHERE customer_id = '" . (int)$customer_id . "'");

        return $query->row['total'];
    }

    public function getRewardTotal($customer_id) {
        $query = $this->db->query("SELECT SUM(points) AS total FROM " . DB_PREFIX . "customer_reward WHERE customer_id = '" . (int)$customer_id . "'");

        return $query->row['total'];
    }       

    public function getTotalCustomerRewardsByOrderId($order_id) {
        $query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "customer_reward WHERE order_id = '" . (int)$order_id . "'");

        return $query->row['total'];
    }

与奖励相关的控制器部分:

public function reward() {
    $this->language->load('sale/customer');

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

    if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->user->hasPermission('modify', 'sale/customer')) { 
        $this->model_sale_customer->addReward($this->request->get['customer_id'], $this->request->post['description'], $this->request->post['points']);

        $this->data['success'] = $this->language->get('text_success');
    } else {
        $this->data['success'] = '';
    }

    if (($this->request->server['REQUEST_METHOD'] == 'POST') && !$this->user->hasPermission('modify', 'sale/customer')) {
        $this->data['error_warning'] = $this->language->get('error_permission');
    } else {
        $this->data['error_warning'] = '';
    }   

    $this->data['text_no_results'] = $this->language->get('text_no_results');
    $this->data['text_balance'] = $this->language->get('text_balance');

    $this->data['column_date_added'] = $this->language->get('column_date_added');
    $this->data['column_description'] = $this->language->get('column_description');
    $this->data['column_points'] = $this->language->get('column_points');

    if (isset($this->request->get['page'])) {
        $page = $this->request->get['page'];
    } else {
        $page = 1;
    }  

    $this->data['rewards'] = array();

    $results = $this->model_sale_customer->getRewards($this->request->get['customer_id'], ($page - 1) * 10, 10);

    foreach ($results as $result) {
        $this->data['rewards'][] = array(
            'points'      => $result['points'],
            'description' => $result['description'],
            'date_added'  => date($this->language->get('date_format_short'), strtotime($result['date_added']))
        );
    }           

    $this->data['balance'] = $this->model_sale_customer->getRewardTotal($this->request->get['customer_id']);

    $reward_total = $this->model_sale_customer->getTotalRewards($this->request->get['customer_id']);

    $pagination = new Pagination();
    $pagination->total = $reward_total;
    $pagination->page = $page;
    $pagination->limit = 10; 
    $pagination->text = $this->language->get('text_pagination');
    $pagination->url = $this->url->link('sale/customer/reward', 'token=' . $this->session->data['token'] . '&customer_id=' . $this->request->get['customer_id'] . '&page={page}', 'SSL');

    $this->data['pagination'] = $pagination->render();

    $this->template = 'sale/customer_reward.tpl';   

    $this->response->setOutput($this->render());
}

customer_rewards表结构:

customer_reward_id,
customer_id,
order_id,
description,
points,
date_added

也许你有一些想法。谢谢!

更新 好吧,我已经做了这个似乎工作正常,但customer_id列包含" 1"如你所见,我无法正常获得传真字段。现在的主要问题是如何获得传真领域?

...
public function getFax($customer_id) {
        $query = $this->db->query("SELECT fax FROM " . DB_PREFIX . "customer WHERE customer_id = '" . (int)$customer_id . "'");

        return $query->row;
    }

    public function addReward($customer_id, $description = '', $points = '', $order_id = 0) {
        $customer_info = $this->getCustomer($customer_id);

        $customer_fax = $this->getFax($customer_id);

        if ($customer_info) { 
            $this->db->query("INSERT INTO " . DB_PREFIX . "customer_reward SET customer_id = '" . (int)$customer_fax . "', order_id = '" . (int)$order_id . "', points = '" . (int)$points . "', description = '" . $this->db->escape($description) . "', date_added = NOW()");
...

1 个答案:

答案 0 :(得分:0)

我刚使用 $ customer_fax = $ customer_info ['传真']; 来获取传真字段。