1: | <?php
|
2: | namespace Opencart\Catalog\Model\Account;
|
3: | |
4: | |
5: | |
6: | |
7: |
|
8: | class Subscription extends \Opencart\System\Engine\Model {
|
9: | |
10: | |
11: | |
12: | |
13: | |
14: | |
15: |
|
16: | public function getSubscription(int $subscription_id): array {
|
17: | $subscription_data = [];
|
18: |
|
19: | $query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "subscription` `s` WHERE `subscription_id` = '" . (int)$subscription_id . "' AND `customer_id` = '" . (int)$this->customer->getId() . "'");
|
20: |
|
21: | if ($query->num_rows) {
|
22: | $subscription_data = $query->row;
|
23: |
|
24: | $subscription_data['option'] = ($query->row['option'] ? json_decode($query->row['option'], true) : '');
|
25: | $subscription_data['payment_method'] = ($query->row['payment_method'] ? json_decode($query->row['payment_method'], true) : '');
|
26: | $subscription_data['shipping_method'] = ($query->row['shipping_method'] ? json_decode($query->row['shipping_method'], true) : '');
|
27: | }
|
28: |
|
29: | return $subscription_data;
|
30: | }
|
31: |
|
32: | |
33: | |
34: | |
35: | |
36: | |
37: | |
38: | |
39: |
|
40: | public function getSubscriptionByOrderProductId(int $order_id, int $order_product_id): array {
|
41: | $subscription_data = [];
|
42: |
|
43: | $query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "subscription` WHERE `order_id` = '" . (int)$order_id . "' AND `order_product_id` = '" . (int)$order_product_id . "' AND `customer_id` = '" . (int)$this->customer->getId() . "'");
|
44: |
|
45: | if ($query->num_rows) {
|
46: | $subscription_data = $query->row;
|
47: |
|
48: | $subscription_data['option'] = ($query->row['option'] ? json_decode($query->row['option'], true) : '');
|
49: | $subscription_data['payment_method'] = ($query->row['payment_method'] ? json_decode($query->row['payment_method'], true) : '');
|
50: | $subscription_data['shipping_method'] = ($query->row['shipping_method'] ? json_decode($query->row['shipping_method'], true) : '');
|
51: | }
|
52: |
|
53: | return $subscription_data;
|
54: | }
|
55: |
|
56: | |
57: | |
58: | |
59: | |
60: | |
61: | |
62: | |
63: |
|
64: | public function getSubscriptions(int $start = 0, int $limit = 20): array {
|
65: | if ($start < 0) {
|
66: | $start = 0;
|
67: | }
|
68: |
|
69: | if ($limit < 1) {
|
70: | $limit = 1;
|
71: | }
|
72: |
|
73: | $query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "subscription` WHERE `customer_id` = '" . (int)$this->customer->getId() . "' AND `subscription_status_id` > '0' AND `store_id` = '" . (int)$this->config->get('config_store_id') . "' ORDER BY `subscription_id` DESC LIMIT " . (int)$start . "," . (int)$limit);
|
74: |
|
75: | return $query->rows;
|
76: | }
|
77: |
|
78: | |
79: | |
80: | |
81: | |
82: |
|
83: | public function getTotalSubscriptions(): int {
|
84: | $query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "subscription` WHERE `customer_id` = '" . (int)$this->customer->getId() . "' AND `subscription_status_id` > '0' AND `store_id` = '" . (int)$this->config->get('config_store_id') . "'");
|
85: |
|
86: | if ($query->num_rows) {
|
87: | return (int)$query->row['total'];
|
88: | } else {
|
89: | return 0;
|
90: | }
|
91: | }
|
92: |
|
93: | |
94: | |
95: | |
96: | |
97: | |
98: | |
99: |
|
100: | public function getTotalSubscriptionByShippingAddressId(int $address_id): int {
|
101: | $query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "subscription` WHERE `customer_id` = '" . (int)$this->customer->getId() . "' AND `shipping_address_id` = '" . (int)$address_id . "'");
|
102: |
|
103: | return (int)$query->row['total'];
|
104: | }
|
105: |
|
106: | |
107: | |
108: | |
109: | |
110: | |
111: | |
112: |
|
113: | public function getTotalSubscriptionByPaymentAddressId(int $address_id): int {
|
114: | $query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "subscription` WHERE `customer_id` = '" . (int)$this->customer->getId() . "' AND `payment_address_id` = '" . (int)$address_id . "'");
|
115: |
|
116: | return (int)$query->row['total'];
|
117: | }
|
118: |
|
119: | |
120: | |
121: | |
122: | |
123: | |
124: | |
125: | |
126: | |
127: |
|
128: | public function getHistories(int $subscription_id, int $start = 0, int $limit = 10): array {
|
129: | if ($start < 0) {
|
130: | $start = 0;
|
131: | }
|
132: |
|
133: | if ($limit < 1) {
|
134: | $limit = 10;
|
135: | }
|
136: |
|
137: | $query = $this->db->query("SELECT `sh`.`date_added`, `ss`.`name` AS `status`, `sh`.`comment`, `sh`.`notify` FROM `" . DB_PREFIX . "subscription_history` `sh` LEFT JOIN `" . DB_PREFIX . "subscription_status` `ss` ON `sh`.`subscription_status_id` = `ss`.`subscription_status_id` WHERE `sh`.`subscription_id` = '" . (int)$subscription_id . "' AND `ss`.`language_id` = '" . (int)$this->config->get('config_language_id') . "' ORDER BY `sh`.`date_added` DESC LIMIT " . (int)$start . "," . (int)$limit);
|
138: |
|
139: | return $query->rows;
|
140: | }
|
141: |
|
142: | |
143: | |
144: | |
145: | |
146: | |
147: | |
148: |
|
149: | public function getTotalHistories(int $subscription_id): int {
|
150: | $query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "subscription_history` WHERE `subscription_id` = '" . (int)$subscription_id . "'");
|
151: |
|
152: | return (int)$query->row['total'];
|
153: | }
|
154: |
|
155: | |
156: | |
157: | |
158: | |
159: | |
160: | |
161: | |
162: |
|
163: | public function editRemaining(int $subscription_id, int $remaining): void {
|
164: | $this->db->query("UPDATE `" . DB_PREFIX . "subscription` SET `remaining` = '" . (int)$remaining . "' WHERE `subscription_id` = '" . (int)$subscription_id . "'");
|
165: | }
|
166: |
|
167: | |
168: | |
169: | |
170: | |
171: | |
172: | |
173: | |
174: |
|
175: | public function editTrialRemaining(int $subscription_id, int $trial_remaining): void {
|
176: | $this->db->query("UPDATE `" . DB_PREFIX . "subscription` SET `trial_remaining` = '" . (int)$trial_remaining . "' WHERE `subscription_id` = '" . (int)$subscription_id . "'");
|
177: | }
|
178: | }
|
179: | |