Back to Opencart

File extension\opencart\admin\model\module\bestseller.php

docs/api/source-extension.opencart.admin.model.module.bestseller.html

4.1.0.36.1 KB
Original Source

Namespaces

Classes

| 1: | <?php | | 2: | namespace Opencart\Admin\Model\Extension\Opencart\Module; | | 3: | /** | | 4: | * Class Bestseller | | 5: | * | | 6: | * @package Opencart\Admin\Model\Extension\Opencart\Module | | 7: | */ | | 8: | class Bestseller extends \Opencart\System\Engine\Model { | | 9: | /** | | 10: | * Install | | 11: | * | | 12: | * @return void | | 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: | * Uninstall | | 24: | * | | 25: | * @return void | | 26: | */ | | 27: | public function uninstall(): void { | | 28: | $this->db->query("DROP TABLE IF EXISTS " . DB\_PREFIX . "product\_bestseller"); | | 29: | } | | 30: | | | 31: | /** | | 32: | * Edit Total | | 33: | * | | 34: | * @param int $product_id | | 35: | * @param int $total | | 36: | * | | 37: | * @return void | | 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: | * Delete | | 45: | * | | 46: | * @param int $product_id | | 47: | * | | 48: | * @return void | | 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: | * Get Reports | | 56: | * | | 57: | * @param int $start | | 58: | * @param int $limit | | 59: | * | | 60: | * @return array<int, array<string, mixed>> | | 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: | * Get Total Reports | | 78: | * | | 79: | * @return int | | 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: | |

OpenCart API API documentation generated by ApiGen dev-master