Back to Opencart

File extension\opencart\admin\model\report\product_purchased.php

docs/api/source-extension.opencart.admin.model.report.product_purchased.html

4.1.0.37.6 KB
Original Source

Namespaces

Classes

| 1: | <?php | | 2: | namespace Opencart\Admin\Model\Extension\Opencart\Report; | | 3: | /** | | 4: | * Class ProductPurchased | | 5: | * | | 6: | * @package Opencart\Admin\Model\Extension\Opencart\Report | | 7: | */ | | 8: | class ProductPurchased extends \Opencart\System\Engine\Model { | | 9: | /** | | 10: | * Get Purchased | | 11: | * | | 12: | * @param array<string, mixed> $data | | 13: | * | | 14: | * @return array<int, array<string, mixed>> | | 15: | */ | | 16: | public function getPurchased(array $data = []): array { | | 17: | $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)"; | | 18: | | | 19: | if (!empty($data['filter_order_status_id'])) { | | 20: | $sql .= " WHERE o.order_status_id = '" . (int)$data['filter_order_status_id'] . "'"; | | 21: | } else { | | 22: | $sql .= " WHERE o.order_status_id > '0'"; | | 23: | } | | 24: | | | 25: | if (!empty($data['filter_date_start'])) { | | 26: | $sql .= " AND DATE(o.date_added) >= DATE('" . $this->db->escape((string)$data['filter_date_start']) . "')"; | | 27: | } | | 28: | | | 29: | if (!empty($data['filter_date_end'])) { | | 30: | $sql .= " AND DATE(o.date_added) <= DATE('" . $this->db->escape((string)$data['filter_date_end']) . "')"; | | 31: | } | | 32: | | | 33: | $sql .= " GROUP BY op.product_id ORDER BY total DESC"; | | 34: | | | 35: | if (isset($data['start']) || isset($data['limit'])) { | | 36: | if ($data['start'] < 0) { | | 37: | $data['start'] = 0; | | 38: | } | | 39: | | | 40: | if ($data['limit'] < 1) { | | 41: | $data['limit'] = 20; | | 42: | } | | 43: | | | 44: | $sql .= " LIMIT " . (int)$data['start'] . "," . (int)$data['limit']; | | 45: | } | | 46: | | | 47: | $query = $this->db->query($sql); | | 48: | | | 49: | return $query->rows; | | 50: | } | | 51: | | | 52: | /** | | 53: | * Get Total Purchased | | 54: | * | | 55: | * @param array<string, mixed> $data | | 56: | * | | 57: | * @return int | | 58: | */ | | 59: | public function getTotalPurchased(array $data = []): int { | | 60: | $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)"; | | 61: | | | 62: | if (!empty($data['filter_order_status_id'])) { | | 63: | $sql .= " WHERE o.order_status_id = '" . (int)$data['filter_order_status_id'] . "'"; | | 64: | } else { | | 65: | $sql .= " WHERE o.order_status_id > '0'"; | | 66: | } | | 67: | | | 68: | if (!empty($data['filter_date_start'])) { | | 69: | $sql .= " AND DATE(o.date_added) >= DATE('" . $this->db->escape((string)$data['filter_date_start']) . "')"; | | 70: | } | | 71: | | | 72: | if (!empty($data['filter_date_end'])) { | | 73: | $sql .= " AND DATE(o.date_added) <= DATE('" . $this->db->escape((string)$data['filter_date_end']) . "')"; | | 74: | } | | 75: | | | 76: | $query = $this->db->query($sql); | | 77: | | | 78: | return (int)$query->row['total']; | | 79: | } | | 80: | } | | 81: | |

OpenCart API API documentation generated by ApiGen dev-master