1: | <?php
|
2: | namespace Opencart\Admin\Model\Extension\Opencart\Module;
|
3: | |
4: | |
5: | |
6: | |
7: |
|
8: | class Bestseller extends \Opencart\System\Engine\Model {
|
9: | |
10: | |
11: | |
12: | |
13: |
|
14: | public function install(): void {
|
15: | $this->db->query("CREATE TABLE IF NOT EXISTS `" . DB_PREFIX . "product_bestseller` (
|
16: | `product_id` int(11) NOT NULL,
|
17: | `total` int(11) NOT NULL,
|
18: | PRIMARY KEY (`product_id`)
|
19: | ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci");
|
20: | }
|
21: |
|
22: | |
23: | |
24: | |
25: | |
26: |
|
27: | public function uninstall(): void {
|
28: | $this->db->query("DROP TABLE IF EXISTS `" . DB_PREFIX . "product_bestseller`");
|
29: | }
|
30: |
|
31: | |
32: | |
33: | |
34: | |
35: | |
36: | |
37: | |
38: |
|
39: | public function editTotal(int $product_id, int $total): void {
|
40: | $this->db->query("REPLACE INTO `" . DB_PREFIX . "product_bestseller` SET `product_id` = '" . (int)$product_id . "', `total` = '" . (int)$total . "'");
|
41: | }
|
42: |
|
43: | |
44: | |
45: | |
46: | |
47: | |
48: | |
49: |
|
50: | public function delete(int $product_id): void {
|
51: | $this->db->query("DELETE FROM `" . DB_PREFIX . "product_bestseller` WHERE `product_id` = '" . (int)$product_id . "'");
|
52: | }
|
53: |
|
54: | |
55: | |
56: | |
57: | |
58: | |
59: | |
60: | |
61: |
|
62: | public function getReports(int $start = 0, int $limit = 10): array {
|
63: | if ($start < 0) {
|
64: | $start = 0;
|
65: | }
|
66: |
|
67: | if ($limit < 1) {
|
68: | $limit = 10;
|
69: | }
|
70: |
|
71: | $query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "product_bestseller` ORDER BY `total` DESC LIMIT " . (int)$start . "," . (int)$limit);
|
72: |
|
73: | return $query->rows;
|
74: | }
|
75: |
|
76: | |
77: | |
78: | |
79: | |
80: |
|
81: | public function getTotalReports(): int {
|
82: | $query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "product_bestseller`");
|
83: |
|
84: | return (int)$query->row['total'];
|
85: | }
|
86: | }
|
87: | |