1: <?php
2: namespace Opencart\Catalog\Controller\Account;
3: /**
4: * Class Reward
5: *
6: * @package Opencart\Catalog\Controller\Account
7: */
8: class Reward extends \Opencart\System\Engine\Controller {
9: /**
10: * @return void
11: */
12: public function index(): void {
13: $this->load->language('account/reward');
14:
15: if (isset($this->request->get['page'])) {
16: $page = (int)$this->request->get['page'];
17: } else {
18: $page = 1;
19: }
20:
21: if (!$this->customer->isLogged() || (!isset($this->request->get['customer_token']) || !isset($this->session->data['customer_token']) || ($this->request->get['customer_token'] != $this->session->data['customer_token']))) {
22: $this->session->data['redirect'] = $this->url->link('account/reward', 'language=' . $this->config->get('config_language'));
23:
24: $this->response->redirect($this->url->link('account/login', 'language=' . $this->config->get('config_language'), true));
25: }
26:
27: $this->document->setTitle($this->language->get('heading_title'));
28:
29: $data['breadcrumbs'] = [];
30:
31: $data['breadcrumbs'][] = [
32: 'text' => $this->language->get('text_home'),
33: 'href' => $this->url->link('common/home', 'language=' . $this->config->get('config_language'))
34: ];
35:
36: $data['breadcrumbs'][] = [
37: 'text' => $this->language->get('text_account'),
38: 'href' => $this->url->link('account/account', 'language=' . $this->config->get('config_language') . '&customer_token=' . $this->session->data['customer_token'])
39: ];
40:
41: $data['breadcrumbs'][] = [
42: 'text' => $this->language->get('text_reward'),
43: 'href' => $this->url->link('account/reward', 'language=' . $this->config->get('config_language') . '&customer_token=' . $this->session->data['customer_token'])
44: ];
45:
46: $limit = 10;
47:
48: $data['rewards'] = [];
49:
50: $filter_data = [
51: 'sort' => 'date_added',
52: 'order' => 'DESC',
53: 'start' => ($page - 1) * $limit,
54: 'limit' => $limit
55: ];
56:
57: $this->load->model('account/reward');
58:
59: $results = $this->model_account_reward->getRewards($this->customer->getId(), $filter_data);
60:
61: foreach ($results as $result) {
62: $data['rewards'][] = [
63: 'order_id' => $result['order_id'],
64: 'points' => $result['points'],
65: 'description' => $result['description'],
66: 'date_added' => date($this->language->get('date_format_short'), strtotime($result['date_added'])),
67: 'href' => $this->url->link('account/order.info', 'language=' . $this->config->get('config_language') . '&customer_token=' . $this->session->data['customer_token'] . '&order_id=' . $result['order_id'])
68: ];
69: }
70:
71: $reward_total = $this->model_account_reward->getTotalRewards($this->customer->getId());
72:
73: $data['pagination'] = $this->load->controller('common/pagination', [
74: 'total' => $reward_total,
75: 'page' => $page,
76: 'limit' => $limit,
77: 'url' => $this->url->link('account/reward', 'language=' . $this->config->get('config_language') . '&customer_token=' . $this->session->data['customer_token'] . '&page={page}')
78: ]);
79:
80: $data['results'] = sprintf($this->language->get('text_pagination'), ($reward_total) ? (($page - 1) * $limit) + 1 : 0, ((($page - 1) * $limit) > ($reward_total - $limit)) ? $reward_total : ((($page - 1) * $limit) + $limit), $reward_total, ceil($reward_total / $limit));
81:
82: $data['total'] = (int)$this->customer->getRewardPoints();
83:
84: $data['continue'] = $this->url->link('account/account', 'language=' . $this->config->get('config_language') . '&customer_token=' . $this->session->data['customer_token']);
85:
86: $data['column_left'] = $this->load->controller('common/column_left');
87: $data['column_right'] = $this->load->controller('common/column_right');
88: $data['content_top'] = $this->load->controller('common/content_top');
89: $data['content_bottom'] = $this->load->controller('common/content_bottom');
90: $data['footer'] = $this->load->controller('common/footer');
91: $data['header'] = $this->load->controller('common/header');
92:
93: $this->response->setOutput($this->load->view('account/reward', $data));
94: }
95: }
96: