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

标签 php mysql opencart

我更改了表“customer_rewards”和其他一些与 Opencart 1.5.x 中的奖励相关的内容。

现在在表“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'];
    }

Controller 中与 Rewards 相关的部分:

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()");
...

最佳答案

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

关于php - 在 Opencart 1.5.x 中将 customer_id 更改为传真,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40153294/

相关文章:

javascript - $_SESSION 在 AJAX 请求上丢失

php - 如何在mysql中打印计数?

php - 从 zf2 模块中将 CSS 注入(inject)布局

php - MySQL 获取一个选择,如果不可用则获取其他

php - 我的 MySQL 数据库中的正则表达式不工作

php - 是否可以要求登录 OpenCart 信息页面,并且只有信息页面?

javascript - php如何使用js获取帖子ID

php - 如何将表中的列值检索到 PHP 变量中?

opencart - opencart中的扩展和模块有什么区别?

css - Opencart 主题 - 使用 CSS 更改表格标题的颜色?