first commit
This commit is contained in:
701
admininistrator/model/sale/order.php
Normal file
701
admininistrator/model/sale/order.php
Normal file
@ -0,0 +1,701 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Model\Sale;
|
||||
/**
|
||||
* Class Order
|
||||
*
|
||||
* @package Opencart\Admin\Model\Sale
|
||||
*/
|
||||
class Order extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @param int $order_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getOrder(int $order_id): array {
|
||||
$order_query = $this->db->query("SELECT *, (SELECT `os`.`name` FROM `" . DB_PREFIX . "order_status` os WHERE `os`.`order_status_id` = `o`.`order_status_id` AND `os`.`language_id` = '" . (int)$this->config->get('config_language_id') . "') AS `order_status` FROM `" . DB_PREFIX . "order` `o` WHERE `o`.`order_id` = '" . (int)$order_id . "'");
|
||||
|
||||
if ($order_query->num_rows) {
|
||||
$country_query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "country` WHERE `country_id` = '" . (int)$order_query->row['payment_country_id'] . "'");
|
||||
|
||||
if ($country_query->num_rows) {
|
||||
$payment_iso_code_2 = $country_query->row['iso_code_2'];
|
||||
$payment_iso_code_3 = $country_query->row['iso_code_3'];
|
||||
} else {
|
||||
$payment_iso_code_2 = '';
|
||||
$payment_iso_code_3 = '';
|
||||
}
|
||||
|
||||
$zone_query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "zone` WHERE `zone_id` = '" . (int)$order_query->row['payment_zone_id'] . "'");
|
||||
|
||||
if ($zone_query->num_rows) {
|
||||
$payment_zone_code = $zone_query->row['code'];
|
||||
} else {
|
||||
$payment_zone_code = '';
|
||||
}
|
||||
|
||||
$country_query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "country` WHERE `country_id` = '" . (int)$order_query->row['shipping_country_id'] . "'");
|
||||
|
||||
if ($country_query->num_rows) {
|
||||
$shipping_iso_code_2 = $country_query->row['iso_code_2'];
|
||||
$shipping_iso_code_3 = $country_query->row['iso_code_3'];
|
||||
} else {
|
||||
$shipping_iso_code_2 = '';
|
||||
$shipping_iso_code_3 = '';
|
||||
}
|
||||
|
||||
$zone_query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "zone` WHERE `zone_id` = '" . (int)$order_query->row['shipping_zone_id'] . "'");
|
||||
|
||||
if ($zone_query->num_rows) {
|
||||
$shipping_zone_code = $zone_query->row['code'];
|
||||
} else {
|
||||
$shipping_zone_code = '';
|
||||
}
|
||||
|
||||
$reward = 0;
|
||||
|
||||
$order_product_query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "order_product` WHERE `order_id` = '" . (int)$order_id . "'");
|
||||
|
||||
foreach ($order_product_query->rows as $product) {
|
||||
$reward += $product['reward'];
|
||||
}
|
||||
|
||||
$this->load->model('customer/customer');
|
||||
|
||||
$affiliate_info = $this->model_customer_customer->getCustomer($order_query->row['affiliate_id']);
|
||||
|
||||
if ($affiliate_info) {
|
||||
$affiliate = $affiliate_info['firstname'] . ' ' . $affiliate_info['lastname'];
|
||||
} else {
|
||||
$affiliate = '';
|
||||
}
|
||||
|
||||
$this->load->model('localisation/language');
|
||||
|
||||
$language_info = $this->model_localisation_language->getLanguage($order_query->row['language_id']);
|
||||
|
||||
if ($language_info) {
|
||||
$language_code = $language_info['code'];
|
||||
} else {
|
||||
$language_code = $this->config->get('config_language');
|
||||
}
|
||||
|
||||
return [
|
||||
'order_id' => $order_query->row['order_id'],
|
||||
'invoice_no' => $order_query->row['invoice_no'],
|
||||
'invoice_prefix' => $order_query->row['invoice_prefix'],
|
||||
'store_id' => $order_query->row['store_id'],
|
||||
'store_name' => $order_query->row['store_name'],
|
||||
'store_url' => $order_query->row['store_url'],
|
||||
'customer_id' => $order_query->row['customer_id'],
|
||||
'customer_group_id' => $order_query->row['customer_group_id'],
|
||||
'firstname' => $order_query->row['firstname'],
|
||||
'lastname' => $order_query->row['lastname'],
|
||||
'email' => $order_query->row['email'],
|
||||
'telephone' => $order_query->row['telephone'],
|
||||
'custom_field' => json_decode($order_query->row['custom_field'], true),
|
||||
'payment_address_id' => $order_query->row['payment_address_id'],
|
||||
'payment_firstname' => $order_query->row['payment_firstname'],
|
||||
'payment_lastname' => $order_query->row['payment_lastname'],
|
||||
'payment_company' => $order_query->row['payment_company'],
|
||||
'payment_address_1' => $order_query->row['payment_address_1'],
|
||||
'payment_address_2' => $order_query->row['payment_address_2'],
|
||||
'payment_postcode' => $order_query->row['payment_postcode'],
|
||||
'payment_city' => $order_query->row['payment_city'],
|
||||
'payment_zone_id' => $order_query->row['payment_zone_id'],
|
||||
'payment_zone' => $order_query->row['payment_zone'],
|
||||
'payment_zone_code' => $payment_zone_code,
|
||||
'payment_country_id' => $order_query->row['payment_country_id'],
|
||||
'payment_country' => $order_query->row['payment_country'],
|
||||
'payment_iso_code_2' => $payment_iso_code_2,
|
||||
'payment_iso_code_3' => $payment_iso_code_3,
|
||||
'payment_address_format' => $order_query->row['payment_address_format'],
|
||||
'payment_custom_field' => json_decode($order_query->row['payment_custom_field'], true),
|
||||
'payment_method' => json_decode($order_query->row['payment_method'], true),
|
||||
'shipping_address_id' => $order_query->row['shipping_address_id'],
|
||||
'shipping_firstname' => $order_query->row['shipping_firstname'],
|
||||
'shipping_lastname' => $order_query->row['shipping_lastname'],
|
||||
'shipping_company' => $order_query->row['shipping_company'],
|
||||
'shipping_address_1' => $order_query->row['shipping_address_1'],
|
||||
'shipping_address_2' => $order_query->row['shipping_address_2'],
|
||||
'shipping_postcode' => $order_query->row['shipping_postcode'],
|
||||
'shipping_city' => $order_query->row['shipping_city'],
|
||||
'shipping_zone_id' => $order_query->row['shipping_zone_id'],
|
||||
'shipping_zone' => $order_query->row['shipping_zone'],
|
||||
'shipping_zone_code' => $shipping_zone_code,
|
||||
'shipping_country_id' => $order_query->row['shipping_country_id'],
|
||||
'shipping_country' => $order_query->row['shipping_country'],
|
||||
'shipping_iso_code_2' => $shipping_iso_code_2,
|
||||
'shipping_iso_code_3' => $shipping_iso_code_3,
|
||||
'shipping_address_format' => $order_query->row['shipping_address_format'],
|
||||
'shipping_custom_field' => json_decode($order_query->row['shipping_custom_field'], true),
|
||||
'shipping_method' => json_decode($order_query->row['shipping_method'], true),
|
||||
'comment' => $order_query->row['comment'],
|
||||
'total' => $order_query->row['total'],
|
||||
'reward' => $reward,
|
||||
'order_status_id' => $order_query->row['order_status_id'],
|
||||
'order_status' => $order_query->row['order_status'],
|
||||
'affiliate_id' => $order_query->row['affiliate_id'],
|
||||
'affiliate' => $affiliate,
|
||||
'commission' => $order_query->row['commission'],
|
||||
'language_id' => $order_query->row['language_id'],
|
||||
'language_code' => $language_code,
|
||||
'currency_id' => $order_query->row['currency_id'],
|
||||
'currency_code' => $order_query->row['currency_code'],
|
||||
'currency_value' => $order_query->row['currency_value'],
|
||||
'ip' => $order_query->row['ip'],
|
||||
'forwarded_ip' => $order_query->row['forwarded_ip'],
|
||||
'user_agent' => $order_query->row['user_agent'],
|
||||
'accept_language' => $order_query->row['accept_language'],
|
||||
'date_added' => $order_query->row['date_added'],
|
||||
'date_modified' => $order_query->row['date_modified']
|
||||
];
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getOrders(array $data = []): array {
|
||||
$sql = "SELECT o.`order_id`, CONCAT(o.`firstname`, ' ', o.`lastname`) AS customer, (SELECT os.`name` FROM `" . DB_PREFIX . "order_status` os WHERE os.`order_status_id` = o.`order_status_id` AND os.`language_id` = '" . (int)$this->config->get('config_language_id') . "') AS order_status, o.`store_name`, o.`shipping_method`, o.`total`, o.`currency_code`, o.`currency_value`, o.`date_added`, o.`date_modified` FROM `" . DB_PREFIX . "order` o";
|
||||
|
||||
if (!empty($data['filter_order_status'])) {
|
||||
$implode = [];
|
||||
|
||||
$order_statuses = explode(',', $data['filter_order_status']);
|
||||
|
||||
foreach ($order_statuses as $order_status_id) {
|
||||
$implode[] = "o.`order_status_id` = '" . (int)$order_status_id . "'";
|
||||
}
|
||||
|
||||
if ($implode) {
|
||||
$sql .= " WHERE (" . implode(" OR ", $implode) . ")";
|
||||
}
|
||||
} elseif (isset($data['filter_order_status_id']) && $data['filter_order_status_id'] !== '') {
|
||||
$sql .= " WHERE o.`order_status_id` = '" . (int)$data['filter_order_status_id'] . "'";
|
||||
} else {
|
||||
$sql .= " WHERE o.`order_status_id` > '0'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_order_id'])) {
|
||||
$sql .= " AND o.`order_id` = '" . (int)$data['filter_order_id'] . "'";
|
||||
}
|
||||
|
||||
if (isset($data['filter_store_id']) && $data['filter_store_id'] !== '') {
|
||||
$sql .= " AND o.`store_id` = '" . (int)$data['filter_store_id'] . "'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_customer_id'])) {
|
||||
$sql .= " AND o.`customer_id` = '" . (int)$data['filter_customer_id'] . "'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_customer'])) {
|
||||
$sql .= " AND CONCAT(o.`firstname`, ' ', o.`lastname`) LIKE '" . $this->db->escape('%' . (string)$data['filter_customer'] . '%') . "'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_email'])) {
|
||||
$sql .= " AND o.`email` LIKE '" . $this->db->escape('%' . (string)$data['filter_email'] . '%') . "'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_date_from'])) {
|
||||
$sql .= " AND DATE(o.`date_added`) >= DATE('" . $this->db->escape((string)$data['filter_date_from']) . "')";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_date_to'])) {
|
||||
$sql .= " AND DATE(o.`date_added`) <= DATE('" . $this->db->escape((string)$data['filter_date_to']) . "')";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_total'])) {
|
||||
$sql .= " AND o.`total` = '" . (float)$data['filter_total'] . "'";
|
||||
}
|
||||
|
||||
$sort_data = [
|
||||
'o.order_id',
|
||||
'o.store_name',
|
||||
'customer',
|
||||
'order_status',
|
||||
'o.date_added',
|
||||
'o.date_modified',
|
||||
'o.total'
|
||||
];
|
||||
|
||||
if (isset($data['sort']) && in_array($data['sort'], $sort_data)) {
|
||||
$sql .= " ORDER BY " . $data['sort'];
|
||||
} else {
|
||||
$sql .= " ORDER BY o.`order_id`";
|
||||
}
|
||||
|
||||
if (isset($data['order']) && ($data['order'] == 'DESC')) {
|
||||
$sql .= " DESC";
|
||||
} else {
|
||||
$sql .= " ASC";
|
||||
}
|
||||
|
||||
if (isset($data['start']) || isset($data['limit'])) {
|
||||
if ($data['start'] < 0) {
|
||||
$data['start'] = 0;
|
||||
}
|
||||
|
||||
if ($data['limit'] < 1) {
|
||||
$data['limit'] = 20;
|
||||
}
|
||||
|
||||
$sql .= " LIMIT " . (int)$data['start'] . "," . (int)$data['limit'];
|
||||
}
|
||||
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
return $query->rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $subscription_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getOrdersBySubscriptionId(int $subscription_id): array {
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "order` WHERE `subscription_id` = '" . (int)$subscription_id . "'");
|
||||
|
||||
return $query->rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $subscription_id
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalOrdersBySubscriptionId(int $subscription_id): int {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "order` WHERE `subscription_id` = '" . (int)$subscription_id . "'");
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $order_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getProducts(int $order_id): array {
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "order_product` WHERE `order_id` = '" . (int)$order_id . "' ORDER BY order_product_id ASC");
|
||||
|
||||
return $query->rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $product_id
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalProductsByProductId(int $product_id): int {
|
||||
$sql = "SELECT SUM(op.quantity) AS `total` FROM `" . DB_PREFIX . "order_product` `op` LEFT JOIN `" . DB_PREFIX . "order` `o` ON (`op`.`order_id` = `o`.`order_id`) WHERE `op`.`product_id` = '" . (int)$product_id . "'";
|
||||
|
||||
if (!empty($data['filter_order_status'])) {
|
||||
$implode = [];
|
||||
|
||||
$order_statuses = explode(',', $data['filter_order_status']);
|
||||
|
||||
foreach ($order_statuses as $order_status_id) {
|
||||
$implode[] = "`order_status_id` = '" . (int)$order_status_id . "'";
|
||||
}
|
||||
|
||||
if ($implode) {
|
||||
$sql .= " AND (" . implode(" OR ", $implode) . ")";
|
||||
}
|
||||
} elseif (isset($data['filter_order_status_id']) && $data['filter_order_status_id'] !== '') {
|
||||
$sql .= " AND `order_status_id` = '" . (int)$data['filter_order_status_id'] . "'";
|
||||
} else {
|
||||
$sql .= " AND `order_status_id` > '0'";
|
||||
}
|
||||
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $order_id
|
||||
* @param int $order_product_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getOptions(int $order_id, int $order_product_id): array {
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "order_option` WHERE `order_id` = '" . (int)$order_id . "' AND `order_product_id` = '" . (int)$order_product_id . "'");
|
||||
|
||||
return $query->rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $order_id
|
||||
* @param int $order_product_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getSubscription(int $order_id, int $order_product_id): array {
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "order_subscription` WHERE `order_id` = '" . (int)$order_id . "' AND `order_product_id` = '" . (int)$order_product_id . "'");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $order_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getVouchers(int $order_id): array {
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "order_voucher` WHERE `order_id` = '" . (int)$order_id . "'");
|
||||
|
||||
return $query->rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $voucher_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getVoucherByVoucherId(int $voucher_id): array {
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "order_voucher` WHERE `voucher_id` = '" . (int)$voucher_id . "'");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $order_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getTotals(int $order_id): array {
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "order_total` WHERE `order_id` = '" . (int)$order_id . "' ORDER BY `sort_order`");
|
||||
|
||||
return $query->rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalOrders(array $data = []): int {
|
||||
$sql = "SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "order`";
|
||||
|
||||
if (!empty($data['filter_order_status'])) {
|
||||
$implode = [];
|
||||
|
||||
$order_statuses = explode(',', $data['filter_order_status']);
|
||||
|
||||
foreach ($order_statuses as $order_status_id) {
|
||||
$implode[] = "`order_status_id` = '" . (int)$order_status_id . "'";
|
||||
}
|
||||
|
||||
if ($implode) {
|
||||
$sql .= " WHERE (" . implode(" OR ", $implode) . ")";
|
||||
}
|
||||
} elseif (isset($data['filter_order_status_id']) && $data['filter_order_status_id'] !== '') {
|
||||
$sql .= " WHERE `order_status_id` = '" . (int)$data['filter_order_status_id'] . "'";
|
||||
} else {
|
||||
$sql .= " WHERE `order_status_id` > '0'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_order_id'])) {
|
||||
$sql .= " AND `order_id` = '" . (int)$data['filter_order_id'] . "'";
|
||||
}
|
||||
|
||||
if (isset($data['filter_store_id']) && $data['filter_store_id'] !== '') {
|
||||
$sql .= " AND `store_id` = '" . (int)$data['filter_store_id'] . "'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_customer_id'])) {
|
||||
$sql .= " AND `customer_id` = '" . (int)$data['filter_customer_id'] . "'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_customer'])) {
|
||||
$sql .= " AND CONCAT(`firstname`, ' ', `lastname`) LIKE '" . $this->db->escape('%' . (string)$data['filter_customer'] . '%') . "'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_email'])) {
|
||||
$sql .= " AND `email` LIKE '" . $this->db->escape('%' . (string)$data['filter_email'] . '%') . "'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_date_from'])) {
|
||||
$sql .= " AND DATE(`date_added`) >= DATE('" . $this->db->escape((string)$data['filter_date_from']) . "')";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_date_to'])) {
|
||||
$sql .= " AND DATE(`date_added`) <= DATE('" . $this->db->escape((string)$data['filter_date_to']) . "')";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_total'])) {
|
||||
$sql .= " AND `total` = '" . (float)$data['filter_total'] . "'";
|
||||
}
|
||||
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $store_id
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalOrdersByStoreId(int $store_id): int {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "order` WHERE `store_id` = '" . (int)$store_id . "'");
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $order_status_id
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalOrdersByOrderStatusId(int $order_status_id): int {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "order` WHERE `order_status_id` = '" . (int)$order_status_id . "' AND `order_status_id` > '0'");
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalOrdersByProcessingStatus(): int {
|
||||
$implode = [];
|
||||
|
||||
$order_statuses = $this->config->get('config_processing_status');
|
||||
|
||||
foreach ($order_statuses as $order_status_id) {
|
||||
$implode[] = "`order_status_id` = '" . (int)$order_status_id . "'";
|
||||
}
|
||||
|
||||
if ($implode) {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "order` WHERE " . implode(" OR ", $implode));
|
||||
|
||||
return (int)$query->row['total'];
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalOrdersByCompleteStatus(): int {
|
||||
$implode = [];
|
||||
|
||||
$order_statuses = $this->config->get('config_complete_status');
|
||||
|
||||
foreach ($order_statuses as $order_status_id) {
|
||||
$implode[] = "`order_status_id` = '" . (int)$order_status_id . "'";
|
||||
}
|
||||
|
||||
if ($implode) {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "order` WHERE " . implode(" OR ", $implode) . "");
|
||||
|
||||
return (int)$query->row['total'];
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $language_id
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalOrdersByLanguageId(int $language_id): int {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "order` WHERE `language_id` = '" . (int)$language_id . "' AND `order_status_id` > '0'");
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $currency_id
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalOrdersByCurrencyId(int $currency_id): int {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "order` WHERE `currency_id` = '" . (int)$currency_id . "' AND `order_status_id` > '0'");
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public function getTotalSales(array $data = []): float {
|
||||
$sql = "SELECT SUM(`total`) AS `total` FROM `" . DB_PREFIX . "order`";
|
||||
|
||||
if (!empty($data['filter_order_status'])) {
|
||||
$implode = [];
|
||||
|
||||
$order_statuses = explode(',', $data['filter_order_status']);
|
||||
|
||||
foreach ($order_statuses as $order_status_id) {
|
||||
$implode[] = "`order_status_id` = '" . (int)$order_status_id . "'";
|
||||
}
|
||||
|
||||
if ($implode) {
|
||||
$sql .= " WHERE (" . implode(" OR ", $implode) . ")";
|
||||
}
|
||||
} elseif (isset($data['filter_order_status_id']) && $data['filter_order_status_id'] !== '') {
|
||||
$sql .= " WHERE `order_status_id` = '" . (int)$data['filter_order_status_id'] . "'";
|
||||
} else {
|
||||
$sql .= " WHERE `order_status_id` > '0'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_order_id'])) {
|
||||
$sql .= " AND `order_id` = '" . (int)$data['filter_order_id'] . "'";
|
||||
}
|
||||
|
||||
if (isset($data['filter_store_id']) && $data['filter_store_id'] !== '') {
|
||||
$sql .= " AND `store_id` = '" . (int)$data['filter_store_id'] . "'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_customer_id'])) {
|
||||
$sql .= " AND `customer_id` = '" . (int)$data['filter_customer_id'] . "'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_customer'])) {
|
||||
$sql .= " AND CONCAT(`firstname`, ' ', `lastname`) LIKE '" . $this->db->escape('%' . (string)$data['filter_customer'] . '%') . "'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_email'])) {
|
||||
$sql .= " AND `email` LIKE '" . $this->db->escape('%' . (string)$data['filter_email'] . '%') . "'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_date_added'])) {
|
||||
$sql .= " AND DATE(`date_added`) = DATE('" . $this->db->escape((string)$data['filter_date_added']) . "')";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_date_modified'])) {
|
||||
$sql .= " AND DATE(`date_modified`) = DATE('" . $this->db->escape((string)$data['filter_date_modified']) . "')";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_total'])) {
|
||||
$sql .= " AND `total` = '" . (float)$data['filter_total'] . "'";
|
||||
}
|
||||
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $order_id
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function createInvoiceNo(int $order_id): string {
|
||||
$order_info = $this->getOrder($order_id);
|
||||
|
||||
if ($order_info && !$order_info['invoice_no']) {
|
||||
$query = $this->db->query("SELECT MAX(`invoice_no`) AS invoice_no FROM `" . DB_PREFIX . "order` WHERE `invoice_prefix` = '" . $this->db->escape($order_info['invoice_prefix']) . "'");
|
||||
|
||||
if ($query->row['invoice_no']) {
|
||||
$invoice_no = $query->row['invoice_no'] + 1;
|
||||
} else {
|
||||
$invoice_no = 1;
|
||||
}
|
||||
|
||||
$this->db->query("UPDATE `" . DB_PREFIX . "order` SET `invoice_no` = '" . (int)$invoice_no . "', `invoice_prefix` = '" . $this->db->escape($order_info['invoice_prefix']) . "' WHERE `order_id` = '" . (int)$order_id . "'");
|
||||
|
||||
return $order_info['invoice_prefix'] . $invoice_no;
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $order_id
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getRewardTotal(int $order_id): int {
|
||||
$query = $this->db->query("SELECT SUM(reward) AS `total` FROM `" . DB_PREFIX . "order_product` WHERE `order_id` = '" . (int)$order_id . "'");
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $order_id
|
||||
* @param int $start
|
||||
* @param int $limit
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getHistories(int $order_id, int $start = 0, int $limit = 10): array {
|
||||
if ($start < 0) {
|
||||
$start = 0;
|
||||
}
|
||||
|
||||
if ($limit < 1) {
|
||||
$limit = 10;
|
||||
}
|
||||
|
||||
$query = $this->db->query("SELECT oh.`date_added`, os.`name` AS `status`, oh.`comment`, oh.`notify` FROM `" . DB_PREFIX . "order_history` oh LEFT JOIN `" . DB_PREFIX . "order_status` os ON oh.`order_status_id` = os.`order_status_id` WHERE oh.`order_id` = '" . (int)$order_id . "' AND os.`language_id` = '" . (int)$this->config->get('config_language_id') . "' ORDER BY oh.`date_added` DESC LIMIT " . (int)$start . "," . (int)$limit);
|
||||
|
||||
return $query->rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $order_id
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalHistories(int $order_id): int {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "order_history` WHERE `order_id` = '" . (int)$order_id . "'");
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $order_status_id
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalHistoriesByOrderStatusId(int $order_status_id): int {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "order_history` WHERE `order_status_id` = '" . (int)$order_status_id . "'");
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $products
|
||||
* @param int $start
|
||||
* @param int $end
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getEmailsByProductsOrdered(array $products, int $start, int $end): array {
|
||||
$implode = [];
|
||||
|
||||
foreach ($products as $product_id) {
|
||||
$implode[] = "op.`product_id` = '" . (int)$product_id . "'";
|
||||
}
|
||||
|
||||
$query = $this->db->query("SELECT DISTINCT o.`email` FROM `" . DB_PREFIX . "order` o LEFT JOIN `" . DB_PREFIX . "order_product` op ON (o.`order_id` = op.`order_id`) WHERE (" . implode(" OR ", $implode) . ") AND o.`order_status_id` <> '0' LIMIT " . (int)$start . "," . (int)$end);
|
||||
|
||||
return $query->rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $products
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalEmailsByProductsOrdered(array $products): int {
|
||||
$implode = [];
|
||||
|
||||
foreach ($products as $product_id) {
|
||||
$implode[] = "op.`product_id` = '" . (int)$product_id . "'";
|
||||
}
|
||||
|
||||
$query = $this->db->query("SELECT COUNT(DISTINCT o.`email`) AS `total` FROM `" . DB_PREFIX . "order` o LEFT JOIN `" . DB_PREFIX . "order_product` op ON (o.`order_id` = op.`order_id`) WHERE (" . implode(" OR ", $implode) . ") AND o.`order_status_id` <> '0'");
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
}
|
276
admininistrator/model/sale/returns.php
Normal file
276
admininistrator/model/sale/returns.php
Normal file
@ -0,0 +1,276 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Model\Sale;
|
||||
/**
|
||||
* Class Returns
|
||||
*
|
||||
* @package Opencart\Admin\Model\Sale
|
||||
*/
|
||||
class Returns extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function addReturn(array $data): int {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "return` SET `order_id` = '" . (int)$data['order_id'] . "', `product_id` = '" . (int)$data['product_id'] . "', `customer_id` = '" . (int)$data['customer_id'] . "', `firstname` = '" . $this->db->escape((string)$data['firstname']) . "', `lastname` = '" . $this->db->escape((string)$data['lastname']) . "', `email` = '" . $this->db->escape((string)$data['email']) . "', `telephone` = '" . $this->db->escape((string)$data['telephone']) . "', `product` = '" . $this->db->escape((string)$data['product']) . "', `model` = '" . $this->db->escape((string)$data['model']) . "', `quantity` = '" . (int)$data['quantity'] . "', `opened` = '" . (int)$data['opened'] . "', `return_reason_id` = '" . (int)$data['return_reason_id'] . "', `return_action_id` = '" . (int)$data['return_action_id'] . "', `return_status_id` = '" . (int)$data['return_status_id'] . "', `comment` = '" . $this->db->escape((string)$data['comment']) . "', `date_ordered` = '" . $this->db->escape((string)$data['date_ordered']) . "', `date_added` = NOW(), `date_modified` = NOW()");
|
||||
|
||||
return $this->db->getLastId();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $return_id
|
||||
* @param array $data
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function editReturn(int $return_id, array $data): void {
|
||||
$this->db->query("UPDATE `" . DB_PREFIX . "return` SET `order_id` = '" . (int)$data['order_id'] . "', `product_id` = '" . (int)$data['product_id'] . "', `customer_id` = '" . (int)$data['customer_id'] . "', `firstname` = '" . $this->db->escape((string)$data['firstname']) . "', `lastname` = '" . $this->db->escape((string)$data['lastname']) . "', `email` = '" . $this->db->escape((string)$data['email']) . "', `telephone` = '" . $this->db->escape((string)$data['telephone']) . "', `product` = '" . $this->db->escape((string)$data['product']) . "', `model` = '" . $this->db->escape((string)$data['model']) . "', `quantity` = '" . (int)$data['quantity'] . "', `opened` = '" . (int)$data['opened'] . "', `return_reason_id` = '" . (int)$data['return_reason_id'] . "', `return_action_id` = '" . (int)$data['return_action_id'] . "', `comment` = '" . $this->db->escape((string)$data['comment']) . "', `date_ordered` = '" . $this->db->escape((string)$data['date_ordered']) . "', `date_modified` = NOW() WHERE `return_id` = '" . (int)$return_id . "'");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $return_id
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function deleteReturn(int $return_id): void {
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "return` WHERE `return_id` = '" . (int)$return_id . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "return_history` WHERE `return_id` = '" . (int)$return_id . "'");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $return_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getReturn(int $return_id): array {
|
||||
$query = $this->db->query("SELECT DISTINCT *, (SELECT CONCAT(c.`firstname`, ' ', c.`lastname`) FROM `" . DB_PREFIX . "customer` c WHERE c.`customer_id` = r.`customer_id`) AS customer, (SELECT c.`language_id` FROM `" . DB_PREFIX . "customer` c WHERE c.`customer_id` = r.`customer_id`) AS language_id, (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 return_status FROM `" . DB_PREFIX . "return` r WHERE r.`return_id` = '" . (int)$return_id . "'");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getReturns(array $data = []): array {
|
||||
$sql = "SELECT *, CONCAT(r.`firstname`, ' ', r.`lastname`) AS customer, (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 return_status FROM `" . DB_PREFIX . "return` r";
|
||||
|
||||
$implode = [];
|
||||
|
||||
if (!empty($data['filter_return_id'])) {
|
||||
$implode[] = "r.`return_id` = '" . (int)$data['filter_return_id'] . "'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_order_id'])) {
|
||||
$implode[] = "r.`order_id` = '" . (int)$data['filter_order_id'] . "'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_customer'])) {
|
||||
$implode[] = "CONCAT(r.`firstname`, ' ', r.`lastname`) LIKE '" . $this->db->escape((string)$data['filter_customer'] . '%') . "'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_product'])) {
|
||||
$implode[] = "r.`product` = '" . $this->db->escape((string)$data['filter_product']) . "'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_model'])) {
|
||||
$implode[] = "r.`model` = '" . $this->db->escape((string)$data['filter_model']) . "'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_return_status_id'])) {
|
||||
$implode[] = "r.`return_status_id` = '" . (int)$data['filter_return_status_id'] . "'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_date_from'])) {
|
||||
$implode[] = "DATE(r.`date_added`) >= DATE('" . $this->db->escape((string)$data['filter_date_from']) . "')";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_date_to'])) {
|
||||
$implode[] = "DATE(r.`date_added`) <= DATE('" . $this->db->escape((string)$data['filter_date_to']) . "')";
|
||||
}
|
||||
|
||||
if ($implode) {
|
||||
$sql .= " WHERE " . implode(" AND ", $implode);
|
||||
}
|
||||
|
||||
$sort_data = [
|
||||
'r.return_id',
|
||||
'r.order_id',
|
||||
'customer',
|
||||
'r.product',
|
||||
'r.model',
|
||||
'return_status',
|
||||
'r.date_added',
|
||||
'r.date_modified'
|
||||
];
|
||||
|
||||
if (isset($data['sort']) && in_array($data['sort'], $sort_data)) {
|
||||
$sql .= " ORDER BY " . $data['sort'];
|
||||
} else {
|
||||
$sql .= " ORDER BY r.`return_id`";
|
||||
}
|
||||
|
||||
if (isset($data['order']) && ($data['order'] == 'DESC')) {
|
||||
$sql .= " DESC";
|
||||
} else {
|
||||
$sql .= " ASC";
|
||||
}
|
||||
|
||||
if (isset($data['start']) || isset($data['limit'])) {
|
||||
if ($data['start'] < 0) {
|
||||
$data['start'] = 0;
|
||||
}
|
||||
|
||||
if ($data['limit'] < 1) {
|
||||
$data['limit'] = 20;
|
||||
}
|
||||
|
||||
$sql .= " LIMIT " . (int)$data['start'] . "," . (int)$data['limit'];
|
||||
}
|
||||
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
return $query->rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalReturns(array $data = []): int {
|
||||
$sql = "SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "return` r";
|
||||
|
||||
$implode = [];
|
||||
|
||||
if (!empty($data['filter_return_id'])) {
|
||||
$implode[] = "r.`return_id` = '" . (int)$data['filter_return_id'] . "'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_customer'])) {
|
||||
$implode[] = "CONCAT(r.`firstname`, ' ', r.`lastname`) LIKE '" . $this->db->escape((string)$data['filter_customer'] . '%') . "'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_order_id'])) {
|
||||
$implode[] = "r.`order_id` = '" . $this->db->escape((string)$data['filter_order_id']) . "'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_product'])) {
|
||||
$implode[] = "r.`product` = '" . $this->db->escape((string)$data['filter_product']) . "'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_model'])) {
|
||||
$implode[] = "r.`model` = '" . $this->db->escape((string)$data['filter_model']) . "'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_return_status_id'])) {
|
||||
$implode[] = "r.`return_status_id` = '" . (int)$data['filter_return_status_id'] . "'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_date_from'])) {
|
||||
$implode[] = "DATE(r.`date_added`) >= DATE('" . $this->db->escape((string)$data['filter_date_from']) . "')";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_date_to'])) {
|
||||
$implode[] = "DATE(r.`date_added`) <= DATE('" . $this->db->escape((string)$data['filter_date_to']) . "')";
|
||||
}
|
||||
|
||||
if ($implode) {
|
||||
$sql .= " WHERE " . implode(" AND ", $implode);
|
||||
}
|
||||
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $return_status_id
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalReturnsByReturnStatusId(int $return_status_id): int {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "return` WHERE `return_status_id` = '" . (int)$return_status_id . "'");
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $return_reason_id
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalReturnsByReturnReasonId(int $return_reason_id): int {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "return` WHERE `return_reason_id` = '" . (int)$return_reason_id . "'");
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $return_action_id
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalReturnsByReturnActionId(int $return_action_id): int {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "return` WHERE `return_action_id` = '" . (int)$return_action_id . "'");
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $return_id
|
||||
* @param int $return_status_id
|
||||
* @param string $comment
|
||||
* @param bool $notify
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function addHistory(int $return_id, int $return_status_id, string $comment, bool $notify): void {
|
||||
$this->db->query("UPDATE `" . DB_PREFIX . "return` SET `return_status_id` = '" . (int)$return_status_id . "', `date_modified` = NOW() WHERE `return_id` = '" . (int)$return_id . "'");
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "return_history` SET `return_id` = '" . (int)$return_id . "', `return_status_id` = '" . (int)$return_status_id . "', `notify` = '" . (int)$notify . "', `comment` = '" . $this->db->escape(strip_tags($comment)) . "', `date_added` = NOW()");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $return_id
|
||||
* @param int $start
|
||||
* @param int $limit
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getHistories(int $return_id, int $start = 0, int $limit = 10): array {
|
||||
if ($start < 0) {
|
||||
$start = 0;
|
||||
}
|
||||
|
||||
if ($limit < 1) {
|
||||
$limit = 10;
|
||||
}
|
||||
|
||||
$query = $this->db->query("SELECT rh.`date_added`, rs.`name` AS status, rh.`comment`, rh.`notify` 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` DESC LIMIT " . (int)$start . "," . (int)$limit);
|
||||
|
||||
return $query->rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $return_id
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalHistories(int $return_id): int {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "return_history` WHERE `return_id` = '" . (int)$return_id . "'");
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $return_status_id
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalHistoriesByReturnStatusId(int $return_status_id): int {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "return_history` WHERE `return_status_id` = '" . (int)$return_status_id . "'");
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
}
|
306
admininistrator/model/sale/subscription.php
Normal file
306
admininistrator/model/sale/subscription.php
Normal file
@ -0,0 +1,306 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Model\Sale;
|
||||
/**
|
||||
* Class Subscription
|
||||
*
|
||||
* @package Opencart\Admin\Model\Sale
|
||||
*/
|
||||
class Subscription extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @param int $subscription_id
|
||||
* @param array $data
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function editSubscription(int $subscription_id, array $data): void {
|
||||
$this->db->query("UPDATE `" . DB_PREFIX . "subscription` SET `subscription_plan_id` = '" . (int)$data['subscription_plan_id'] . "', `customer_payment_id` = '" . (int)$data['customer_payment_id'] . "' WHERE `subscription_id` = '" . (int)$subscription_id . "'");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $subscription_id
|
||||
* @param int $customer_payment_id
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function editPaymentMethod(int $subscription_id, int $customer_payment_id): void {
|
||||
$this->db->query("UPDATE `" . DB_PREFIX . "subscription` SET `customer_payment_id ` = '" . (int)$customer_payment_id . "' WHERE `subscription_id` = '" . (int)$subscription_id . "'");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $subscription_id
|
||||
* @param int $subscription_plan_id
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function editSubscriptionPlan(int $subscription_id, int $subscription_plan_id): void {
|
||||
$this->db->query("UPDATE `" . DB_PREFIX . "subscription` SET `subscription_plan_id` = '" . (int)$subscription_plan_id . "' WHERE `subscription_id` = '" . (int)$subscription_id . "'");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $subscription_id
|
||||
* @param int $remaining
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function editRemaining(int $subscription_id, int $remaining): void {
|
||||
$this->db->query("UPDATE `" . DB_PREFIX . "subscription` SET `remaining` = '" . (int)$remaining . "' WHERE `subscription_id` = '" . (int)$subscription_id . "'");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $subscription_id
|
||||
* @param int $trial_remaining
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function editTrialRemaining(int $subscription_id, int $trial_remaining): void {
|
||||
$this->db->query("UPDATE `" . DB_PREFIX . "subscription` SET `trial_remaining` = '" . (int)$trial_remaining . "' WHERE `subscription_id` = '" . (int)$subscription_id . "'");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $subscription_id
|
||||
* @param string $date_next
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function editDateNext(int $subscription_id, string $date_next): void {
|
||||
$this->db->query("UPDATE `" . DB_PREFIX . "subscription` SET `date_next` = '" . $this->db->escape($date_next) . "' WHERE `subscription_id` = '" . (int)$subscription_id . "'");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $subscription_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getSubscription(int $subscription_id): array {
|
||||
$subscription_data = [];
|
||||
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "subscription` WHERE `subscription_id` = '" . (int)$subscription_id . "'");
|
||||
|
||||
if ($query->num_rows) {
|
||||
$subscription_data = $query->row;
|
||||
|
||||
$subscription_data['payment_method'] = ($query->row['payment_method'] ? json_decode($query->row['payment_method'], true) : '');
|
||||
$subscription_data['shipping_method'] = ($query->row['shipping_method'] ? json_decode($query->row['shipping_method'], true) : '');
|
||||
}
|
||||
|
||||
return $subscription_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $order_id
|
||||
* @param int $order_product_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getSubscriptionByOrderProductId(int $order_id, int $order_product_id): array {
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "subscription` WHERE `order_id` = '" . (int)$order_id . "' AND `order_product_id` = '" . (int)$order_product_id . "'");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getSubscriptions(array $data): array {
|
||||
$sql = "SELECT `s`.`subscription_id`, `s`.*, CONCAT(o.`firstname`, ' ', o.`lastname`) AS customer, (SELECT ss.`name` FROM `" . DB_PREFIX . "subscription_status` ss WHERE ss.`subscription_status_id` = s.`subscription_status_id` AND ss.`language_id` = '" . (int)$this->config->get('config_language_id') . "') AS subscription_status FROM `" . DB_PREFIX . "subscription` `s` LEFT JOIN `" . DB_PREFIX . "order` `o` ON (`s`.`order_id` = `o`.`order_id`)";
|
||||
|
||||
$implode = [];
|
||||
|
||||
if (!empty($data['filter_subscription_id'])) {
|
||||
$implode[] = "`s`.`subscription_id` = '" . (int)$data['filter_subscription_id'] . "'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_order_id'])) {
|
||||
$implode[] = "`s`.`order_id` = '" . (int)$data['filter_order_id'] . "'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_order_product_id'])) {
|
||||
$implode[] = "`s`.`order_product_id` = '" . (int)$data['filter_order_product_id'] . "'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_customer'])) {
|
||||
$implode[] = "CONCAT(o.`firstname`, ' ', o.`lastname`) LIKE '" . $this->db->escape((string)$data['filter_customer'] . '%') . "'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_date_next'])) {
|
||||
$implode[] = "DATE(`s`.`date_next`) = DATE('" . $this->db->escape((string)$data['filter_date_next']) . "')";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_subscription_status_id'])) {
|
||||
$implode[] = "`s`.`subscription_status_id` = '" . (int)$data['filter_subscription_status_id'] . "'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_date_from'])) {
|
||||
$implode[] = "DATE(s.`date_added`) >= DATE('" . $this->db->escape((string)$data['filter_date_from']) . "')";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_date_to'])) {
|
||||
$implode[] = "DATE(s.`date_added`) <= DATE('" . $this->db->escape((string)$data['filter_date_to']) . "')";
|
||||
}
|
||||
|
||||
if ($implode) {
|
||||
$sql .= " WHERE " . implode(" AND ", $implode);
|
||||
}
|
||||
|
||||
$sort_data = [
|
||||
's.subscription_id',
|
||||
's.order_id',
|
||||
's.reference',
|
||||
'customer',
|
||||
's.subscription_status',
|
||||
's.date_added'
|
||||
];
|
||||
|
||||
if (isset($data['sort']) && in_array($data['sort'], $sort_data)) {
|
||||
$sql .= " ORDER BY " . $data['sort'];
|
||||
} else {
|
||||
$sql .= " ORDER BY `s`.`subscription_id`";
|
||||
}
|
||||
|
||||
if (isset($data['order']) && ($data['order'] == 'DESC')) {
|
||||
$sql .= " DESC";
|
||||
} else {
|
||||
$sql .= " ASC";
|
||||
}
|
||||
|
||||
if (isset($data['start']) || isset($data['limit'])) {
|
||||
if ($data['start'] < 0) {
|
||||
$data['start'] = 0;
|
||||
}
|
||||
|
||||
if ($data['limit'] < 1) {
|
||||
$data['limit'] = 20;
|
||||
}
|
||||
|
||||
$sql .= " LIMIT " . (int)$data['start'] . "," . (int)$data['limit'];
|
||||
}
|
||||
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
return $query->rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalSubscriptions(array $data = []): int {
|
||||
$sql = "SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "subscription` `s` LEFT JOIN `" . DB_PREFIX . "order` `o` ON (`s`.`order_id` = o.`order_id`)";
|
||||
|
||||
$implode = [];
|
||||
|
||||
if (!empty($data['filter_subscription_id'])) {
|
||||
$implode[] .= "`s`.`subscription_id` = '" . (int)$data['filter_subscription_id'] . "'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_order_id'])) {
|
||||
$implode[] .= "`s`.`order_id` = '" . (int)$data['filter_order_id'] . "'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_customer'])) {
|
||||
$implode[] .= "CONCAT(o.`firstname`, ' ', o.`lastname`) LIKE '" . $this->db->escape((string)$data['filter_customer'] . '%') . "'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_subscription_status_id'])) {
|
||||
$implode[] .= "`s`.`subscription_status_id` = '" . (int)$data['filter_subscription_status_id'] . "'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_date_from'])) {
|
||||
$implode[] = "DATE(s.`date_added`) >= DATE('" . $this->db->escape((string)$data['filter_date_from']) . "')";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_date_to'])) {
|
||||
$implode[] = "DATE(s.`date_added`) <= DATE('" . $this->db->escape((string)$data['filter_date_to']) . "')";
|
||||
}
|
||||
|
||||
if ($implode) {
|
||||
$sql .= " WHERE " . implode(" AND ", $implode);
|
||||
}
|
||||
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $store_id
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalSubscriptionsByStoreId(int $store_id): int {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "subscription` WHERE `store_id` = '" . (int)$store_id . "'");
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $subscription_status_id
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalSubscriptionsBySubscriptionStatusId(int $subscription_status_id): int {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "subscription` WHERE `subscription_status_id` = '" . (int)$subscription_status_id . "'");
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $subscription_id
|
||||
* @param int $subscription_status_id
|
||||
* @param string $comment
|
||||
* @param bool $notify
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function addHistory(int $subscription_id, int $subscription_status_id, string $comment = '', bool $notify = false): void {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "subscription_history` SET `subscription_id` = '" . (int)$subscription_id . "', `subscription_status_id` = '" . (int)$subscription_status_id . "', `comment` = '" . $this->db->escape($comment) . "', `notify` = '" . (int)$notify . "', `date_added` = NOW()");
|
||||
|
||||
$this->db->query("UPDATE `" . DB_PREFIX . "subscription` SET `subscription_status_id` = '" . (int)$subscription_status_id . "' WHERE `subscription_id` = '" . (int)$subscription_id . "'");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $subscription_id
|
||||
* @param int $start
|
||||
* @param int $limit
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getHistories(int $subscription_id, int $start = 0, int $limit = 10): array {
|
||||
if ($start < 0) {
|
||||
$start = 0;
|
||||
}
|
||||
|
||||
if ($limit < 1) {
|
||||
$limit = 10;
|
||||
}
|
||||
|
||||
$query = $this->db->query("SELECT sh.`date_added`, ss.`name` AS status, sh.`comment`, sh.`notify` FROM `" . DB_PREFIX . "subscription_history` sh LEFT JOIN `" . DB_PREFIX . "subscription_status` ss ON sh.`subscription_status_id` = ss.`subscription_status_id` WHERE sh.`subscription_id` = '" . (int)$subscription_id . "' AND ss.`language_id` = '" . (int)$this->config->get('config_language_id') . "' ORDER BY sh.`date_added` DESC LIMIT " . (int)$start . "," . (int)$limit);
|
||||
|
||||
return $query->rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $subscription_id
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalHistories(int $subscription_id): int {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "subscription_history` WHERE `subscription_id` = '" . (int)$subscription_id . "'");
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $subscription_status_id
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalHistoriesBySubscriptionStatusId(int $subscription_status_id): int {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "subscription_history` WHERE `subscription_status_id` = '" . (int)$subscription_status_id . "'");
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
}
|
160
admininistrator/model/sale/voucher.php
Normal file
160
admininistrator/model/sale/voucher.php
Normal file
@ -0,0 +1,160 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Model\Sale;
|
||||
/**
|
||||
* Class Voucher
|
||||
*
|
||||
* @package Opencart\Admin\Model\Sale
|
||||
*/
|
||||
class Voucher extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function addVoucher(array $data): int {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "voucher` SET `code` = '" . $this->db->escape((string)$data['code']) . "', `from_name` = '" . $this->db->escape((string)$data['from_name']) . "', `from_email` = '" . $this->db->escape((string)$data['from_email']) . "', `to_name` = '" . $this->db->escape((string)$data['to_name']) . "', `to_email` = '" . $this->db->escape((string)$data['to_email']) . "', `voucher_theme_id` = '" . (int)$data['voucher_theme_id'] . "', `message` = '" . $this->db->escape((string)$data['message']) . "', `amount` = '" . (float)$data['amount'] . "', `status` = '" . (bool)$data['status'] . "', `date_added` = NOW()");
|
||||
|
||||
return $this->db->getLastId();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $voucher_id
|
||||
* @param array $data
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function editVoucher(int $voucher_id, array $data): void {
|
||||
$this->db->query("UPDATE `" . DB_PREFIX . "voucher` SET `code` = '" . $this->db->escape((string)$data['code']) . "', `from_name` = '" . $this->db->escape((string)$data['from_name']) . "', `from_email` = '" . $this->db->escape((string)$data['from_email']) . "', `to_name` = '" . $this->db->escape((string)$data['to_name']) . "', `to_email` = '" . $this->db->escape((string)$data['to_email']) . "', `voucher_theme_id` = '" . (int)$data['voucher_theme_id'] . "', `message` = '" . $this->db->escape((string)$data['message']) . "', `amount` = '" . (float)$data['amount'] . "', `status` = '" . (bool)$data['status'] . "' WHERE `voucher_id` = '" . (int)$voucher_id . "'");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $voucher_id
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function deleteVoucher(int $voucher_id): void {
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "voucher` WHERE `voucher_id` = '" . (int)$voucher_id . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "voucher_history` WHERE `voucher_id` = '" . (int)$voucher_id . "'");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $voucher_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getVoucher(int $voucher_id): array {
|
||||
$query = $this->db->query("SELECT DISTINCT * FROM `" . DB_PREFIX . "voucher` WHERE `voucher_id` = '" . (int)$voucher_id . "'");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $code
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getVoucherByCode(string $code): array {
|
||||
$query = $this->db->query("SELECT DISTINCT * FROM `" . DB_PREFIX . "voucher` WHERE `code` = '" . $this->db->escape($code) . "'");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getVouchers(array $data = []): array {
|
||||
$sql = "SELECT v.`voucher_id`, v.`order_id`, v.`code`, v.`from_name`, v.`from_email`, v.`to_name`, v.`to_email`, (SELECT vtd.`name` FROM `" . DB_PREFIX . "voucher_theme_description` vtd WHERE vtd.`voucher_theme_id` = v.`voucher_theme_id` AND vtd.`language_id` = '" . (int)$this->config->get('config_language_id') . "') AS theme, v.`amount`, v.`status`, v.`date_added` FROM `" . DB_PREFIX . "voucher` v";
|
||||
|
||||
$sort_data = [
|
||||
'v.code',
|
||||
'v.from_name',
|
||||
'v.to_name',
|
||||
'theme',
|
||||
'v.amount',
|
||||
'v.status',
|
||||
'v.date_added'
|
||||
];
|
||||
|
||||
if (isset($data['sort']) && in_array($data['sort'], $sort_data)) {
|
||||
$sql .= " ORDER BY " . $data['sort'];
|
||||
} else {
|
||||
$sql .= " ORDER BY v.`date_added`";
|
||||
}
|
||||
|
||||
if (isset($data['order']) && ($data['order'] == 'DESC')) {
|
||||
$sql .= " DESC";
|
||||
} else {
|
||||
$sql .= " ASC";
|
||||
}
|
||||
|
||||
if (isset($data['start']) || isset($data['limit'])) {
|
||||
if ($data['start'] < 0) {
|
||||
$data['start'] = 0;
|
||||
}
|
||||
|
||||
if ($data['limit'] < 1) {
|
||||
$data['limit'] = 20;
|
||||
}
|
||||
|
||||
$sql .= " LIMIT " . (int)$data['start'] . "," . (int)$data['limit'];
|
||||
}
|
||||
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
return $query->rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalVouchers(): int {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "voucher`");
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $voucher_theme_id
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalVouchersByVoucherThemeId(int $voucher_theme_id): int {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "voucher` WHERE `voucher_theme_id` = '" . (int)$voucher_theme_id . "'");
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $voucher_id
|
||||
* @param int $start
|
||||
* @param int $limit
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getHistories(int $voucher_id, int $start = 0, int $limit = 10): array {
|
||||
if ($start < 0) {
|
||||
$start = 0;
|
||||
}
|
||||
|
||||
if ($limit < 1) {
|
||||
$limit = 10;
|
||||
}
|
||||
|
||||
$query = $this->db->query("SELECT vh.`order_id`, CONCAT(o.`firstname`, ' ', o.`lastname`) AS customer, vh.`amount`, vh.`date_added` FROM `" . DB_PREFIX . "voucher_history` vh LEFT JOIN `" . DB_PREFIX . "order` o ON (vh.`order_id` = o.`order_id`) WHERE vh.`voucher_id` = '" . (int)$voucher_id . "' ORDER BY vh.`date_added` ASC LIMIT " . (int)$start . "," . (int)$limit);
|
||||
|
||||
return $query->rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $voucher_id
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalHistories(int $voucher_id): int {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "voucher_history` WHERE `voucher_id` = '" . (int)$voucher_id . "'");
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
}
|
133
admininistrator/model/sale/voucher_theme.php
Normal file
133
admininistrator/model/sale/voucher_theme.php
Normal file
@ -0,0 +1,133 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Model\Sale;
|
||||
/**
|
||||
* Class Voucher Theme
|
||||
*
|
||||
* @package Opencart\Admin\Model\Sale
|
||||
*/
|
||||
class VoucherTheme extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function addVoucherTheme(array $data): int {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "voucher_theme` SET `image` = '" . $this->db->escape((string)$data['image']) . "'");
|
||||
|
||||
$voucher_theme_id = $this->db->getLastId();
|
||||
|
||||
foreach ($data['voucher_theme_description'] as $language_id => $value) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "voucher_theme_description` SET `voucher_theme_id` = '" . (int)$voucher_theme_id . "', `language_id` = '" . (int)$language_id . "', `name` = '" . $this->db->escape($value['name']) . "'");
|
||||
}
|
||||
|
||||
$this->cache->delete('voucher_theme');
|
||||
|
||||
return $voucher_theme_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $voucher_theme_id
|
||||
* @param array $data
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function editVoucherTheme(int $voucher_theme_id, array $data): void {
|
||||
$this->db->query("UPDATE `" . DB_PREFIX . "voucher_theme` SET `image` = '" . $this->db->escape((string)$data['image']) . "' WHERE `voucher_theme_id` = '" . (int)$voucher_theme_id . "'");
|
||||
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "voucher_theme_description` WHERE `voucher_theme_id` = '" . (int)$voucher_theme_id . "'");
|
||||
|
||||
foreach ($data['voucher_theme_description'] as $language_id => $value) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "voucher_theme_description` SET `voucher_theme_id` = '" . (int)$voucher_theme_id . "', `language_id` = '" . (int)$language_id . "', `name` = '" . $this->db->escape($value['name']) . "'");
|
||||
}
|
||||
|
||||
$this->cache->delete('voucher_theme');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $voucher_theme_id
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function deleteVoucherTheme(int $voucher_theme_id): void {
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "voucher_theme` WHERE `voucher_theme_id` = '" . (int)$voucher_theme_id . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "voucher_theme_description` WHERE `voucher_theme_id` = '" . (int)$voucher_theme_id . "'");
|
||||
|
||||
$this->cache->delete('voucher_theme');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $voucher_theme_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getVoucherTheme(int $voucher_theme_id): array {
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "voucher_theme` vt LEFT JOIN `" . DB_PREFIX . "voucher_theme_description` vtd ON (vt.`voucher_theme_id` = vtd.`voucher_theme_id`) WHERE vt.`voucher_theme_id` = '" . (int)$voucher_theme_id . "' AND vtd.`language_id` = '" . (int)$this->config->get('config_language_id') . "'");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getVoucherThemes(array $data = []): array {
|
||||
$sql = "SELECT * FROM `" . DB_PREFIX . "voucher_theme` vt LEFT JOIN `" . DB_PREFIX . "voucher_theme_description` `vtd` ON (`vt`.`voucher_theme_id` = `vtd`.`voucher_theme_id`) WHERE `vtd`.`language_id` = '" . (int)$this->config->get('config_language_id') . "' ORDER BY `vtd`.`name`";
|
||||
|
||||
if (isset($data['order']) && ($data['order'] == 'DESC')) {
|
||||
$sql .= " DESC";
|
||||
} else {
|
||||
$sql .= " ASC";
|
||||
}
|
||||
|
||||
if (isset($data['start']) || isset($data['limit'])) {
|
||||
if ($data['start'] < 0) {
|
||||
$data['start'] = 0;
|
||||
}
|
||||
|
||||
if ($data['limit'] < 1) {
|
||||
$data['limit'] = 20;
|
||||
}
|
||||
|
||||
$sql .= " LIMIT " . (int)$data['start'] . "," . (int)$data['limit'];
|
||||
}
|
||||
|
||||
$voucher_theme_data = $this->cache->get('voucher_theme.' . md5($sql));
|
||||
|
||||
if (!$voucher_theme_data) {
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
$voucher_theme_data = $query->rows;
|
||||
|
||||
$this->cache->set('voucher_theme.' . md5($sql), $voucher_theme_data);
|
||||
}
|
||||
|
||||
return $voucher_theme_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $voucher_theme_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getDescriptions(int $voucher_theme_id): array {
|
||||
$voucher_theme_data = [];
|
||||
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "voucher_theme_description` WHERE `voucher_theme_id` = '" . (int)$voucher_theme_id . "'");
|
||||
|
||||
foreach ($query->rows as $result) {
|
||||
$voucher_theme_data[$result['language_id']] = ['name' => $result['name']];
|
||||
}
|
||||
|
||||
return $voucher_theme_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalVoucherThemes(): int {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "voucher_theme`");
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user