1: | <?php
2: | namespace Opencart\Admin\Controller\Sale;
3: | /**
4: | * Class Subscription
5: | *
6: | * @package Opencart\Admin\Controller\Sale
7: | */
8: | class Subscription extends \Opencart\System\Engine\Controller {
9: | /**
10: | * Index
11: | *
12: | * @return void
13: | */
14: | public function index(): void {
15: | $this->load->language('sale/subscription');
16: |
17: | $this->document->setTitle($this->language->get('heading_title'));
18: |
19: | if (isset($this->request->get['filter_subscription_id'])) {
20: | $filter_subscription_id = (int)$this->request->get['filter_subscription_id'];
21: | } else {
22: | $filter_subscription_id = '';
23: | }
24: |
25: | if (isset($this->request->get['filter_order_id'])) {
26: | $filter_order_id = $this->request->get['filter_order_id'];
27: | } else {
28: | $filter_order_id = '';
29: | }
30: |
31: | if (isset($this->request->get['filter_customer'])) {
32: | $filter_customer = $this->request->get['filter_customer'];
33: | } else {
34: | $filter_customer = '';
35: | }
36: |
37: | if (isset($this->request->get['filter_subscription_status_id'])) {
38: | $filter_subscription_status_id = (int)$this->request->get['filter_subscription_status_id'];
39: | } else {
40: | $filter_subscription_status_id = '';
41: | }
42: |
43: | if (isset($this->request->get['filter_date_from'])) {
44: | $filter_date_from = $this->request->get['filter_date_from'];
45: | } else {
46: | $filter_date_from = '';
47: | }
48: |
49: | if (isset($this->request->get['filter_date_to'])) {
50: | $filter_date_to = $this->request->get['filter_date_to'];
51: | } else {
52: | $filter_date_to = '';
53: | }
54: |
55: | $url = '';
56: |
57: | if (isset($this->request->get['filter_subscription_id'])) {
58: | $url .= '&filter_subscription_id=' . $this->request->get['filter_subscription_id'];
59: | }
60: |
61: | if (isset($this->request->get['filter_order_id'])) {
62: | $url .= '&filter_order_id=' . $this->request->get['filter_order_id'];
63: | }
64: |
65: | if (isset($this->request->get['filter_customer'])) {
66: | $url .= '&filter_customer=' . urlencode(html_entity_decode($this->request->get['filter_customer'], ENT_QUOTES, 'UTF-8'));
67: | }
68: |
69: | if (isset($this->request->get['filter_subscription_status_id'])) {
70: | $url .= '&filter_subscription_status_id=' . $this->request->get['filter_subscription_status_id'];
71: | }
72: |
73: | if (isset($this->request->get['filter_date_from'])) {
74: | $url .= '&filter_date_from=' . $this->request->get['filter_date_from'];
75: | }
76: |
77: | if (isset($this->request->get['filter_date_to'])) {
78: | $url .= '&filter_date_to=' . $this->request->get['filter_date_to'];
79: | }
80: |
81: | if (isset($this->request->get['sort'])) {
82: | $url .= '&sort=' . $this->request->get['sort'];
83: | }
84: |
85: | if (isset($this->request->get['order'])) {
86: | $url .= '&order=' . $this->request->get['order'];
87: | }
88: |
89: | if (isset($this->request->get['page'])) {
90: | $url .= '&page=' . $this->request->get['page'];
91: | }
92: |
93: | $data['breadcrumbs'] = [];
94: |
95: | $data['breadcrumbs'][] = [
96: | 'text' => $this->language->get('text_home'),
97: | 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'])
98: | ];
99: |
100: | $data['breadcrumbs'][] = [
101: | 'text' => $this->language->get('heading_title'),
102: | 'href' => $this->url->link('sale/subscription', 'user_token=' . $this->session->data['user_token'] . $url)
103: | ];
104: |
105: | $data['add'] = $this->url->link('sale/subscription.form', 'user_token=' . $this->session->data['user_token'] . $url);
106: | $data['delete'] = $this->url->link('sale/subscription.delete', 'user_token=' . $this->session->data['user_token']);
107: |
108: | $data['list'] = $this->getList();
109: |
110: | $this->load->model('localisation/subscription_status');
111: |
112: | $data['subscription_statuses'] = $this->model_localisation_subscription_status->getSubscriptionStatuses();
113: |
114: | $data['filter_subscription_id'] = $filter_subscription_id;
115: | $data['filter_order_id'] = $filter_order_id;
116: | $data['filter_customer'] = $filter_customer;
117: | $data['filter_subscription_status_id'] = $filter_subscription_status_id;
118: | $data['filter_date_from'] = $filter_date_from;
119: | $data['filter_date_to'] = $filter_date_to;
120: |
121: | $data['user_token'] = $this->session->data['user_token'];
122: |
123: | $data['header'] = $this->load->controller('common/header');
124: | $data['column_left'] = $this->load->controller('common/column_left');
125: | $data['footer'] = $this->load->controller('common/footer');
126: |
127: | $this->response->setOutput($this->load->view('sale/subscription', $data));
128: | }
129: |
130: | /**
131: | * List
132: | *
133: | * @return void
134: | */
135: | public function list(): void {
136: | $this->load->language('sale/subscription');
137: |
138: | $this->response->setOutput($this->getList());
139: | }
140: |
141: | /**
142: | * Get List
143: | *
144: | * @return string
145: | */
146: | protected function getList(): string {
147: | if (isset($this->request->get['filter_subscription_id'])) {
148: | $filter_subscription_id = (int)$this->request->get['filter_subscription_id'];
149: | } else {
150: | $filter_subscription_id = '';
151: | }
152: |
153: | if (isset($this->request->get['filter_order_id'])) {
154: | $filter_order_id = $this->request->get['filter_order_id'];
155: | } else {
156: | $filter_order_id = '';
157: | }
158: |
159: | if (isset($this->request->get['filter_customer'])) {
160: | $filter_customer = $this->request->get['filter_customer'];
161: | } else {
162: | $filter_customer = '';
163: | }
164: |
165: | if (isset($this->request->get['filter_subscription_status_id'])) {
166: | $filter_subscription_status_id = (int)$this->request->get['filter_subscription_status_id'];
167: | } else {
168: | $filter_subscription_status_id = '';
169: | }
170: |
171: | if (isset($this->request->get['filter_date_from'])) {
172: | $filter_date_from = $this->request->get['filter_date_from'];
173: | } else {
174: | $filter_date_from = '';
175: | }
176: |
177: | if (isset($this->request->get['filter_date_to'])) {
178: | $filter_date_to = $this->request->get['filter_date_to'];
179: | } else {
180: | $filter_date_to = '';
181: | }
182: |
183: | if (isset($this->request->get['sort'])) {
184: | $sort = (string)$this->request->get['sort'];
185: | } else {
186: | $sort = 's.subscription_id';
187: | }
188: |
189: | if (isset($this->request->get['order'])) {
190: | $order = (string)$this->request->get['order'];
191: | } else {
192: | $order = 'DESC';
193: | }
194: |
195: | if (isset($this->request->get['page'])) {
196: | $page = (int)$this->request->get['page'];
197: | } else {
198: | $page = 1;
199: | }
200: |
201: | $url = '';
202: |
203: | if (isset($this->request->get['filter_subscription_id'])) {
204: | $url .= '&filter_subscription_id=' . $this->request->get['filter_subscription_id'];
205: | }
206: |
207: | if (isset($this->request->get['filter_order_id'])) {
208: | $url .= '&filter_order_id=' . $this->request->get['filter_order_id'];
209: | }
210: |
211: | if (isset($this->request->get['filter_customer'])) {
212: | $url .= '&filter_customer=' . urlencode(html_entity_decode($this->request->get['filter_customer'], ENT_QUOTES, 'UTF-8'));
213: | }
214: |
215: | if (isset($this->request->get['filter_subscription_status_id'])) {
216: | $url .= '&filter_subscription_status_id=' . $this->request->get['filter_subscription_status_id'];
217: | }
218: |
219: | if (isset($this->request->get['filter_date_from'])) {
220: | $url .= '&filter_date_from=' . $this->request->get['filter_date_from'];
221: | }
222: |
223: | if (isset($this->request->get['filter_date_to'])) {
224: | $url .= '&filter_date_to=' . $this->request->get['filter_date_to'];
225: | }
226: |
227: | if (isset($this->request->get['sort'])) {
228: | $url .= '&sort=' . $this->request->get['sort'];
229: | }
230: |
231: | if (isset($this->request->get['order'])) {
232: | $url .= '&order=' . $this->request->get['order'];
233: | }
234: |
235: | if (isset($this->request->get['page'])) {
236: | $url .= '&page=' . $this->request->get['page'];
237: | }
238: |
239: | $data['subscriptions'] = [];
240: |
241: | $filter_data = [
242: | 'filter_subscription_id' => $filter_subscription_id,
243: | 'filter_order_id' => $filter_order_id,
244: | 'filter_customer' => $filter_customer,
245: | 'filter_subscription_status_id' => $filter_subscription_status_id,
246: | 'filter_date_from' => $filter_date_from,
247: | 'filter_date_to' => $filter_date_to,
248: | 'order' => $order,
249: | 'sort' => $sort,
250: | 'start' => ($page - 1) * $this->config->get('config_pagination_admin'),
251: | 'limit' => $this->config->get('config_pagination_admin')
252: | ];
253: |
254: | $this->load->model('sale/subscription');
255: |
256: | $results = $this->model_sale_subscription->getSubscriptions($filter_data);
257: |
258: | foreach ($results as $result) {
259: | $data['subscriptions'][] = [
260: | 'subscription_id' => $result['subscription_id'],
261: | 'order_id' => $result['order_id'],
262: | 'customer' => $result['customer'],
263: | 'status' => $result['subscription_status'],
264: | 'date_added' => date($this->language->get('date_format_short'), strtotime($result['date_added'])),
265: | 'view' => $this->url->link('sale/subscription.info', 'user_token=' . $this->session->data['user_token'] . '&subscription_id=' . $result['subscription_id'] . $url),
266: | 'order' => $this->url->link('sale/order.info', 'user_token=' . $this->session->data['user_token'] . '&order_id=' . $result['order_id'])
267: | ];
268: | }
269: |
270: | $url = '';
271: |
272: | if (isset($this->request->get['filter_subscription_id'])) {
273: | $url .= '&filter_subscription_id=' . $this->request->get['filter_subscription_id'];
274: | }
275: |
276: | if (isset($this->request->get['filter_order_id'])) {
277: | $url .= '&filter_order_id=' . $this->request->get['filter_order_id'];
278: | }
279: |
280: | if (isset($this->request->get['filter_customer'])) {
281: | $url .= '&filter_customer=' . urlencode(html_entity_decode($this->request->get['filter_customer'], ENT_QUOTES, 'UTF-8'));
282: | }
283: |
284: | if (isset($this->request->get['filter_subscription_status_id'])) {
285: | $url .= '&filter_subscription_status_id=' . $this->request->get['filter_subscription_status_id'];
286: | }
287: |
288: | if (isset($this->request->get['filter_date_from'])) {
289: | $url .= '&filter_date_from=' . $this->request->get['filter_date_from'];
290: | }
291: |
292: | if (isset($this->request->get['filter_date_to'])) {
293: | $url .= '&filter_date_to=' . $this->request->get['filter_date_to'];
294: | }
295: |
296: | if ($order == 'ASC') {
297: | $url .= '&order=DESC';
298: | } else {
299: | $url .= '&order=ASC';
300: | }
301: |
302: | $data['sort_subscription'] = $this->url->link('sale/subscription.list', 'user_token=' . $this->session->data['user_token'] . '&sort=s.subscription_id' . $url);
303: | $data['sort_order'] = $this->url->link('sale/subscription.list', 'user_token=' . $this->session->data['user_token'] . '&sort=s.order_id' . $url);
304: | $data['sort_customer'] = $this->url->link('sale/subscription.list', 'user_token=' . $this->session->data['user_token'] . '&sort=customer' . $url);
305: | $data['sort_status'] = $this->url->link('sale/subscription.list', 'user_token=' . $this->session->data['user_token'] . '&sort=subscription_status' . $url);
306: | $data['sort_date_added'] = $this->url->link('sale/subscription.list', 'user_token=' . $this->session->data['user_token'] . '&sort=s.date_added' . $url);
307: |
308: | $url = '';
309: |
310: | if (isset($this->request->get['filter_subscription_id'])) {
311: | $url .= '&filter_subscription_id=' . $this->request->get['filter_subscription_id'];
312: | }
313: |
314: | if (isset($this->request->get['filter_order_id'])) {
315: | $url .= '&filter_order_id=' . $this->request->get['filter_order_id'];
316: | }
317: |
318: | if (isset($this->request->get['filter_customer'])) {
319: | $url .= '&filter_customer=' . urlencode(html_entity_decode($this->request->get['filter_customer'], ENT_QUOTES, 'UTF-8'));
320: | }
321: |
322: | if (isset($this->request->get['filter_status'])) {
323: | $url .= '&filter_status=' . $this->request->get['filter_status'];
324: | }
325: |
326: | if (isset($this->request->get['filter_date_from'])) {
327: | $url .= '&filter_date_from=' . $this->request->get['filter_date_from'];
328: | }
329: |
330: | if (isset($this->request->get['filter_date_to'])) {
331: | $url .= '&filter_date_to=' . $this->request->get['filter_date_to'];
332: | }
333: |
334: | if (isset($this->request->get['sort'])) {
335: | $url .= '&sort=' . $this->request->get['sort'];
336: | }
337: |
338: | if (isset($this->request->get['order'])) {
339: | $url .= '&order=' . $this->request->get['order'];
340: | }
341: |
342: | $subscription_total = $this->model_sale_subscription->getTotalSubscriptions($filter_data);
343: |
344: | $data['pagination'] = $this->load->controller('common/pagination', [
345: | 'total' => $subscription_total,
346: | 'page' => $page,
347: | 'limit' => $this->config->get('config_pagination_admin'),
348: | 'url' => $this->url->link('sale/subscription.list', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}')
349: | ]);
350: |
351: | $data['results'] = sprintf($this->language->get('text_pagination'), ($subscription_total) ? (($page - 1) * $this->config->get('config_pagination_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_pagination_admin')) > ($subscription_total - $this->config->get('config_pagination_admin'))) ? $subscription_total : ((($page - 1) * $this->config->get('config_pagination_admin')) + $this->config->get('config_pagination_admin')), $subscription_total, ceil($subscription_total / $this->config->get('config_pagination_admin')));
352: |
353: | $data['sort'] = $sort;
354: | $data['order'] = $order;
355: |
356: | return $this->load->view('sale/subscription_list', $data);
357: | }
358: |
359: | /**
360: | * Info
361: | *
362: | * @return void
363: | */
364: | public function info(): void {
365: | $this->load->language('sale/subscription');
366: |
367: | if (isset($this->request->get['subscription_id'])) {
368: | $subscription_id = (int)$this->request->get['subscription_id'];
369: | } else {
370: | $subscription_id = 0;
371: | }
372: |
373: | $this->document->setTitle($this->language->get('heading_title'));
374: |
375: | $data['text_form'] = !$subscription_id ? $this->language->get('text_add') : sprintf($this->language->get('text_edit'), $subscription_id);
376: |
377: | $url = '';
378: |
379: | if (isset($this->request->get['filter_subscription_id'])) {
380: | $url .= '&filter_subscription_id=' . $this->request->get['filter_subscription_id'];
381: | }
382: |
383: | if (isset($this->request->get['filter_order_id'])) {
384: | $url .= '&filter_order_id=' . $this->request->get['filter_order_id'];
385: | }
386: |
387: | if (isset($this->request->get['filter_customer'])) {
388: | $url .= '&filter_customer=' . urlencode(html_entity_decode($this->request->get['filter_customer'], ENT_QUOTES, 'UTF-8'));
389: | }
390: |
391: | if (isset($this->request->get['filter_subscription_status_id'])) {
392: | $url .= '&filter_subscription_status_id=' . $this->request->get['filter_subscription_status_id'];
393: | }
394: |
395: | if (isset($this->request->get['filter_date_from'])) {
396: | $url .= '&filter_date_from=' . $this->request->get['filter_date_from'];
397: | }
398: |
399: | if (isset($this->request->get['filter_date_to'])) {
400: | $url .= '&filter_date_to=' . $this->request->get['filter_date_to'];
401: | }
402: |
403: | if (isset($this->request->get['sort'])) {
404: | $url .= '&sort=' . $this->request->get['sort'];
405: | }
406: |
407: | if (isset($this->request->get['order'])) {
408: | $url .= '&order=' . $this->request->get['order'];
409: | }
410: |
411: | if (isset($this->request->get['page'])) {
412: | $url .= '&page=' . $this->request->get['page'];
413: | }
414: |
415: | $data['breadcrumbs'] = [];
416: |
417: | $data['breadcrumbs'][] = [
418: | 'text' => $this->language->get('text_home'),
419: | 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'])
420: | ];
421: |
422: | $data['breadcrumbs'][] = [
423: | 'text' => $this->language->get('heading_title'),
424: | 'href' => $this->url->link('sale/subscription', 'user_token=' . $this->session->data['user_token'] . $url)
425: | ];
426: |
427: | $data['back'] = $this->url->link('sale/subscription', 'user_token=' . $this->session->data['user_token'] . $url);
428: |
429: | $this->load->model('sale/subscription');
430: |
431: | $subscription_info = $this->model_sale_subscription->getSubscription($subscription_id);
432: |
433: | if (!empty($subscription_info)) {
434: | $data['subscription_id'] = $subscription_info['subscription_id'];
435: | } else {
436: | $data['subscription_id'] = '';
437: | }
438: |
439: | // Order
440: | if (!empty($subscription_info)) {
441: | $this->load->model('sale/order');
442: |
443: | $order_info = $this->model_sale_order->getOrder($subscription_info['order_id']);
444: | }
445: |
446: | if (!empty($order_info)) {
447: | $data['order'] = $this->url->link('sale/order.info', 'user_token=' . $this->session->data['user_token'] . '&order_id=' . $subscription_info['order_id']);
448: | } else {
449: | $data['order'] = '';
450: | }
451: |
452: | if (!empty($subscription_info)) {
453: | $data['order_id'] = $subscription_info['order_id'];
454: | } else {
455: | $data['order_id'] = 0;
456: | }
457: |
458: | // Customer
459: | if (!empty($subscription_info)) {
460: | $this->load->model('customer/customer');
461: |
462: | $customer_info = $this->model_customer_customer->getCustomer($subscription_info['customer_id']);
463: | }
464: |
465: | if (!empty($customer_info)) {
466: | $data['firstname'] = $customer_info['firstname'];
467: | } else {
468: | $data['firstname'] = '';
469: | }
470: |
471: | if (!empty($customer_info)) {
472: | $data['lastname'] = $customer_info['lastname'];
473: | } else {
474: | $data['lastname'] = '';
475: | }
476: |
477: | // Subscription
478: | $data['subscription_plans'] = [];
479: |
480: | $this->load->model('catalog/subscription_plan');
481: |
482: | $results = $this->model_catalog_subscription_plan->getSubscriptionPlans();
483: |
484: | foreach ($results as $result) {
485: | $description = '';
486: |
487: | if ($result['trial_status']) {
488: | $trial_price = $this->currency->format($subscription_info['trial_price'], $this->config->get('config_currency'));
489: | $trial_cycle = $result['trial_cycle'];
490: | $trial_frequency = $this->language->get('text_' . $result['trial_frequency']);
491: | $trial_duration = $result['trial_duration'];
492: |
493: | $description .= sprintf($this->language->get('text_subscription_trial'), $trial_price, $trial_cycle, $trial_frequency, $trial_duration);
494: | }
495: |
496: | $price = $this->currency->format($subscription_info['price'], $this->config->get('config_currency'));
497: | $cycle = $result['cycle'];
498: | $frequency = $this->language->get('text_' . $result['frequency']);
499: | $duration = $result['duration'];
500: |
501: | if ($result['duration']) {
502: | $description .= sprintf($this->language->get('text_subscription_duration'), $price, $cycle, $frequency, $duration);
503: | } else {
504: | $description .= sprintf($this->language->get('text_subscription_cancel'), $price, $cycle, $frequency);
505: | }
506: |
507: | $data['subscription_plans'][] = [
508: | 'subscription_plan_id' => $result['subscription_plan_id'],
509: | 'name' => $result['name'],
510: | 'description' => $description
511: | ];
512: | }
513: |
514: | if (!empty($subscription_info)) {
515: | $data['subscription_plan_id'] = $subscription_info['subscription_plan_id'];
516: | } else {
517: | $data['subscription_plan_id'] = 0;
518: | }
519: |
520: | $subscription_plan_info = $this->model_catalog_subscription_plan->getSubscriptionPlan($data['subscription_plan_id']);
521: |
522: | if (!empty($subscription_plan_info)) {
523: | $data['subscription_plan'] = '';
524: |
525: | if ($subscription_plan_info['trial_status']) {
526: | $trial_price = $this->currency->format($subscription_info['trial_price'], $this->config->get('config_currency'));
527: | $trial_cycle = $subscription_plan_info['trial_cycle'];
528: | $trial_frequency = $this->language->get('text_' . $subscription_plan_info['trial_frequency']);
529: | $trial_duration = $subscription_plan_info['trial_duration'];
530: |
531: | $data['subscription_plan'] .= sprintf($this->language->get('text_subscription_trial'), $trial_price, $trial_cycle, $trial_frequency, $trial_duration);
532: | }
533: |
534: | $price = $this->currency->format($subscription_info['price'], $this->config->get('config_currency'));
535: | $cycle = $subscription_plan_info['cycle'];
536: | $frequency = $this->language->get('text_' . $subscription_plan_info['frequency']);
537: | $duration = $subscription_plan_info['duration'];
538: |
539: | if ($subscription_plan_info['duration']) {
540: | $data['subscription_plan'] .= sprintf($this->language->get('text_subscription_duration'), $price, $cycle, $frequency, $duration);
541: | } else {
542: | $data['subscription_plan'] .= sprintf($this->language->get('text_subscription_cancel'), $price, $cycle, $frequency);
543: | }
544: | } else {
545: | $data['subscription_plan'] = '';
546: | }
547: |
548: | if (!empty($subscription_info)) {
549: | $data['trial_price'] = $subscription_info['trial_price'];
550: | } else {
551: | $data['trial_price'] = 0;
552: | }
553: |
554: | $data['frequencies'] = [];
555: |
556: | $data['frequencies'][] = [
557: | 'text' => $this->language->get('text_day'),
558: | 'value' => 'day'
559: | ];
560: |
561: | $data['frequencies'][] = [
562: | 'text' => $this->language->get('text_week'),
563: | 'value' => 'week'
564: | ];
565: |
566: | $data['frequencies'][] = [
567: | 'text' => $this->language->get('text_semi_month'),
568: | 'value' => 'semi_month'
569: | ];
570: |
571: | $data['frequencies'][] = [
572: | 'text' => $this->language->get('text_month'),
573: | 'value' => 'month'
574: | ];
575: |
576: | $data['frequencies'][] = [
577: | 'text' => $this->language->get('text_year'),
578: | 'value' => 'year'
579: | ];
580: |
581: | if (!empty($subscription_info)) {
582: | $data['trial_frequency'] = $subscription_info['trial_frequency'];
583: | } else {
584: | $data['trial_frequency'] = '';
585: | }
586: |
587: | if (!empty($subscription_info)) {
588: | $data['trial_cycle'] = $subscription_info['trial_cycle'];
589: | } else {
590: | $data['trial_cycle'] = 0;
591: | }
592: |
593: | if (!empty($subscription_info)) {
594: | $data['trial_duration'] = $subscription_info['trial_duration'];
595: | } else {
596: | $data['trial_duration'] = 0;
597: | }
598: |
599: | if (!empty($subscription_info)) {
600: | $data['trial_remaining'] = $subscription_info['trial_remaining'];
601: | } else {
602: | $data['trial_remaining'] = 0;
603: | }
604: |
605: | if (!empty($subscription_info)) {
606: | $data['trial_status'] = $subscription_info['trial_status'];
607: | } else {
608: | $data['trial_status'] = 0;
609: | }
610: |
611: | if (!empty($subscription_info)) {
612: | $data['price'] = $subscription_info['price'];
613: | } else {
614: | $data['price'] = 0;
615: | }
616: |
617: | if (!empty($subscription_info)) {
618: | $data['frequency'] = $subscription_info['frequency'];
619: | } else {
620: | $data['frequency'] = '';
621: | }
622: |
623: | if (!empty($subscription_info)) {
624: | $data['cycle'] = $subscription_info['cycle'];
625: | } else {
626: | $data['cycle'] = 0;
627: | }
628: |
629: | if (!empty($subscription_info)) {
630: | $data['duration'] = $subscription_info['duration'];
631: | } else {
632: | $data['duration'] = 0;
633: | }
634: |
635: | if (!empty($subscription_info)) {
636: | $data['remaining'] = $subscription_info['remaining'];
637: | } else {
638: | $data['remaining'] = 0;
639: | }
640: |
641: | // Date next
642: | if (!empty($subscription_info)) {
643: | $data['date_next'] = date($this->language->get('date_format_short'), strtotime($subscription_info['date_next']));
644: | } else {
645: | $data['date_next'] = '';
646: | }
647: |
648: | // Payment method
649: | if (!empty($subscription_info)) {
650: | $data['payment_method'] = $subscription_info['payment_method']['name'];
651: | } else {
652: | $data['payment_method'] = '';
653: | }
654: |
655: | if (!empty($order_info)) {
656: | $data['date_added'] = date($this->language->get('date_format_short'), strtotime($order_info['date_added']));
657: | } else {
658: | $data['date_added'] = '';
659: | }
660: |
661: | // Product data
662: | if (!empty($subscription_info)) {
663: | $this->load->model('account/order');
664: | $product_info = $this->model_account_order->getProduct($subscription_info['order_id'], $subscription_info['order_product_id']);
665: | }
666: |
667: | if (!empty($product_info['name'])) {
668: | $data['product_name'] = $product_info['name'];
669: | } else {
670: | $data['product_name'] = '';
671: | }
672: |
673: | if (!empty($product_info)) {
674: | $data['product'] = $this->url->link('catalog/product.form', 'user_token=' . $this->session->data['user_token'] . '&product_id=' . $product_info['product_id']);
675: | } else {
676: | $data['product'] = '';
677: | }
678: |
679: | $data['options'] = [];
680: |
681: | $options = $this->model_sale_order->getOptions($subscription_info['order_id'], $subscription_info['order_product_id']);
682: |
683: | foreach ($options as $option) {
684: | if ($option['type'] != 'file') {
685: | $data['options'][] = [
686: | 'name' => $option['name'],
687: | 'value' => $option['value'],
688: | 'type' => $option['type']
689: | ];
690: | } else {
691: | $upload_info = $this->model_tool_upload->getUploadByCode($option['value']);
692: |
693: | if ($upload_info) {
694: | $data['options'][] = [
695: | 'name' => $option['name'],
696: | 'value' => $upload_info['name'],
697: | 'type' => $option['type'],
698: | 'href' => $this->url->link('tool/upload.download', 'user_token=' . $this->session->data['user_token'] . '&code=' . $upload_info['code'])
699: | ];
700: | }
701: | }
702: | }
703: |
704: | if (!empty($product_info)) {
705: | $data['quantity'] = $product_info['quantity'];
706: | } else {
707: | $data['quantity'] = '';
708: | }
709: |
710: | $this->load->model('localisation/subscription_status');
711: |
712: | $data['subscription_statuses'] = $this->model_localisation_subscription_status->getSubscriptionStatuses();
713: |
714: | if (!empty($subscription_info)) {
715: | $data['subscription_status_id'] = $subscription_info['subscription_status_id'];
716: | } else {
717: | $data['subscription_status_id'] = '';
718: | }
719: |
720: | $data['history'] = $this->getHistory();
721: | $data['orders'] = $this->getOrder();
722: |
723: | // Additional tabs that are payment gateway specific
724: | $data['tabs'] = [];
725: |
726: | // Extension Order Tabs can be called here.
727: | /*
728: | $this->load->model('setting/extension');
729: |
730: | if (!empty($order_info)) {
731: | $extension_info = $this->model_setting_extension->getExtensionByCode('payment', $order_info['payment_method']['code']);
732: |
733: | if ($extension_info && $this->user->hasPermission('access', 'extension/' . $extension_info['extension'] . '/payment/' . $extension_info['code'])) {
734: | $output = $this->load->controller('extension/payment/' . $order_info['payment_code'] . '.subscription');
735: |
736: | if (!$output instanceof \Exception) {
737: | $this->load->language('extension/' . $extension_info['extension'] . '/payment/' . $extension_info['code'], 'extension');
738: |
739: | $data['tabs'][] = [
740: | 'code' => $extension_info['code'],
741: | 'title' => $this->language->get('extension_heading_title'),
742: | 'content' => $output
743: | ];
744: | }
745: | }
746: | }
747: | */
748: | $data['user_token'] = $this->session->data['user_token'];
749: |
750: | $data['header'] = $this->load->controller('common/header');
751: | $data['column_left'] = $this->load->controller('common/column_left');
752: | $data['footer'] = $this->load->controller('common/footer');
753: |
754: | $this->response->setOutput($this->load->view('sale/subscription_info', $data));
755: | }
756: |
757: | /**
758: | * Save
759: | *
760: | * @return void
761: | */
762: | public function save(): void {
763: | $this->load->language('sale/subscription');
764: |
765: | $json = [];
766: |
767: | if (isset($this->request->get['subscription_id'])) {
768: | $subscription_id = (int)$this->request->get['subscription_id'];
769: | } else {
770: | $subscription_id = 0;
771: | }
772: |
773: | if (!$this->user->hasPermission('modify', 'sale/subscription')) {
774: | $json['error'] = $this->language->get('error_permission');
775: | } elseif ($this->request->post['subscription_plan_id'] == '') {
776: | $json['error'] = $this->language->get('error_subscription_plan');
777: | }
778: |
779: | $this->load->model('catalog/subscription_plan');
780: |
781: | $subscription_plan_info = $this->model_catalog_subscription_plan->getSubscriptionPlan($this->request->post['subscription_plan_id']);
782: |
783: | if (!$subscription_plan_info) {
784: | $json['error'] = $this->language->get('error_subscription_plan');
785: | }
786: |
787: | $this->load->model('sale/subscription');
788: |
789: | $subscription_info = $this->model_sale_subscription->getSubscription($subscription_id);
790: |
791: | if ($subscription_info) {
792: | $this->load->model('sale/subscription');
793: |
794: | $payment_method_info = $this->model_sale_subscription->getSubscriptions(['filter_customer_id' => $subscription_info['customer_id'], 'filter_customer_payment_id' => $this->request->post['customer_payment_id']]);
795: |
796: | if (!$payment_method_info) {
797: | $json['error'] = $this->language->get('error_payment_method');
798: | }
799: | } else {
800: | $json['error'] = $this->language->get('error_subscription');
801: | }
802: |
803: | if (!$json) {
804: | $this->model_sale_subscription->editSubscriptionPlan($subscription_id, $this->request->post['subscription_plan_id']);
805: |
806: | $json['success'] = $this->language->get('text_success');
807: | }
808: |
809: | $this->response->addHeader('Content-Type: application/json');
810: | $this->response->setOutput(json_encode($json));
811: | }
812: |
813: | /**
814: | * History
815: | *
816: | * @return void
817: | */
818: | public function history(): void {
819: | $this->load->language('sale/subscription');
820: |
821: | $this->response->setOutput($this->getHistory());
822: | }
823: |
824: | /**
825: | * Get History
826: | *
827: | * @return string
828: | */
829: | public function getHistory(): string {
830: | if (isset($this->request->get['subscription_id'])) {
831: | $subscription_id = (int)$this->request->get['subscription_id'];
832: | } else {
833: | $subscription_id = 0;
834: | }
835: |
836: | if (isset($this->request->get['page']) && $this->request->get['route'] == 'sale/subscription.history') {
837: | $page = (int)$this->request->get['page'];
838: | } else {
839: | $page = 1;
840: | }
841: |
842: | $limit = 10;
843: |
844: | $data['histories'] = [];
845: |
846: | $this->load->model('sale/subscription');
847: |
848: | $results = $this->model_sale_subscription->getHistories($subscription_id, ($page - 1) * $limit, $limit);
849: |
850: | foreach ($results as $result) {
851: | $data['histories'][] = [
852: | 'status' => $result['status'],
853: | 'comment' => nl2br($result['comment']),
854: | 'notify' => $result['notify'] ? $this->language->get('text_yes') : $this->language->get('text_no'),
855: | 'date_added' => date($this->language->get('date_format_short'), strtotime($result['date_added']))
856: | ];
857: | }
858: |
859: | $subscription_total = $this->model_sale_subscription->getTotalHistories($subscription_id);
860: |
861: | $data['pagination'] = $this->load->controller('common/pagination', [
862: | 'total' => $subscription_total,
863: | 'page' => $page,
864: | 'limit' => $limit,
865: | 'url' => $this->url->link('sale/subscription.history', 'user_token=' . $this->session->data['user_token'] . '&subscription_id=' . $subscription_id . '&page={page}')
866: | ]);
867: |
868: | $data['results'] = sprintf($this->language->get('text_pagination'), ($subscription_total) ? (($page - 1) * $limit) + 1 : 0, ((($page - 1) * $limit) > ($subscription_total - $limit)) ? $subscription_total : ((($page - 1) * $limit) + $limit), $subscription_total, ceil($subscription_total / $limit));
869: |
870: | return $this->load->view('sale/subscription_history', $data);
871: | }
872: |
873: | /**
874: | * Add History
875: | *
876: | * @return void
877: | */
878: | public function addHistory(): void {
879: | $this->load->language('sale/subscription');
880: |
881: | $json = [];
882: |
883: | if (isset($this->request->get['subscription_id'])) {
884: | $subscription_id = (int)$this->request->get['subscription_id'];
885: | } else {
886: | $subscription_id = 0;
887: | }
888: |
889: | if (!$this->user->hasPermission('modify', 'sale/subscription')) {
890: | $json['error'] = $this->language->get('error_permission');
891: | }
892: |
893: | // Subscription
894: | $this->load->model('sale/subscription');
895: |
896: | $subscription_info = $this->model_sale_subscription->getSubscription($subscription_id);
897: |
898: | if (!$subscription_info) {
899: | $json['error'] = $this->language->get('error_subscription');
900: | }
901: |
902: | // Subscription Plan
903: | $this->load->model('localisation/subscription_status');
904: |
905: | $subscription_status_info = $this->model_localisation_subscription_status->getSubscriptionStatus($this->request->post['subscription_status_id']);
906: |
907: | if (!$subscription_status_info) {
908: | $json['error'] = $this->language->get('error_subscription_status');
909: | }
910: |
911: | if (!$json) {
912: | $this->model_sale_subscription->addHistory($subscription_id, $this->request->post['subscription_status_id'], $this->request->post['comment'], $this->request->post['notify']);
913: |
914: | $json['success'] = $this->language->get('text_success');
915: | }
916: |
917: | $this->response->addHeader('Content-Type: application/json');
918: | $this->response->setOutput(json_encode($json));
919: | }
920: |
921: | /**
922: | * Order
923: | *
924: | * @return void
925: | */
926: | public function order(): void {
927: | $this->load->language('sale/subscription');
928: |
929: | $this->response->setOutput($this->getOrder());
930: | }
931: |
932: | /**
933: | * Get Order
934: | *
935: | * @return string
936: | */
937: | public function getOrder(): string {
938: | if (isset($this->request->get['subscription_id'])) {
939: | $subscription_id = (int)$this->request->get['subscription_id'];
940: | } else {
941: | $subscription_id = 0;
942: | }
943: |
944: | if (isset($this->request->get['page']) && $this->request->get['route'] == 'sale/subscription.order') {
945: | $page = (int)$this->request->get['page'];
946: | } else {
947: | $page = 1;
948: | }
949: |
950: | $limit = 10;
951: |
952: | $data['orders'] = [];
953: |
954: | $this->load->model('sale/order');
955: |
956: | $results = $this->model_sale_order->getOrdersBySubscriptionId($subscription_id);
957: |
958: | foreach ($results as $result) {
959: | $data['orders'][] = [
960: | 'order_id' => $result['order_id'],
961: | 'status' => $result['status'],
962: | 'total' => $this->currency->format($result['total'], $result['currency_code'], $result['currency_value']),
963: | 'date_added' => date($this->language->get('date_format_short'), strtotime($result['date_added'])),
964: | 'view' => $this->url->link('sale/subscription.order', 'user_token=' . $this->session->data['user_token'] . '&order_id=' . $result['order_id'] . '&page={page}')
965: | ];
966: | }
967: |
968: | $order_total = $this->model_sale_order->getTotalOrdersBySubscriptionId($subscription_id);
969: |
970: | $data['pagination'] = $this->load->controller('common/pagination', [
971: | 'total' => $order_total,
972: | 'page' => $page,
973: | 'limit' => $limit,
974: | 'url' => $this->url->link('sale/subscription.order', 'user_token=' . $this->session->data['user_token'] . '&subscription_id=' . $subscription_id . '&page={page}')
975: | ]);
976: |
977: | $data['results'] = sprintf($this->language->get('text_pagination'), ($order_total) ? (($page - 1) * $limit) + 1 : 0, ((($page - 1) * $limit) > ($order_total - $limit)) ? $order_total : ((($page - 1) * $limit) + $limit), $order_total, ceil($order_total / $limit));
978: |
979: | return $this->load->view('sale/subscription_order', $data);
980: | }
981: | }
982: |

OpenCart API API documentation generated by ApiGen dev-master