product.php (3158B)
1 <?php 2 class ModelExtensionReportProduct extends Model { 3 public function getProductsViewed($data = array()) { 4 $sql = "SELECT pd.name, p.model, p.viewed FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) WHERE pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p.viewed > 0 ORDER BY p.viewed DESC"; 5 6 if (isset($data['start']) || isset($data['limit'])) { 7 if ($data['start'] < 0) { 8 $data['start'] = 0; 9 } 10 11 if ($data['limit'] < 1) { 12 $data['limit'] = 20; 13 } 14 15 $sql .= " LIMIT " . (int)$data['start'] . "," . (int)$data['limit']; 16 } 17 18 $query = $this->db->query($sql); 19 20 return $query->rows; 21 } 22 23 public function getTotalProductViews() { 24 $query = $this->db->query("SELECT SUM(viewed) AS total FROM " . DB_PREFIX . "product"); 25 26 return $query->row['total']; 27 } 28 29 public function getTotalProductsViewed() { 30 $query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "product WHERE viewed > 0"); 31 32 return $query->row['total']; 33 } 34 35 public function reset() { 36 $this->db->query("UPDATE " . DB_PREFIX . "product SET viewed = '0'"); 37 } 38 39 public function getPurchased($data = array()) { 40 $sql = "SELECT op.name, op.model, SUM(op.quantity) AS quantity, SUM((op.price + op.tax) * op.quantity) AS total FROM " . DB_PREFIX . "order_product op LEFT JOIN `" . DB_PREFIX . "order` o ON (op.order_id = o.order_id)"; 41 42 if (!empty($data['filter_order_status_id'])) { 43 $sql .= " WHERE o.order_status_id = '" . (int)$data['filter_order_status_id'] . "'"; 44 } else { 45 $sql .= " WHERE o.order_status_id > '0'"; 46 } 47 48 if (!empty($data['filter_date_start'])) { 49 $sql .= " AND DATE(o.date_added) >= '" . $this->db->escape($data['filter_date_start']) . "'"; 50 } 51 52 if (!empty($data['filter_date_end'])) { 53 $sql .= " AND DATE(o.date_added) <= '" . $this->db->escape($data['filter_date_end']) . "'"; 54 } 55 56 $sql .= " GROUP BY op.product_id ORDER BY total DESC"; 57 58 if (isset($data['start']) || isset($data['limit'])) { 59 if ($data['start'] < 0) { 60 $data['start'] = 0; 61 } 62 63 if ($data['limit'] < 1) { 64 $data['limit'] = 20; 65 } 66 67 $sql .= " LIMIT " . (int)$data['start'] . "," . (int)$data['limit']; 68 } 69 70 $query = $this->db->query($sql); 71 72 return $query->rows; 73 } 74 75 public function getTotalPurchased($data) { 76 $sql = "SELECT COUNT(DISTINCT op.product_id) AS total FROM `" . DB_PREFIX . "order_product` op LEFT JOIN `" . DB_PREFIX . "order` o ON (op.order_id = o.order_id)"; 77 78 if (!empty($data['filter_order_status_id'])) { 79 $sql .= " WHERE o.order_status_id = '" . (int)$data['filter_order_status_id'] . "'"; 80 } else { 81 $sql .= " WHERE o.order_status_id > '0'"; 82 } 83 84 if (!empty($data['filter_date_start'])) { 85 $sql .= " AND DATE(o.date_added) >= '" . $this->db->escape($data['filter_date_start']) . "'"; 86 } 87 88 if (!empty($data['filter_date_end'])) { 89 $sql .= " AND DATE(o.date_added) <= '" . $this->db->escape($data['filter_date_end']) . "'"; 90 } 91 92 $query = $this->db->query($sql); 93 94 return $query->row['total']; 95 } 96 }