1: <?php
2: namespace Opencart\Admin\Controller\Extension\Opencart\Dashboard;
3: /**
4: * Class Customer
5: *
6: * @package Opencart\Admin\Controller\Extension\Opencart\Dashboard
7: */
8: class Customer extends \Opencart\System\Engine\Controller {
9: /**
10: * Index
11: *
12: * @return void
13: */
14: public function index(): void {
15: $this->load->language('extension/opencart/dashboard/customer');
16:
17: $this->document->setTitle($this->language->get('heading_title'));
18:
19: $data['breadcrumbs'] = [];
20:
21: $data['breadcrumbs'][] = [
22: 'text' => $this->language->get('text_home'),
23: 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'])
24: ];
25:
26: $data['breadcrumbs'][] = [
27: 'text' => $this->language->get('text_extension'),
28: 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=dashboard')
29: ];
30:
31: $data['breadcrumbs'][] = [
32: 'text' => $this->language->get('heading_title'),
33: 'href' => $this->url->link('extension/opencart/dashboard/customer', 'user_token=' . $this->session->data['user_token'])
34: ];
35:
36: $data['save'] = $this->url->link('extension/opencart/dashboard/customer.save', 'user_token=' . $this->session->data['user_token']);
37: $data['back'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=dashboard');
38:
39: $data['dashboard_customer_width'] = $this->config->get('dashboard_customer_width');
40:
41: $data['columns'] = [];
42:
43: for ($i = 3; $i <= 12; $i++) {
44: $data['columns'][] = $i;
45: }
46:
47: $data['dashboard_customer_status'] = $this->config->get('dashboard_customer_status');
48: $data['dashboard_customer_sort_order'] = $this->config->get('dashboard_customer_sort_order');
49:
50: $data['header'] = $this->load->controller('common/header');
51: $data['column_left'] = $this->load->controller('common/column_left');
52: $data['footer'] = $this->load->controller('common/footer');
53:
54: $this->response->setOutput($this->load->view('extension/opencart/dashboard/customer_form', $data));
55: }
56:
57: /**
58: * Save
59: *
60: * @return void
61: */
62: public function save(): void {
63: $this->load->language('extension/opencart/dashboard/customer');
64:
65: $json = [];
66:
67: if (!$this->user->hasPermission('modify', 'extension/opencart/dashboard/customer')) {
68: $json['error'] = $this->language->get('error_permission');
69: }
70:
71: if (!$json) {
72: $this->load->model('setting/setting');
73:
74: $this->model_setting_setting->editSetting('dashboard_customer', $this->request->post);
75:
76: $json['success'] = $this->language->get('text_success');
77: }
78:
79: $this->response->addHeader('Content-Type: application/json');
80: $this->response->setOutput(json_encode($json));
81: }
82:
83: /**
84: * Dashboard
85: *
86: * @return string
87: */
88: public function dashboard(): string {
89: $this->load->language('extension/opencart/dashboard/customer');
90:
91: $data['user_token'] = $this->session->data['user_token'];
92:
93: // Total Orders
94: $this->load->model('customer/customer');
95:
96: $today = $this->model_customer_customer->getTotalCustomers(['filter_date_added' => date('Y-m-d', strtotime('-1 day'))]);
97:
98: $yesterday = $this->model_customer_customer->getTotalCustomers(['filter_date_added' => date('Y-m-d', strtotime('-2 day'))]);
99:
100: $difference = $today - $yesterday;
101:
102: if ($difference && $today) {
103: $data['percentage'] = round(($difference / $today) * 100);
104: } else {
105: $data['percentage'] = 0;
106: }
107:
108: $customer_total = $this->model_customer_customer->getTotalCustomers();
109:
110: if ($customer_total > 1000000000000) {
111: $data['total'] = round($customer_total / 1000000000000, 1) . 'T';
112: } elseif ($customer_total > 1000000000) {
113: $data['total'] = round($customer_total / 1000000000, 1) . 'B';
114: } elseif ($customer_total > 1000000) {
115: $data['total'] = round($customer_total / 1000000, 1) . 'M';
116: } elseif ($customer_total > 1000) {
117: $data['total'] = round($customer_total / 1000, 1) . 'K';
118: } else {
119: $data['total'] = $customer_total;
120: }
121:
122: $data['customer'] = $this->url->link('customer/customer', 'user_token=' . $this->session->data['user_token']);
123:
124: return $this->load->view('extension/opencart/dashboard/customer_info', $data);
125: }
126: }
127: