1: <?php
2: namespace Opencart\Catalog\Controller\Account;
3: /**
4: * Class Transaction
5: *
6: * @package Opencart\Catalog\Controller\Account
7: */
8: class Transaction extends \Opencart\System\Engine\Controller {
9: /**
10: * @return void
11: */
12: public function index(): void {
13: $this->load->language('account/transaction');
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/transaction', '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_transaction'),
43: 'href' => $this->url->link('account/transaction', 'language=' . $this->config->get('config_language') . '&customer_token=' . $this->session->data['customer_token'])
44: ];
45:
46: $data['column_amount'] = sprintf($this->language->get('column_amount'), $this->config->get('config_currency'));
47:
48: $limit = 10;
49:
50: $data['transactions'] = [];
51:
52: $filter_data = [
53: 'sort' => 'date_added',
54: 'order' => 'DESC',
55: 'start' => ($page - 1) * $limit,
56: 'limit' => $limit
57: ];
58:
59: $this->load->model('account/transaction');
60:
61: $results = $this->model_account_transaction->getTransactions($this->customer->getId(), $filter_data);
62:
63: foreach ($results as $result) {
64: $data['transactions'][] = [
65: 'amount' => $this->currency->format($result['amount'], $this->config->get('config_currency')),
66: 'description' => $result['description'],
67: 'date_added' => date($this->language->get('date_format_short'), strtotime($result['date_added']))
68: ];
69: }
70:
71: $transaction_total = $this->model_account_transaction->getTotalTransactions($this->customer->getId());
72:
73: $data['pagination'] = $this->load->controller('common/pagination', [
74: 'total' => $transaction_total,
75: 'page' => $page,
76: 'limit' => $limit,
77: 'url' => $this->url->link('account/transaction', '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'), ($transaction_total) ? (($page - 1) * $limit) + 1 : 0, ((($page - 1) * $limit) > ($transaction_total - $limit)) ? $transaction_total : ((($page - 1) * $limit) + $limit), $transaction_total, ceil($transaction_total / $limit));
81:
82: $data['total'] = $this->currency->format($this->customer->getBalance(), $this->session->data['currency']);
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/transaction', $data));
94: }
95: }
96: