1: | <?php
2: | namespace Opencart\Catalog\Model\Account;
3: | /**
4: | * Class Returns
5: | *
6: | * @package Opencart\Catalog\Model\Account
7: | */
8: | class Returns extends \Opencart\System\Engine\Model {
9: | /**
10: | * Add Return
11: | *
12: | * @param array<string, mixed> $data
13: | *
14: | * @return int
15: | */
16: | public function addReturn(array $data): int {
17: | $this->db->query("INSERT INTO `" . DB_PREFIX . "return` SET `order_id` = '" . (int)$data['order_id'] . "', `product_id` = '" . (int)$data['product_id'] . "', `customer_id` = '" . (int)$this->customer->getId() . "', `firstname` = '" . $this->db->escape($data['firstname']) . "', `lastname` = '" . $this->db->escape($data['lastname']) . "', `email` = '" . $this->db->escape($data['email']) . "', `telephone` = '" . $this->db->escape($data['telephone']) . "', `product` = '" . $this->db->escape($data['product']) . "', `model` = '" . $this->db->escape($data['model']) . "', `quantity` = '" . (int)$data['quantity'] . "', `opened` = '" . (int)$data['opened'] . "', `return_reason_id` = '" . (int)$data['return_reason_id'] . "', `return_status_id` = '" . (int)$this->config->get('config_return_status_id') . "', `comment` = '" . $this->db->escape($data['comment']) . "', `date_ordered` = '" . $this->db->escape($data['date_ordered']) . "', `date_added` = NOW(), `date_modified` = NOW()");
18: |
19: | return $this->db->getLastId();
20: | }
21: |
22: | /**
23: | * Get Return
24: | *
25: | * @param int $return_id
26: | *
27: | * @return array<string, mixed>
28: | */
29: | public function getReturn(int $return_id): array {
30: | $query = $this->db->query("SELECT `r`.`return_id`, `r`.`order_id`, `r`.`firstname`, `r`.`lastname`, `r`.`email`, `r`.`telephone`, `r`.`product`, `r`.`model`, `r`.`quantity`, `r`.`opened`, (SELECT `rr`.`name` FROM `" . DB_PREFIX . "return_reason` `rr` WHERE `rr`.`return_reason_id` = `r`.`return_reason_id` AND `rr`.`language_id` = '" . (int)$this->config->get('config_language_id') . "') AS `reason`, (SELECT `ra`.`name` FROM `" . DB_PREFIX . "return_action` `ra` WHERE `ra`.`return_action_id` = `r`.`return_action_id` AND `ra`.`language_id` = '" . (int)$this->config->get('config_language_id') . "') AS `action`, (SELECT `rs`.`name` FROM `" . DB_PREFIX . "return_status` `rs` WHERE `rs`.`return_status_id` = `r`.`return_status_id` AND `rs`.`language_id` = '" . (int)$this->config->get('config_language_id') . "') AS `status`, `r`.`comment`, `r`.`date_ordered`, `r`.`date_added`, `r`.`date_modified` FROM `" . DB_PREFIX . "return` `r` WHERE `r`.`return_id` = '" . (int)$return_id . "' AND `r`.`customer_id` = '" . $this->customer->getId() . "'");
31: |
32: | return $query->row;
33: | }
34: |
35: | /**
36: | * Get Returns
37: | *
38: | * @param int $start
39: | * @param int $limit
40: | *
41: | * @return array<int, array<string, mixed>>
42: | */
43: | public function getReturns(int $start = 0, int $limit = 20): array {
44: | if ($start < 0) {
45: | $start = 0;
46: | }
47: |
48: | if ($limit < 1) {
49: | $limit = 20;
50: | }
51: |
52: | $query = $this->db->query("SELECT `r`.`return_id`, `r`.`order_id`, `r`.`firstname`, `r`.`lastname`, `rs`.`name` AS `status`, `r`.`date_added` FROM `" . DB_PREFIX . "return` `r` LEFT JOIN `" . DB_PREFIX . "return_status` `rs` ON (`r`.`return_status_id` = `rs`.`return_status_id`) WHERE `r`.`customer_id` = '" . (int)$this->customer->getId() . "' AND `rs`.`language_id` = '" . (int)$this->config->get('config_language_id') . "' ORDER BY `r`.`return_id` DESC LIMIT " . (int)$start . "," . (int)$limit);
53: |
54: | return $query->rows;
55: | }
56: |
57: | /**
58: | * Get Total Returns
59: | *
60: | * @return int
61: | */
62: | public function getTotalReturns(): int {
63: | $query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "return` WHERE `customer_id` = '" . $this->customer->getId() . "'");
64: |
65: | return (int)$query->row['total'];
66: | }
67: |
68: | /**
69: | * Get Histories
70: | *
71: | * @param int $return_id
72: | *
73: | * @return array<int, array<string, mixed>>
74: | */
75: | public function getHistories(int $return_id): array {
76: | $query = $this->db->query("SELECT `rh`.`date_added`, `rs`.`name` AS status, `rh`.`comment` FROM `" . DB_PREFIX . "return_history` `rh` LEFT JOIN `" . DB_PREFIX . "return_status` `rs` ON (`rh`.`return_status_id` = `rs`.`return_status_id`) WHERE `rh`.`return_id` = '" . (int)$return_id . "' AND `rs`.`language_id` = '" . (int)$this->config->get('config_language_id') . "' ORDER BY `rh`.`date_added` ASC");
77: |
78: | return $query->rows;
79: | }
80: | }
81: |

OpenCart API API documentation generated by ApiGen dev-master