1: <?php
2: namespace Opencart\Catalog\Controller\Event;
3: /**
4: * Class Activity
5: *
6: * @package Opencart\Catalog\Controller\Event
7: */
8: class Activity extends \Opencart\System\Engine\Controller {
9: // catalog/model/account/customer/addCustomer/after
10: /**
11: * Add Customer
12: *
13: * @param string $route
14: * @param array<int, mixed> $args
15: * @param mixed $output
16: *
17: * @return void
18: */
19: public function addCustomer(string &$route, array &$args, &$output): void {
20: if ($this->config->get('config_customer_activity')) {
21: $this->load->model('account/activity');
22:
23: $activity_data = [
24: 'customer_id' => $output,
25: 'name' => $args[0]['firstname'] . ' ' . $args[0]['lastname']
26: ];
27:
28: $this->model_account_activity->addActivity('register', $activity_data);
29: }
30: }
31:
32: // catalog/model/account/customer/editCustomer/after
33:
34: /**
35: * Edit Customer
36: *
37: * @param string $route
38: * @param array<int, mixed> $args
39: * @param mixed $output
40: *
41: * @return void
42: */
43: public function editCustomer(string &$route, array &$args, &$output): void {
44: if ($this->config->get('config_customer_activity')) {
45: $this->load->model('account/activity');
46:
47: $activity_data = [
48: 'customer_id' => $this->customer->getId(),
49: 'name' => $this->customer->getFirstName() . ' ' . $this->customer->getLastName()
50: ];
51:
52: $this->model_account_activity->addActivity('edit', $activity_data);
53: }
54: }
55:
56: // catalog/model/account/customer/editPassword/after
57:
58: /**
59: * Edit Password
60: *
61: * @param string $route
62: * @param array<int, mixed> $args
63: * @param mixed $output
64: *
65: * @return void
66: */
67: public function editPassword(string &$route, array &$args, &$output): void {
68: if ($this->config->get('config_customer_activity')) {
69: $this->load->model('account/activity');
70:
71: if ($this->customer->isLogged()) {
72: $activity_data = [
73: 'customer_id' => $this->customer->getId(),
74: 'name' => $this->customer->getFirstName() . ' ' . $this->customer->getLastName()
75: ];
76:
77: $this->model_account_activity->addActivity('password', $activity_data);
78: } else {
79: $customer_info = $this->model_account_customer->getCustomerByEmail($args[0]);
80:
81: if ($customer_info) {
82: $activity_data = [
83: 'customer_id' => $customer_info['customer_id'],
84: 'name' => $customer_info['firstname'] . ' ' . $customer_info['lastname']
85: ];
86:
87: $this->model_account_activity->addActivity('reset', $activity_data);
88: }
89: }
90: }
91: }
92:
93: // catalog/model/account/customer/deleteLoginAttempts/after
94:
95: /**
96: * Login
97: *
98: * @param string $route
99: * @param array<int, mixed> $args
100: * @param mixed $output
101: *
102: * @return void
103: */
104: public function login(string &$route, array &$args, &$output): void {
105: if (isset($this->request->get['route']) && ($this->request->get['route'] == 'account/login' || $this->request->get['route'] == 'checkout/login.save') && $this->config->get('config_customer_activity')) {
106: $customer_info = $this->model_account_customer->getCustomerByEmail($args[0]);
107:
108: if ($customer_info) {
109: $this->load->model('account/activity');
110:
111: $activity_data = [
112: 'customer_id' => $customer_info['customer_id'],
113: 'name' => $customer_info['firstname'] . ' ' . $customer_info['lastname']
114: ];
115:
116: $this->model_account_activity->addActivity('login', $activity_data);
117: }
118: }
119: }
120:
121: // catalog/model/account/customer/editCode/after
122:
123: /**
124: * Forgotten
125: *
126: * @param string $route
127: * @param array<int, mixed> $args
128: * @param mixed $output
129: *
130: * @return void
131: */
132: public function forgotten(string &$route, array &$args, &$output): void {
133: if (isset($this->request->get['route']) && $this->request->get['route'] == 'account/forgotten' && $this->config->get('config_customer_activity')) {
134: $this->load->model('account/customer');
135:
136: $customer_info = $this->model_account_customer->getCustomerByEmail($args[0]);
137:
138: if ($customer_info) {
139: $this->load->model('account/activity');
140:
141: $activity_data = [
142: 'customer_id' => $customer_info['customer_id'],
143: 'name' => $customer_info['firstname'] . ' ' . $customer_info['lastname']
144: ];
145:
146: $this->model_account_activity->addActivity('forgotten', $activity_data);
147: }
148: }
149: }
150:
151: // catalog/model/account/customer/addTransaction/after
152:
153: /**
154: * Add Transaction
155: *
156: * @param string $route
157: * @param array<int, mixed> $args
158: * @param mixed $output
159: *
160: * @return void
161: */
162: public function addTransaction(string &$route, array &$args, &$output): void {
163: if ($this->config->get('config_customer_activity')) {
164: $this->load->model('account/customer');
165:
166: $customer_info = $this->model_account_customer->getCustomer($args[0]);
167:
168: if ($customer_info) {
169: $this->load->model('account/activity');
170:
171: $activity_data = [
172: 'customer_id' => $customer_info['customer_id'],
173: 'name' => $customer_info['firstname'] . ' ' . $customer_info['lastname'],
174: 'order_id' => $args[3]
175: ];
176:
177: $this->model_account_activity->addActivity('transaction', $activity_data);
178: }
179: }
180: }
181:
182: // catalog/model/account/affiliate/addAffiliate/after
183:
184: /**
185: * Add Affiliate
186: *
187: * @param string $route
188: * @param array<int, mixed> $args
189: * @param mixed $output
190: *
191: * @return void
192: */
193: public function addAffiliate(string &$route, array &$args, &$output): void {
194: if ($this->config->get('config_customer_activity')) {
195: $this->load->model('account/activity');
196:
197: $activity_data = [
198: 'customer_id' => $args[0],
199: 'name' => $args[1]['firstname'] . ' ' . $args[1]['lastname']
200: ];
201:
202: $this->model_account_activity->addActivity('affiliate_add', $activity_data);
203: }
204: }
205:
206: // catalog/model/account/affiliate/editAffiliate/after
207:
208: /**
209: * Edit Affiliate
210: *
211: * @param string $route
212: * @param array<int, mixed> $args
213: * @param mixed $output
214: *
215: * @return void
216: */
217: public function editAffiliate(string &$route, array &$args, &$output): void {
218: if ($this->config->get('config_customer_activity')) {
219: $this->load->model('account/activity');
220:
221: $activity_data = [
222: 'customer_id' => $this->customer->getId(),
223: 'name' => $this->customer->getFirstName() . ' ' . $this->customer->getLastName()
224: ];
225:
226: $this->model_account_activity->addActivity('affiliate_edit', $activity_data);
227: }
228: }
229:
230: // catalog/model/account/address/addAddress/after
231:
232: /**
233: * Add Address
234: *
235: * @param string $route
236: * @param array<int, mixed> $args
237: * @param mixed $output
238: *
239: * @return void
240: */
241: public function addAddress(string &$route, array &$args, &$output): void {
242: if ($this->config->get('config_customer_activity')) {
243: $this->load->model('account/activity');
244:
245: $activity_data = [
246: 'customer_id' => $this->customer->getId(),
247: 'name' => $this->customer->getFirstName() . ' ' . $this->customer->getLastName()
248: ];
249:
250: $this->model_account_activity->addActivity('address_add', $activity_data);
251: }
252: }
253:
254: // catalog/model/account/address/editAddress/after
255:
256: /**
257: * Edit Address
258: *
259: * @param string $route
260: * @param array<int, mixed> $args
261: * @param mixed $output
262: *
263: * @return void
264: */
265: public function editAddress(string &$route, array &$args, &$output): void {
266: if ($this->config->get('config_customer_activity')) {
267: $this->load->model('account/activity');
268:
269: $activity_data = [
270: 'customer_id' => $this->customer->getId(),
271: 'name' => $this->customer->getFirstName() . ' ' . $this->customer->getLastName()
272: ];
273:
274: $this->model_account_activity->addActivity('address_edit', $activity_data);
275: }
276: }
277:
278: // catalog/model/account/address/deleteAddress/after
279:
280: /**
281: * Delete Address
282: *
283: * @param string $route
284: * @param array<int, mixed> $args
285: * @param mixed $output
286: *
287: * @return void
288: */
289: public function deleteAddress(string &$route, array &$args, &$output): void {
290: if ($this->config->get('config_customer_activity')) {
291: $this->load->model('account/activity');
292:
293: $activity_data = [
294: 'customer_id' => $this->customer->getId(),
295: 'name' => $this->customer->getFirstName() . ' ' . $this->customer->getLastName()
296: ];
297:
298: $this->model_account_activity->addActivity('address_delete', $activity_data);
299: }
300: }
301:
302: // catalog/model/account/returns/addReturn/after
303:
304: /**
305: * Add Return
306: *
307: * @param string $route
308: * @param array<int, mixed> $args
309: * @param mixed $output
310: *
311: * @return void
312: */
313: public function addReturn(string &$route, array &$args, &$output): void {
314: if ($this->config->get('config_customer_activity') && $output) {
315: $this->load->model('account/activity');
316:
317: if ($this->customer->isLogged()) {
318: $activity_data = [
319: 'customer_id' => $this->customer->getId(),
320: 'name' => $this->customer->getFirstName() . ' ' . $this->customer->getLastName(),
321: 'return_id' => $output
322: ];
323:
324: $this->model_account_activity->addActivity('return_account', $activity_data);
325: } else {
326: $activity_data = [
327: 'name' => $args[0]['firstname'] . ' ' . $args[0]['lastname'],
328: 'return_id' => $output
329: ];
330:
331: $this->model_account_activity->addActivity('return_guest', $activity_data);
332: }
333: }
334: }
335:
336: // catalog/model/checkout/order/addHistory/before
337:
338: /**
339: * Add History
340: *
341: * @param string $route
342: * @param array<int, mixed> $args
343: *
344: * @return void
345: */
346: public function addHistory(string &$route, array &$args): void {
347: if ($this->config->get('config_customer_activity')) {
348: // If the last order status id returns 0, and the new order status is not, then we record it as new order
349: $this->load->model('checkout/order');
350:
351: $order_info = $this->model_checkout_order->getOrder($args[0]);
352:
353: if ($order_info && !$order_info['order_status_id'] && $args[1]) {
354: $this->load->model('account/activity');
355:
356: if ($order_info['customer_id']) {
357: $activity_data = [
358: 'customer_id' => $order_info['customer_id'],
359: 'name' => $order_info['firstname'] . ' ' . $order_info['lastname'],
360: 'order_id' => $args[0]
361: ];
362:
363: $this->model_account_activity->addActivity('order_account', $activity_data);
364: } else {
365: $activity_data = [
366: 'name' => $order_info['firstname'] . ' ' . $order_info['lastname'],
367: 'order_id' => $args[0]
368: ];
369:
370: $this->model_account_activity->addActivity('order_guest', $activity_data);
371: }
372: }
373: }
374: }
375: }
376: