[英]Changing customer_id to fax in Opencart 1.5.x
I have changed table "customer_rewards" and some other stuff what connected with rewards in Opencart 1.5.x. 我更改了表“ customer_rewards”和其他一些与Opencart 1.5.x中的奖励有关的内容。
Now in table "customer_rewards" customer_id column contains fax of customer. 现在,在“ customer_rewards”表的customer_id列中包含客户的传真 。
I just have changed content of customer_id and now it contains fax field (I'm using this for storing discount card code) but column also named as customer_id . 我只是更改了customer_id的内容,现在它包含传真字段(我正在使用它存储折扣卡代码),但列也命名为customer_id 。
I thought I also could edit some query and simple replace customer_id to fax but it doesn't work properly :( 我以为我也可以编辑一些查询并简单地替换customer_id进行传真,但是它不能正常工作:(
Then I have add some functions but the also didn't work properly, I've got in customer_id column null, 0, 1 but no fax field. 然后我添加了一些功能,但也无法正常工作,我在customer_id列中输入了null,0、1,但没有传真字段。
Tried to edit: 尝试编辑:
/admin/controller/sale/customer.php /admin/controller/sale/customer.php
/admin/model/sale/customer.php /admin/model/sale/customer.php
Query to get fax of user (tried this after trying with getting from other model): 查询以获取用户传真(尝试从其他模型获取后进行了尝试):
$fax = $this->db->query("SELECT fax FROM " . DB_PREFIX . "customer WHERE customer_id = '" . (int)$customer_id . "'");
All code behind without my edits. 没有我的编辑,所有代码都在后面。
Some parts of Model: 模型的某些部分:
...
$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'];
}
Parts of Controller what connected with 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 table structure: customer_rewards表结构:
customer_reward_id,
customer_id,
order_id,
description,
points,
date_added
Maybe you have some ideas. 也许您有一些想法。 Thanks!
谢谢!
UPDATE: OK, I have made this it seems work fine but customer_id column contains "1" and as you see I can't get fax field properly. 更新:好的,我已经使它看起来工作正常,但是customer_id列包含“ 1”,并且如您所见,我无法正确获取传真字段。 And now main question is how can I get fax field?
现在主要的问题是如何获得传真字段?
...
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()");
...
I just have used $customer_fax=$customer_info['fax']; 我只用了$ customer_fax = $ customer_info ['fax']; to get fax field.
获取传真字段。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.