#php #mysql #opencart
#php #mysql #opencart
Вопрос:
Я изменил таблицу «customer_rewards» и некоторые другие вещи, связанные с вознаграждениями в Opencart 1.5.x.
Теперь в таблице «customer_rewards» столбец customer_id содержит факс клиента.
Я только что изменил содержимое customer_id, и теперь оно содержит поле fax (я использую его для хранения кода дисконтной карты), но столбец также называется customer_id.
Я думал, что также мог бы отредактировать какой-нибудь запрос и просто заменить customer_id на fax, но это не работает должным образом: (
Затем я добавил некоторые функции, но они также не работали должным образом, у меня в столбце customer_id null, 0, 1, но нет поля fax.
Пытался отредактировать:
/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) . "nn";
$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') amp;amp; $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') amp;amp; !$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'] . 'amp;customer_id=' . $this->request->get['customer_id'] . 'amp;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», и, как вы видите, я не могу правильно получить поле fax. И теперь главный вопрос в том, как я могу получить поле fax?
...
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:
Я только что использовал $customer_fax=$customer_info[‘fax’]; для получения поля fax.
Комментарии:
1. Но я все еще не могу получить вознаграждение.
2. $results = $this->model_sale_customer->getRewards($this->request->get[‘customer_id’], ($page — 1) * 10, 10); Работает, но с get[‘customer_fax’] не будет работать.