first commit
This commit is contained in:
229
admininistrator/model/catalog/attribute.php
Normal file
229
admininistrator/model/catalog/attribute.php
Normal file
@ -0,0 +1,229 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Model\Catalog;
|
||||
/*
|
||||
* Class Attribute
|
||||
*
|
||||
* Can be called from $this->load->model('catalog/attribute');
|
||||
*
|
||||
* @package Opencart\Admin\Model\Catalog
|
||||
* */
|
||||
class Attribute extends \Opencart\System\Engine\Model {
|
||||
/*
|
||||
* Add Attribute
|
||||
*
|
||||
* Create a new attribute record in the database.
|
||||
*
|
||||
* @param array $data
|
||||
*
|
||||
* @return int returns the primary key of the new attribute record.
|
||||
*/
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function addAttribute(array $data): int {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "attribute` SET `attribute_group_id` = '" . (int)$data['attribute_group_id'] . "', `sort_order` = '" . (int)$data['sort_order'] . "'");
|
||||
|
||||
$attribute_id = $this->db->getLastId();
|
||||
|
||||
foreach ($data['attribute_description'] as $language_id => $value) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "attribute_description` SET `attribute_id` = '" . (int)$attribute_id . "', `language_id` = '" . (int)$language_id . "', `name` = '" . $this->db->escape($value['name']) . "'");
|
||||
}
|
||||
|
||||
return $attribute_id;
|
||||
}
|
||||
|
||||
/*
|
||||
* Edit Attribute
|
||||
*
|
||||
* Edit attribute record in the database.
|
||||
*
|
||||
* @param int $attribute_id Primary key of the attribute record to edit.
|
||||
* @param array $data Array of data [
|
||||
* 'attribute_group_id'
|
||||
* ].
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
/**
|
||||
* @param int $attribute_id
|
||||
* @param array $data
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function editAttribute(int $attribute_id, array $data): void {
|
||||
$this->db->query("UPDATE `" . DB_PREFIX . "attribute` SET `attribute_group_id` = '" . (int)$data['attribute_group_id'] . "', `sort_order` = '" . (int)$data['sort_order'] . "' WHERE `attribute_id` = '" . (int)$attribute_id . "'");
|
||||
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "attribute_description` WHERE `attribute_id` = '" . (int)$attribute_id . "'");
|
||||
|
||||
foreach ($data['attribute_description'] as $language_id => $value) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "attribute_description` SET `attribute_id` = '" . (int)$attribute_id . "', `language_id` = '" . (int)$language_id . "', `name` = '" . $this->db->escape($value['name']) . "'");
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Delete Attribute
|
||||
*
|
||||
* Delete attribute record in the database.
|
||||
*
|
||||
* @param int $attribute_id primary key of the attribute record to be deleted
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
*/
|
||||
/**
|
||||
* @param int $attribute_id
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function deleteAttribute(int $attribute_id): void {
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "attribute` WHERE `attribute_id` = '" . (int)$attribute_id . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "attribute_description` WHERE `attribute_id` = '" . (int)$attribute_id . "'");
|
||||
}
|
||||
|
||||
/*
|
||||
* Get Attribute
|
||||
*
|
||||
* Get the record of the attribute record in the database.
|
||||
*
|
||||
* @param int $attribute_id primary key of the attribute record to be fetched
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
*/
|
||||
/**
|
||||
* @param int $attribute_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getAttribute(int $attribute_id): array {
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "attribute` a LEFT JOIN `" . DB_PREFIX . "attribute_description` ad ON (a.`attribute_id` = ad.`attribute_id`) WHERE a.`attribute_id` = '" . (int)$attribute_id . "' AND ad.`language_id` = '" . (int)$this->config->get('config_language_id') . "'");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
/*
|
||||
* Get Attributes
|
||||
*
|
||||
* Get the record of the attribute record in the database.
|
||||
*
|
||||
* @param array $data array of filters
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
*/
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getAttributes(array $data = []): array {
|
||||
$sql = "SELECT *, (SELECT agd.`name` FROM `" . DB_PREFIX . "attribute_group_description` agd WHERE agd.`attribute_group_id` = a.`attribute_group_id` AND agd.`language_id` = '" . (int)$this->config->get('config_language_id') . "') AS attribute_group FROM `" . DB_PREFIX . "attribute` a LEFT JOIN `" . DB_PREFIX . "attribute_description` ad ON (a.`attribute_id` = ad.`attribute_id`) WHERE ad.`language_id` = '" . (int)$this->config->get('config_language_id') . "'";
|
||||
|
||||
if (!empty($data['filter_name'])) {
|
||||
$sql .= " AND ad.`name` LIKE '" . $this->db->escape((string)$data['filter_name'] . '%') . "'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_attribute_group_id'])) {
|
||||
$sql .= " AND a.`attribute_group_id` = '" . (int)$data['filter_attribute_group_id'] . "'";
|
||||
}
|
||||
|
||||
$sort_data = ['ad.name', 'attribute_group', 'a.sort_order'];
|
||||
|
||||
if (isset($data['sort']) && in_array($data['sort'], $sort_data)) {
|
||||
$sql .= " ORDER BY " . $data['sort'];
|
||||
} else {
|
||||
$sql .= " ORDER BY `attribute_group`, ad.`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'];
|
||||
}
|
||||
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
return $query->rows;
|
||||
}
|
||||
|
||||
/*
|
||||
* Get Descriptions
|
||||
*
|
||||
* Get the record of the attribute record in the database.
|
||||
*
|
||||
* @param int $attribute_id primary key of the attribute record to be fetched.
|
||||
*
|
||||
* @return array returns array of descriptions sorted by language_id
|
||||
*
|
||||
*/
|
||||
/**
|
||||
* @param int $attribute_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getDescriptions(int $attribute_id): array {
|
||||
$attribute_data = [];
|
||||
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "attribute_description` WHERE `attribute_id` = '" . (int)$attribute_id . "'");
|
||||
|
||||
foreach ($query->rows as $result) {
|
||||
$attribute_data[$result['language_id']] = ['name' => $result['name']];
|
||||
}
|
||||
|
||||
return $attribute_data;
|
||||
}
|
||||
|
||||
/*
|
||||
* Get Total Attributes
|
||||
*
|
||||
* Get the total number of attribute records in the database.
|
||||
*
|
||||
* @return int Total number of attribute records.
|
||||
*/
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalAttributes(): int {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "attribute`");
|
||||
|
||||
if ($query->num_rows) {
|
||||
return (int)$query->row['total'];
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Get Total Attributes By Attribute Group ID
|
||||
*
|
||||
* Get the total number of attribute records with group ID in the database.
|
||||
*
|
||||
* @param int $attribute_group_id foreign key of the attribute record to be fetched.
|
||||
*
|
||||
* @return int Total number of attribute records that have attribute group ID.
|
||||
*/
|
||||
/**
|
||||
* @param int $attribute_group_id
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalAttributesByAttributeGroupId(int $attribute_group_id): int {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "attribute` WHERE `attribute_group_id` = '" . (int)$attribute_group_id . "'");
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
}
|
127
admininistrator/model/catalog/attribute_group.php
Normal file
127
admininistrator/model/catalog/attribute_group.php
Normal file
@ -0,0 +1,127 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Model\Catalog;
|
||||
/**
|
||||
* Class Attribute Group
|
||||
*
|
||||
* @package Opencart\Admin\Model\Catalog
|
||||
*/
|
||||
class AttributeGroup extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function addAttributeGroup(array $data): int {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "attribute_group` SET `sort_order` = '" . (int)$data['sort_order'] . "'");
|
||||
|
||||
$attribute_group_id = $this->db->getLastId();
|
||||
|
||||
foreach ($data['attribute_group_description'] as $language_id => $value) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "attribute_group_description` SET `attribute_group_id` = '" . (int)$attribute_group_id . "', `language_id` = '" . (int)$language_id . "', `name` = '" . $this->db->escape($value['name']) . "'");
|
||||
}
|
||||
|
||||
return $attribute_group_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $attribute_group_id
|
||||
* @param array $data
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function editAttributeGroup(int $attribute_group_id, array $data): void {
|
||||
$this->db->query("UPDATE `" . DB_PREFIX . "attribute_group` SET `sort_order` = '" . (int)$data['sort_order'] . "' WHERE `attribute_group_id` = '" . (int)$attribute_group_id . "'");
|
||||
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "attribute_group_description` WHERE `attribute_group_id` = '" . (int)$attribute_group_id . "'");
|
||||
|
||||
foreach ($data['attribute_group_description'] as $language_id => $value) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "attribute_group_description` SET `attribute_group_id` = '" . (int)$attribute_group_id . "', `language_id` = '" . (int)$language_id . "', `name` = '" . $this->db->escape($value['name']) . "'");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $attribute_group_id
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function deleteAttributeGroup(int $attribute_group_id): void {
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "attribute_group` WHERE `attribute_group_id` = '" . (int)$attribute_group_id . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "attribute_group_description` WHERE `attribute_group_id` = '" . (int)$attribute_group_id . "'");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $attribute_group_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getAttributeGroup(int $attribute_group_id): array {
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "attribute_group` WHERE `attribute_group_id` = '" . (int)$attribute_group_id . "'");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getAttributeGroups(array $data = []): array {
|
||||
$sql = "SELECT * FROM `" . DB_PREFIX . "attribute_group` ag LEFT JOIN `" . DB_PREFIX . "attribute_group_description` agd ON (ag.`attribute_group_id` = agd.`attribute_group_id`) WHERE agd.`language_id` = '" . (int)$this->config->get('config_language_id') . "'";
|
||||
|
||||
$sort_data = ['agd.name', 'ag.sort_order'];
|
||||
|
||||
if (isset($data['sort']) && in_array($data['sort'], $sort_data)) {
|
||||
$sql .= " ORDER BY " . $data['sort'];
|
||||
} else {
|
||||
$sql .= " ORDER BY agd.`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'];
|
||||
}
|
||||
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
return $query->rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $attribute_group_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getDescriptions(int $attribute_group_id): array {
|
||||
$attribute_group_data = [];
|
||||
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "attribute_group_description` WHERE `attribute_group_id` = '" . (int)$attribute_group_id . "'");
|
||||
|
||||
foreach ($query->rows as $result) {
|
||||
$attribute_group_data[$result['language_id']] = ['name' => $result['name']];
|
||||
}
|
||||
|
||||
return $attribute_group_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalAttributeGroups(): int {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "attribute_group`");
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
}
|
451
admininistrator/model/catalog/category.php
Normal file
451
admininistrator/model/catalog/category.php
Normal file
@ -0,0 +1,451 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Model\Catalog;
|
||||
/**
|
||||
* Class Category
|
||||
*
|
||||
* @package Opencart\Admin\Model\Catalog
|
||||
*/
|
||||
class Category extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function addCategory(array $data): int {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "category` SET `image` = '" . $this->db->escape((string)$data['image']) . "', `parent_id` = '" . (int)$data['parent_id'] . "', `top` = '" . (isset($data['top']) ? (int)$data['top'] : 0) . "', `column` = '" . (int)$data['column'] . "', `sort_order` = '" . (int)$data['sort_order'] . "', `status` = '" . (bool)(isset($data['status']) ? $data['status'] : 0) . "', `date_modified` = NOW(), `date_added` = NOW()");
|
||||
|
||||
$category_id = $this->db->getLastId();
|
||||
|
||||
foreach ($data['category_description'] as $language_id => $value) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "category_description` SET `category_id` = '" . (int)$category_id . "', `language_id` = '" . (int)$language_id . "', `name` = '" . $this->db->escape($value['name']) . "', `description` = '" . $this->db->escape($value['description']) . "', `meta_title` = '" . $this->db->escape($value['meta_title']) . "', `meta_description` = '" . $this->db->escape($value['meta_description']) . "', `meta_keyword` = '" . $this->db->escape($value['meta_keyword']) . "'");
|
||||
}
|
||||
|
||||
// MySQL Hierarchical Data Closure Table Pattern
|
||||
$level = 0;
|
||||
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "category_path` WHERE `category_id` = '" . (int)$data['parent_id'] . "' ORDER BY `level` ASC");
|
||||
|
||||
foreach ($query->rows as $result) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "category_path` SET `category_id` = '" . (int)$category_id . "', `path_id` = '" . (int)$result['path_id'] . "', `level` = '" . (int)$level . "'");
|
||||
|
||||
$level++;
|
||||
}
|
||||
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "category_path` SET `category_id` = '" . (int)$category_id . "', `path_id` = '" . (int)$category_id . "', `level` = '" . (int)$level. "'");
|
||||
|
||||
if (isset($data['category_filter'])) {
|
||||
foreach ($data['category_filter'] as $filter_id) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "category_filter` SET `category_id` = '" . (int)$category_id . "', `filter_id` = '" . (int)$filter_id . "'");
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($data['category_store'])) {
|
||||
foreach ($data['category_store'] as $store_id) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "category_to_store` SET `category_id` = '" . (int)$category_id . "', `store_id` = '" . (int)$store_id . "'");
|
||||
}
|
||||
}
|
||||
|
||||
// Seo urls on categories need to be done differently to they include the full keyword path
|
||||
$parent_path = $this->getPath($data['parent_id']);
|
||||
|
||||
if (!$parent_path) {
|
||||
$path = $category_id;
|
||||
} else {
|
||||
$path = $parent_path . '_' . $category_id;
|
||||
}
|
||||
|
||||
$this->load->model('design/seo_url');
|
||||
|
||||
foreach ($data['category_seo_url'] as $store_id => $language) {
|
||||
foreach ($language as $language_id => $keyword) {
|
||||
$seo_url_info = $this->model_design_seo_url->getSeoUrlByKeyValue('path', $parent_path, $store_id, $language_id);
|
||||
|
||||
if ($seo_url_info) {
|
||||
$keyword = $seo_url_info['keyword'] . '/' . $keyword;
|
||||
}
|
||||
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "seo_url` SET `store_id` = '" . (int)$store_id . "', `language_id` = '" . (int)$language_id . "', `key` = 'path', `value`= '" . $this->db->escape($path) . "', `keyword` = '" . $this->db->escape($keyword) . "'");
|
||||
}
|
||||
}
|
||||
|
||||
// Set which layout to use with this category
|
||||
if (isset($data['category_layout'])) {
|
||||
foreach ($data['category_layout'] as $store_id => $layout_id) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "category_to_layout` SET `category_id` = '" . (int)$category_id . "', `store_id` = '" . (int)$store_id . "', `layout_id` = '" . (int)$layout_id . "'");
|
||||
}
|
||||
}
|
||||
|
||||
return $category_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $category_id
|
||||
* @param array $data
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function editCategory(int $category_id, array $data): void {
|
||||
$this->db->query("UPDATE `" . DB_PREFIX . "category` SET `image` = '" . $this->db->escape((string)$data['image']) . "', `parent_id` = '" . (int)$data['parent_id'] . "', `top` = '" . (isset($data['top']) ? (int)$data['top'] : 0) . "', `column` = '" . (int)$data['column'] . "', `sort_order` = '" . (int)$data['sort_order'] . "', `status` = '" . (bool)(isset($data['status']) ? $data['status'] : 0) . "', `date_modified` = NOW() WHERE `category_id` = '" . (int)$category_id . "'");
|
||||
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "category_description` WHERE `category_id` = '" . (int)$category_id . "'");
|
||||
|
||||
foreach ($data['category_description'] as $language_id => $value) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "category_description` SET `category_id` = '" . (int)$category_id . "', `language_id` = '" . (int)$language_id . "', `name` = '" . $this->db->escape($value['name']) . "', `description` = '" . $this->db->escape($value['description']) . "', `meta_title` = '" . $this->db->escape($value['meta_title']) . "', `meta_description` = '" . $this->db->escape($value['meta_description']) . "', `meta_keyword` = '" . $this->db->escape($value['meta_keyword']) . "'");
|
||||
}
|
||||
|
||||
// Old path
|
||||
$path_old = $this->getPath($category_id);
|
||||
|
||||
// MySQL Hierarchical Data Closure Table Pattern
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "category_path` WHERE `path_id` = '" . (int)$category_id . "' ORDER BY `level` ASC");
|
||||
|
||||
if ($query->rows) {
|
||||
foreach ($query->rows as $category_path) {
|
||||
// Delete the path below the current one
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "category_path` WHERE `category_id` = '" . (int)$category_path['category_id'] . "' AND `level` < '" . (int)$category_path['level'] . "'");
|
||||
|
||||
$paths = [];
|
||||
|
||||
// Get the nodes new parents
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "category_path` WHERE `category_id` = '" . (int)$data['parent_id'] . "' ORDER BY `level` ASC");
|
||||
|
||||
foreach ($query->rows as $result) {
|
||||
$paths[] = $result['path_id'];
|
||||
}
|
||||
|
||||
// Get whats left of the nodes current path
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "category_path` WHERE `category_id` = '" . (int)$category_path['category_id'] . "' ORDER BY `level` ASC");
|
||||
|
||||
foreach ($query->rows as $result) {
|
||||
$paths[] = $result['path_id'];
|
||||
}
|
||||
|
||||
// Combine the paths with a new level
|
||||
$level = 0;
|
||||
|
||||
foreach ($paths as $path_id) {
|
||||
$this->db->query("REPLACE INTO `" . DB_PREFIX . "category_path` SET `category_id` = '" . (int)$category_path['category_id'] . "', `path_id` = '" . (int)$path_id . "', `level` = '" . (int)$level . "'");
|
||||
|
||||
$level++;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Delete the path below the current one
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "category_path` WHERE `category_id` = '" . (int)$category_id . "'");
|
||||
|
||||
// Fix for records with no paths
|
||||
$level = 0;
|
||||
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "category_path` WHERE `category_id` = '" . (int)$data['parent_id'] . "' ORDER BY `level` ASC");
|
||||
|
||||
foreach ($query->rows as $result) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "category_path` SET `category_id` = '" . (int)$category_id . "', `path_id` = '" . (int)$result['path_id'] . "', `level` = '" . (int)$level . "'");
|
||||
|
||||
$level++;
|
||||
}
|
||||
|
||||
$this->db->query("REPLACE INTO `" . DB_PREFIX . "category_path` SET `category_id` = '" . (int)$category_id . "', `path_id` = '" . (int)$category_id . "', `level` = '" . (int)$level . "'");
|
||||
}
|
||||
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "category_filter` WHERE `category_id` = '" . (int)$category_id . "'");
|
||||
|
||||
if (isset($data['category_filter'])) {
|
||||
foreach ($data['category_filter'] as $filter_id) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "category_filter` SET `category_id` = '" . (int)$category_id . "', `filter_id` = '" . (int)$filter_id . "'");
|
||||
}
|
||||
}
|
||||
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "category_to_store` WHERE `category_id` = '" . (int)$category_id . "'");
|
||||
|
||||
if (isset($data['category_store'])) {
|
||||
foreach ($data['category_store'] as $store_id) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "category_to_store` SET `category_id` = '" . (int)$category_id . "', `store_id` = '" . (int)$store_id . "'");
|
||||
}
|
||||
}
|
||||
|
||||
// Seo urls on categories need to be done differently to they include the full keyword path
|
||||
$path_parent = $this->getPath($data['parent_id']);
|
||||
|
||||
if (!$path_parent) {
|
||||
$path_new = $category_id;
|
||||
} else {
|
||||
$path_new = $path_parent . '_' . $category_id;
|
||||
}
|
||||
|
||||
// Get old data to so we know what to replace
|
||||
$seo_url_data = $this->getSeoUrls($category_id);
|
||||
|
||||
// Delete the old path
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "seo_url` WHERE `key` = 'path' AND `value` = '" . $this->db->escape($path_old) . "'");
|
||||
|
||||
$this->load->model('design/seo_url');
|
||||
|
||||
foreach ($data['category_seo_url'] as $store_id => $language) {
|
||||
foreach ($language as $language_id => $keyword) {
|
||||
$parent_info = $this->model_design_seo_url->getSeoUrlByKeyValue('path', $path_parent, $store_id, $language_id);
|
||||
|
||||
if ($parent_info) {
|
||||
$keyword = $parent_info['keyword'] . '/' . $keyword;
|
||||
}
|
||||
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "seo_url` SET `store_id` = '" . (int)$store_id . "', `language_id` = '" . (int)$language_id . "', `key` = 'path', `value` = '" . $this->db->escape($path_new) . "', `keyword` = '" . $this->db->escape($keyword) . "'");
|
||||
|
||||
// Update sub category seo urls
|
||||
if (isset($seo_url_data[$store_id][$language_id])) {
|
||||
$this->db->query("UPDATE `" . DB_PREFIX . "seo_url` SET `value` = CONCAT('" . $this->db->escape($path_new . '_') . "', SUBSTRING(`value`, " . (strlen($path_old . '_') + 1) . ")), `keyword` = CONCAT('" . $this->db->escape($keyword) . "', SUBSTRING(`keyword`, " . (oc_strlen($seo_url_data[$store_id][$language_id]) + 1) . ")) WHERE `store_id` = '" . (int)$store_id . "' AND `language_id` = '" . (int)$language_id . "' AND `key` = 'path' AND `value` LIKE '" . $this->db->escape($path_old . '\_%') . "'");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Layouts
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "category_to_layout` WHERE `category_id` = '" . (int)$category_id . "'");
|
||||
|
||||
if (isset($data['category_layout'])) {
|
||||
foreach ($data['category_layout'] as $store_id => $layout_id) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "category_to_layout` SET `category_id` = '" . (int)$category_id . "', `store_id` = '" . (int)$store_id . "', `layout_id` = '" . (int)$layout_id . "'");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $category_id
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function deleteCategory(int $category_id): void {
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "category` WHERE `category_id` = '" . (int)$category_id . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "category_description` WHERE `category_id` = '" . (int)$category_id . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "category_filter` WHERE `category_id` = '" . (int)$category_id . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "category_to_store` WHERE `category_id` = '" . (int)$category_id . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "category_to_layout` WHERE `category_id` = '" . (int)$category_id . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "product_to_category` WHERE `category_id` = '" . (int)$category_id . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "coupon_category` WHERE `category_id` = '" . (int)$category_id . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "seo_url` WHERE `key` = 'path' AND `value` = '" . $this->db->escape($this->getPath($category_id)) . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "category_path` WHERE `category_id` = '" . (int)$category_id . "'");
|
||||
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "category_path` WHERE `path_id` = '" . (int)$category_id . "'");
|
||||
|
||||
foreach ($query->rows as $result) {
|
||||
$this->deleteCategory($result['category_id']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $parent_id
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function repairCategories(int $parent_id = 0): void {
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "category` WHERE `parent_id` = '" . (int)$parent_id . "'");
|
||||
|
||||
foreach ($query->rows as $category) {
|
||||
// Delete the path below the current one
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "category_path` WHERE `category_id` = '" . (int)$category['category_id'] . "'");
|
||||
|
||||
// Fix for records with no paths
|
||||
$level = 0;
|
||||
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "category_path` WHERE `category_id` = '" . (int)$parent_id . "' ORDER BY `level` ASC");
|
||||
|
||||
foreach ($query->rows as $result) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "category_path` SET `category_id` = '" . (int)$category['category_id'] . "', `path_id` = '" . (int)$result['path_id'] . "', `level` = '" . (int)$level . "'");
|
||||
|
||||
$level++;
|
||||
}
|
||||
|
||||
$this->db->query("REPLACE INTO `" . DB_PREFIX . "category_path` SET `category_id` = '" . (int)$category['category_id'] . "', `path_id` = '" . (int)$category['category_id'] . "', `level` = '" . (int)$level . "'");
|
||||
|
||||
$this->repairCategories($category['category_id']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $category_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getCategory(int $category_id): array {
|
||||
$query = $this->db->query("SELECT DISTINCT *, (SELECT GROUP_CONCAT(cd1.`name` ORDER BY `level` SEPARATOR ' > ') FROM `" . DB_PREFIX . "category_path` cp LEFT JOIN `" . DB_PREFIX . "category_description` cd1 ON (cp.`path_id` = cd1.`category_id` AND cp.`category_id` != cp.`path_id`) WHERE cp.`category_id` = c.`category_id` AND cd1.`language_id` = '" . (int)$this->config->get('config_language_id') . "' GROUP BY cp.`category_id`) AS `path` FROM `" . DB_PREFIX . "category` c LEFT JOIN `" . DB_PREFIX . "category_description` cd2 ON (c.`category_id` = cd2.`category_id`) WHERE c.`category_id` = '" . (int)$category_id . "' AND cd2.`language_id` = '" . (int)$this->config->get('config_language_id') . "'");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $category_id
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getPath(int $category_id): string {
|
||||
return implode('_', array_column($this->getPaths($category_id), 'path_id'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $category_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getPaths(int $category_id): array {
|
||||
$query = $this->db->query("SELECT `category_id`, `path_id`, `level` FROM `" . DB_PREFIX . "category_path` WHERE `category_id` = '" . (int)$category_id . "' ORDER BY `level` ASC");
|
||||
|
||||
return $query->rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getCategories(array $data = []): array {
|
||||
$sql = "SELECT cp.`category_id` AS `category_id`, GROUP_CONCAT(cd1.`name` ORDER BY cp.`level` SEPARATOR ' > ') AS `name`, c1.`parent_id`, c1.`sort_order`, c1.`status` FROM `" . DB_PREFIX . "category_path` cp LEFT JOIN `" . DB_PREFIX . "category` c1 ON (cp.`category_id` = c1.`category_id`) LEFT JOIN `" . DB_PREFIX . "category` c2 ON (cp.`path_id` = c2.`category_id`) LEFT JOIN `" . DB_PREFIX . "category_description` cd1 ON (cp.`path_id` = cd1.`category_id`) LEFT JOIN `" . DB_PREFIX . "category_description` cd2 ON (cp.`category_id` = cd2.`category_id`) WHERE cd1.`language_id` = '" . (int)$this->config->get('config_language_id') . "' AND cd2.`language_id` = '" . (int)$this->config->get('config_language_id') . "'";
|
||||
|
||||
if (!empty($data['filter_name'])) {
|
||||
$sql .= " AND cd2.`name` LIKE '" . $this->db->escape((string)$data['filter_name']) . "'";
|
||||
}
|
||||
|
||||
$sql .= " GROUP BY cp.`category_id`";
|
||||
|
||||
$sort_data = [
|
||||
'name',
|
||||
'sort_order'
|
||||
];
|
||||
|
||||
if (isset($data['sort']) && in_array($data['sort'], $sort_data)) {
|
||||
$sql .= " ORDER BY " . $data['sort'];
|
||||
} else {
|
||||
$sql .= " ORDER BY `sort_order`";
|
||||
}
|
||||
|
||||
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 $category_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getDescriptions(int $category_id): array {
|
||||
$category_description_data = [];
|
||||
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "category_description` WHERE `category_id` = '" . (int)$category_id . "'");
|
||||
|
||||
foreach ($query->rows as $result) {
|
||||
$category_description_data[$result['language_id']] = [
|
||||
'name' => $result['name'],
|
||||
'meta_title' => $result['meta_title'],
|
||||
'meta_description' => $result['meta_description'],
|
||||
'meta_keyword' => $result['meta_keyword'],
|
||||
'description' => $result['description']
|
||||
];
|
||||
}
|
||||
|
||||
return $category_description_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $category_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getFilters(int $category_id): array {
|
||||
$category_filter_data = [];
|
||||
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "category_filter` WHERE `category_id` = '" . (int)$category_id . "'");
|
||||
|
||||
foreach ($query->rows as $result) {
|
||||
$category_filter_data[] = $result['filter_id'];
|
||||
}
|
||||
|
||||
return $category_filter_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $category_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getSeoUrls(int $category_id): array {
|
||||
$category_seo_url_data = [];
|
||||
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "seo_url` WHERE `key` = 'path' AND `value` = '" . $this->db->escape($this->getPath($category_id)) . "'");
|
||||
|
||||
foreach ($query->rows as $result) {
|
||||
$category_seo_url_data[$result['store_id']][$result['language_id']] = $result['keyword'];
|
||||
}
|
||||
|
||||
return $category_seo_url_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $category_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getStores(int $category_id): array {
|
||||
$category_store_data = [];
|
||||
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "category_to_store` WHERE `category_id` = '" . (int)$category_id . "'");
|
||||
|
||||
foreach ($query->rows as $result) {
|
||||
$category_store_data[] = $result['store_id'];
|
||||
}
|
||||
|
||||
return $category_store_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $category_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getLayouts(int $category_id): array {
|
||||
$category_layout_data = [];
|
||||
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "category_to_layout` WHERE `category_id` = '" . (int)$category_id . "'");
|
||||
|
||||
foreach ($query->rows as $result) {
|
||||
$category_layout_data[$result['store_id']] = $result['layout_id'];
|
||||
}
|
||||
|
||||
return $category_layout_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalCategories(): int {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "category`");
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $layout_id
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalCategoriesByLayoutId(int $layout_id): int {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "category_to_layout` WHERE `layout_id` = '" . (int)$layout_id . "'");
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
}
|
166
admininistrator/model/catalog/download.php
Normal file
166
admininistrator/model/catalog/download.php
Normal file
@ -0,0 +1,166 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Model\Catalog;
|
||||
/**
|
||||
* Class Download
|
||||
*
|
||||
* @package Opencart\Admin\Model\Catalog
|
||||
*/
|
||||
class Download extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function addDownload(array $data): int {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "download` SET `filename` = '" . $this->db->escape((string)$data['filename']) . "', `mask` = '" . $this->db->escape((string)$data['mask']) . "', `date_added` = NOW()");
|
||||
|
||||
$download_id = $this->db->getLastId();
|
||||
|
||||
foreach ($data['download_description'] as $language_id => $value) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "download_description` SET `download_id` = '" . (int)$download_id . "', `language_id` = '" . (int)$language_id . "', `name` = '" . $this->db->escape($value['name']) . "'");
|
||||
}
|
||||
|
||||
return $download_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $download_id
|
||||
* @param array $data
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function editDownload(int $download_id, array $data): void {
|
||||
$this->db->query("UPDATE `" . DB_PREFIX . "download` SET `filename` = '" . $this->db->escape((string)$data['filename']) . "', `mask` = '" . $this->db->escape((string)$data['mask']) . "' WHERE `download_id` = '" . (int)$download_id . "'");
|
||||
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "download_description` WHERE `download_id` = '" . (int)$download_id . "'");
|
||||
|
||||
foreach ($data['download_description'] as $language_id => $value) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "download_description` SET `download_id` = '" . (int)$download_id . "', `language_id` = '" . (int)$language_id . "', `name` = '" . $this->db->escape($value['name']) . "'");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $download_id
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function deleteDownload(int $download_id): void {
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "download` WHERE `download_id` = '" . (int)$download_id . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "download_description` WHERE `download_id` = '" . (int)$download_id . "'");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $download_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getDownload(int $download_id): array {
|
||||
$query = $this->db->query("SELECT DISTINCT * FROM `" . DB_PREFIX . "download` d LEFT JOIN `" . DB_PREFIX . "download_description` dd ON (d.`download_id` = dd.`download_id`) WHERE d.`download_id` = '" . (int)$download_id . "' AND dd.`language_id` = '" . (int)$this->config->get('config_language_id') . "'");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getDownloads(array $data = []): array {
|
||||
$sql = "SELECT * FROM `" . DB_PREFIX . "download` d LEFT JOIN `" . DB_PREFIX . "download_description` dd ON (d.`download_id` = dd.`download_id`) WHERE dd.`language_id` = '" . (int)$this->config->get('config_language_id') . "'";
|
||||
|
||||
if (!empty($data['filter_name'])) {
|
||||
$sql .= " AND dd.`name` LIKE '" . $this->db->escape((string)$data['filter_name'] . '%') . "'";
|
||||
}
|
||||
|
||||
$sort_data = [
|
||||
'dd.name',
|
||||
'd.date_added'
|
||||
];
|
||||
|
||||
if (isset($data['sort']) && in_array($data['sort'], $sort_data)) {
|
||||
$sql .= " ORDER BY " . $data['sort'];
|
||||
} else {
|
||||
$sql .= " ORDER BY dd.`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'];
|
||||
}
|
||||
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
return $query->rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $download_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getDescriptions(int $download_id): array {
|
||||
$download_description_data = [];
|
||||
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "download_description` WHERE `download_id` = '" . (int)$download_id . "'");
|
||||
|
||||
foreach ($query->rows as $result) {
|
||||
$download_description_data[$result['language_id']] = ['name' => $result['name']];
|
||||
}
|
||||
|
||||
return $download_description_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalDownloads(): int {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "download`");
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $download_id
|
||||
* @param int $start
|
||||
* @param int $limit
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getReports(int $download_id, int $start = 0, int $limit = 10): array {
|
||||
if ($start < 0) {
|
||||
$start = 0;
|
||||
}
|
||||
|
||||
if ($limit < 1) {
|
||||
$limit = 10;
|
||||
}
|
||||
|
||||
$query = $this->db->query("SELECT `ip`, `store_id`, `country`, `date_added` FROM `" . DB_PREFIX . "download_report` WHERE `download_id` = '" . (int)$download_id . "' ORDER BY `date_added` ASC LIMIT " . (int)$start . "," . (int)$limit);
|
||||
|
||||
return $query->rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $download_id
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalReports(int $download_id): int {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "download_report` WHERE `download_id` = '" . (int)$download_id . "'");
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
}
|
234
admininistrator/model/catalog/filter.php
Normal file
234
admininistrator/model/catalog/filter.php
Normal file
@ -0,0 +1,234 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Model\Catalog;
|
||||
/**
|
||||
* Class Filter
|
||||
*
|
||||
* @package Opencart\Admin\Model\Catalog
|
||||
*/
|
||||
class Filter extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function addFilter(array $data): int {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "filter_group` SET `sort_order` = '" . (int)$data['sort_order'] . "'");
|
||||
|
||||
$filter_group_id = $this->db->getLastId();
|
||||
|
||||
foreach ($data['filter_group_description'] as $language_id => $value) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "filter_group_description` SET `filter_group_id` = '" . (int)$filter_group_id . "', `language_id` = '" . (int)$language_id . "', `name` = '" . $this->db->escape($value['name']) . "'");
|
||||
}
|
||||
|
||||
if (isset($data['filter'])) {
|
||||
foreach ($data['filter'] as $filter) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "filter` SET `filter_group_id` = '" . (int)$filter_group_id . "', `sort_order` = '" . (int)$filter['sort_order'] . "'");
|
||||
|
||||
$filter_id = $this->db->getLastId();
|
||||
|
||||
foreach ($filter['filter_description'] as $language_id => $filter_description) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "filter_description` SET `filter_id` = '" . (int)$filter_id . "', `language_id` = '" . (int)$language_id . "', `filter_group_id` = '" . (int)$filter_group_id . "', `name` = '" . $this->db->escape($filter_description['name']) . "'");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $filter_group_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $filter_group_id
|
||||
* @param array $data
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function editFilter(int $filter_group_id, array $data): void {
|
||||
$this->db->query("UPDATE `" . DB_PREFIX . "filter_group` SET `sort_order` = '" . (int)$data['sort_order'] . "' WHERE `filter_group_id` = '" . (int)$filter_group_id . "'");
|
||||
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "filter_group_description` WHERE `filter_group_id` = '" . (int)$filter_group_id . "'");
|
||||
|
||||
foreach ($data['filter_group_description'] as $language_id => $value) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "filter_group_description` SET `filter_group_id` = '" . (int)$filter_group_id . "', `language_id` = '" . (int)$language_id . "', `name` = '" . $this->db->escape($value['name']) . "'");
|
||||
}
|
||||
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "filter` WHERE `filter_group_id` = '" . (int)$filter_group_id . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "filter_description` WHERE `filter_group_id` = '" . (int)$filter_group_id . "'");
|
||||
|
||||
if (isset($data['filter'])) {
|
||||
foreach ($data['filter'] as $filter) {
|
||||
if ($filter['filter_id']) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "filter` SET `filter_id` = '" . (int)$filter['filter_id'] . "', `filter_group_id` = '" . (int)$filter_group_id . "', `sort_order` = '" . (int)$filter['sort_order'] . "'");
|
||||
} else {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "filter` SET `filter_group_id` = '" . (int)$filter_group_id . "', `sort_order` = '" . (int)$filter['sort_order'] . "'");
|
||||
}
|
||||
|
||||
$filter_id = $this->db->getLastId();
|
||||
|
||||
foreach ($filter['filter_description'] as $language_id => $filter_description) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "filter_description` SET `filter_id` = '" . (int)$filter_id . "', `language_id` = '" . (int)$language_id . "', `filter_group_id` = '" . (int)$filter_group_id . "', `name` = '" . $this->db->escape($filter_description['name']) . "'");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $filter_group_id
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function deleteFilter(int $filter_group_id): void {
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "filter_group` WHERE `filter_group_id` = '" . (int)$filter_group_id . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "filter_group_description` WHERE `filter_group_id` = '" . (int)$filter_group_id . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "filter` WHERE `filter_group_id` = '" . (int)$filter_group_id . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "filter_description` WHERE `filter_group_id` = '" . (int)$filter_group_id . "'");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $filter_group_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getGroup(int $filter_group_id): array {
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "filter_group` fg LEFT JOIN `" . DB_PREFIX . "filter_group_description` fgd ON (fg.`filter_group_id` = fgd.`filter_group_id`) WHERE fg.`filter_group_id` = '" . (int)$filter_group_id . "' AND fgd.`language_id` = '" . (int)$this->config->get('config_language_id') . "'");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getGroups(array $data = []): array {
|
||||
$sql = "SELECT * FROM `" . DB_PREFIX . "filter_group` fg LEFT JOIN `" . DB_PREFIX . "filter_group_description` fgd ON (fg.`filter_group_id` = fgd.`filter_group_id`) WHERE fgd.`language_id` = '" . (int)$this->config->get('config_language_id') . "'";
|
||||
|
||||
$sort_data = [
|
||||
'fgd.name',
|
||||
'fg.sort_order'
|
||||
];
|
||||
|
||||
if (isset($data['sort']) && in_array($data['sort'], $sort_data)) {
|
||||
$sql .= " ORDER BY " . $data['sort'];
|
||||
} else {
|
||||
$sql .= " ORDER BY fgd.`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'];
|
||||
}
|
||||
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
return $query->rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $filter_group_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getGroupDescriptions(int $filter_group_id): array {
|
||||
$filter_group_data = [];
|
||||
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "filter_group_description` WHERE `filter_group_id` = '" . (int)$filter_group_id . "'");
|
||||
|
||||
foreach ($query->rows as $result) {
|
||||
$filter_group_data[$result['language_id']] = ['name' => $result['name']];
|
||||
}
|
||||
|
||||
return $filter_group_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $filter_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getFilter(int $filter_id): array {
|
||||
$query = $this->db->query("SELECT *, (SELECT `name` FROM `" . DB_PREFIX . "filter_group_description` fgd WHERE f.`filter_group_id` = fgd.`filter_group_id` AND fgd.`language_id` = '" . (int)$this->config->get('config_language_id') . "') AS `group` FROM `" . DB_PREFIX . "filter` f LEFT JOIN `" . DB_PREFIX . "filter_description` fd ON (f.`filter_id` = fd.`filter_id`) WHERE f.`filter_id` = '" . (int)$filter_id . "' AND fd.`language_id` = '" . (int)$this->config->get('config_language_id') . "'");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getFilters(array $data): array {
|
||||
$sql = "SELECT *, (SELECT name FROM `" . DB_PREFIX . "filter_group_description` fgd WHERE f.`filter_group_id` = fgd.`filter_group_id` AND fgd.`language_id` = '" . (int)$this->config->get('config_language_id') . "') AS `group` FROM `" . DB_PREFIX . "filter` f LEFT JOIN `" . DB_PREFIX . "filter_description` fd ON (f.`filter_id` = fd.`filter_id`) WHERE fd.`language_id` = '" . (int)$this->config->get('config_language_id') . "'";
|
||||
|
||||
if (!empty($data['filter_name'])) {
|
||||
$sql .= " AND fd.`name` LIKE '" . $this->db->escape((string)$data['filter_name'] . '%') . "'";
|
||||
}
|
||||
|
||||
$sql .= " ORDER BY f.`sort_order` 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 $filter_group_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getDescriptions(int $filter_group_id): array {
|
||||
$filter_data = [];
|
||||
|
||||
$filter_query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "filter` WHERE `filter_group_id` = '" . (int)$filter_group_id . "'");
|
||||
|
||||
foreach ($filter_query->rows as $filter) {
|
||||
$filter_description_data = [];
|
||||
|
||||
$filter_description_query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "filter_description` WHERE `filter_id` = '" . (int)$filter['filter_id'] . "'");
|
||||
|
||||
foreach ($filter_description_query->rows as $filter_description) {
|
||||
$filter_description_data[$filter_description['language_id']] = ['name' => $filter_description['name']];
|
||||
}
|
||||
|
||||
$filter_data[] = [
|
||||
'filter_id' => $filter['filter_id'],
|
||||
'filter_description' => $filter_description_data,
|
||||
'sort_order' => $filter['sort_order']
|
||||
];
|
||||
}
|
||||
|
||||
return $filter_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalGroups(): int {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "filter_group`");
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
}
|
262
admininistrator/model/catalog/information.php
Normal file
262
admininistrator/model/catalog/information.php
Normal file
@ -0,0 +1,262 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Model\Catalog;
|
||||
/**
|
||||
* Class Information
|
||||
*
|
||||
* @package Opencart\Admin\Model\Catalog
|
||||
*/
|
||||
class Information extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function addInformation(array $data): int {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "information` SET `sort_order` = '" . (int)$data['sort_order'] . "', `bottom` = '" . (isset($data['bottom']) ? (int)$data['bottom'] : 0) . "', `status` = '" . (bool)(isset($data['status']) ? $data['status'] : 0) . "'");
|
||||
|
||||
$information_id = $this->db->getLastId();
|
||||
|
||||
foreach ($data['information_description'] as $language_id => $value) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "information_description` SET `information_id` = '" . (int)$information_id . "', `language_id` = '" . (int)$language_id . "', `title` = '" . $this->db->escape($value['title']) . "', `description` = '" . $this->db->escape($value['description']) . "', `meta_title` = '" . $this->db->escape($value['meta_title']) . "', `meta_description` = '" . $this->db->escape($value['meta_description']) . "', `meta_keyword` = '" . $this->db->escape($value['meta_keyword']) . "'");
|
||||
}
|
||||
|
||||
if (isset($data['information_store'])) {
|
||||
foreach ($data['information_store'] as $store_id) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "information_to_store` SET `information_id` = '" . (int)$information_id . "', `store_id` = '" . (int)$store_id . "'");
|
||||
}
|
||||
}
|
||||
|
||||
// SEO URL
|
||||
if (isset($data['information_seo_url'])) {
|
||||
foreach ($data['information_seo_url'] as $store_id => $language) {
|
||||
foreach ($language as $language_id => $keyword) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "seo_url` SET `store_id` = '" . (int)$store_id . "', `language_id` = '" . (int)$language_id . "', `key` = 'information_id', `value` = '" . (int)$information_id . "', `keyword` = '" . $this->db->escape($keyword) . "'");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($data['information_layout'])) {
|
||||
foreach ($data['information_layout'] as $store_id => $layout_id) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "information_to_layout` SET `information_id` = '" . (int)$information_id . "', `store_id` = '" . (int)$store_id . "', `layout_id` = '" . (int)$layout_id . "'");
|
||||
}
|
||||
}
|
||||
|
||||
$this->cache->delete('information');
|
||||
|
||||
return $information_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $information_id
|
||||
* @param array $data
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function editInformation(int $information_id, array $data): void {
|
||||
$this->db->query("UPDATE `" . DB_PREFIX . "information` SET `sort_order` = '" . (int)$data['sort_order'] . "', `bottom` = '" . (isset($data['bottom']) ? (int)$data['bottom'] : 0) . "', `status` = '" . (bool)(isset($data['status']) ? $data['status'] : 0) . "' WHERE `information_id` = '" . (int)$information_id . "'");
|
||||
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "information_description` WHERE `information_id` = '" . (int)$information_id . "'");
|
||||
|
||||
foreach ($data['information_description'] as $language_id => $value) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "information_description` SET `information_id` = '" . (int)$information_id . "', `language_id` = '" . (int)$language_id . "', `title` = '" . $this->db->escape($value['title']) . "', `description` = '" . $this->db->escape($value['description']) . "', `meta_title` = '" . $this->db->escape($value['meta_title']) . "', `meta_description` = '" . $this->db->escape($value['meta_description']) . "', `meta_keyword` = '" . $this->db->escape($value['meta_keyword']) . "'");
|
||||
}
|
||||
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "information_to_store` WHERE `information_id` = '" . (int)$information_id . "'");
|
||||
|
||||
if (isset($data['information_store'])) {
|
||||
foreach ($data['information_store'] as $store_id) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "information_to_store` SET `information_id` = '" . (int)$information_id . "', `store_id` = '" . (int)$store_id . "'");
|
||||
}
|
||||
}
|
||||
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "seo_url` WHERE `key` = 'information_id' AND `value` = '" . (int)$information_id . "'");
|
||||
|
||||
if (isset($data['information_seo_url'])) {
|
||||
foreach ($data['information_seo_url'] as $store_id => $language) {
|
||||
foreach ($language as $language_id => $keyword) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "seo_url` SET `store_id` = '" . (int)$store_id . "', `language_id` = '" . (int)$language_id . "', `key` = 'information_id', `value` = '" . (int)$information_id . "', `keyword` = '" . $this->db->escape($keyword) . "'");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "information_to_layout` WHERE `information_id` = '" . (int)$information_id . "'");
|
||||
|
||||
if (isset($data['information_layout'])) {
|
||||
foreach ($data['information_layout'] as $store_id => $layout_id) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "information_to_layout` SET `information_id` = '" . (int)$information_id . "', `store_id` = '" . (int)$store_id . "', `layout_id` = '" . (int)$layout_id . "'");
|
||||
}
|
||||
}
|
||||
|
||||
$this->cache->delete('information');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $information_id
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function deleteInformation(int $information_id): void {
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "information` WHERE `information_id` = '" . (int)$information_id . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "information_description` WHERE `information_id` = '" . (int)$information_id . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "information_to_store` WHERE `information_id` = '" . (int)$information_id . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "information_to_layout` WHERE `information_id` = '" . (int)$information_id . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "seo_url` WHERE `key` = 'information_id' AND `value` = '" . (int)$information_id . "'");
|
||||
|
||||
$this->cache->delete('information');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $information_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getInformation(int $information_id): array {
|
||||
$query = $this->db->query("SELECT DISTINCT * FROM `" . DB_PREFIX . "information` WHERE `information_id` = '" . (int)$information_id . "'");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getInformations(array $data = []): array {
|
||||
$sql = "SELECT * FROM `" . DB_PREFIX . "information` i LEFT JOIN `" . DB_PREFIX . "information_description` id ON (i.`information_id` = id.`information_id`) WHERE id.`language_id` = '" . (int)$this->config->get('config_language_id') . "'";
|
||||
|
||||
$sort_data = [
|
||||
'id.title',
|
||||
'i.sort_order'
|
||||
];
|
||||
|
||||
if (isset($data['sort']) && in_array($data['sort'], $sort_data)) {
|
||||
$sql .= " ORDER BY " . $data['sort'];
|
||||
} else {
|
||||
$sql .= " ORDER BY id.`title`";
|
||||
}
|
||||
|
||||
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'];
|
||||
}
|
||||
|
||||
$information_data = $this->cache->get('information.' . md5($sql));
|
||||
|
||||
if (!$information_data) {
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
$information_data = $query->rows;
|
||||
|
||||
$this->cache->set('information.' . md5($sql), $information_data);
|
||||
}
|
||||
|
||||
return $information_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $information_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getDescriptions(int $information_id): array {
|
||||
$information_description_data = [];
|
||||
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "information_description` WHERE `information_id` = '" . (int)$information_id . "'");
|
||||
|
||||
foreach ($query->rows as $result) {
|
||||
$information_description_data[$result['language_id']] = [
|
||||
'title' => $result['title'],
|
||||
'description' => $result['description'],
|
||||
'meta_title' => $result['meta_title'],
|
||||
'meta_description' => $result['meta_description'],
|
||||
'meta_keyword' => $result['meta_keyword']
|
||||
];
|
||||
}
|
||||
|
||||
return $information_description_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $information_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getStores(int $information_id): array {
|
||||
$information_store_data = [];
|
||||
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "information_to_store` WHERE `information_id` = '" . (int)$information_id . "'");
|
||||
|
||||
foreach ($query->rows as $result) {
|
||||
$information_store_data[] = $result['store_id'];
|
||||
}
|
||||
|
||||
return $information_store_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $information_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getSeoUrls(int $information_id): array {
|
||||
$information_seo_url_data = [];
|
||||
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "seo_url` WHERE `key` = 'information_id' AND `value` = '" . (int)$information_id . "'");
|
||||
|
||||
foreach ($query->rows as $result) {
|
||||
$information_seo_url_data[$result['store_id']][$result['language_id']] = $result['keyword'];
|
||||
}
|
||||
|
||||
return $information_seo_url_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $information_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getLayouts(int $information_id): array {
|
||||
$information_layout_data = [];
|
||||
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "information_to_layout` WHERE `information_id` = '" . (int)$information_id . "'");
|
||||
|
||||
foreach ($query->rows as $result) {
|
||||
$information_layout_data[$result['store_id']] = $result['layout_id'];
|
||||
}
|
||||
|
||||
return $information_layout_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalInformations(): int {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "information`");
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $layout_id
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalInformationsByLayoutId(int $layout_id): int {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "information_to_layout` WHERE `layout_id` = '" . (int)$layout_id . "'");
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
}
|
224
admininistrator/model/catalog/manufacturer.php
Normal file
224
admininistrator/model/catalog/manufacturer.php
Normal file
@ -0,0 +1,224 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Model\Catalog;
|
||||
/**
|
||||
* Class Manufacturer
|
||||
*
|
||||
* @package Opencart\Admin\Model\Catalog
|
||||
*/
|
||||
class Manufacturer extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function addManufacturer(array $data): int {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "manufacturer` SET `name` = '" . $this->db->escape((string)$data['name']) . "', `image` = '" . $this->db->escape((string)$data['image']) . "', `sort_order` = '" . (int)$data['sort_order'] . "'");
|
||||
|
||||
$manufacturer_id = $this->db->getLastId();
|
||||
|
||||
if (isset($data['manufacturer_store'])) {
|
||||
foreach ($data['manufacturer_store'] as $store_id) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "manufacturer_to_store` SET `manufacturer_id` = '" . (int)$manufacturer_id . "', `store_id` = '" . (int)$store_id . "'");
|
||||
}
|
||||
}
|
||||
|
||||
// SEO URL
|
||||
if (isset($data['manufacturer_seo_url'])) {
|
||||
foreach ($data['manufacturer_seo_url'] as $store_id => $language) {
|
||||
foreach ($language as $language_id => $keyword) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "seo_url` SET `store_id` = '" . (int)$store_id . "', `language_id` = '" . (int)$language_id . "', `key` = 'manufacturer_id', `value` = '" . (int)$manufacturer_id . "', `keyword` = '" . $this->db->escape($keyword) . "'");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($data['manufacturer_layout'])) {
|
||||
foreach ($data['manufacturer_layout'] as $store_id => $layout_id) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "manufacturer_to_layout` SET `manufacturer_id` = '" . (int)$manufacturer_id . "', `store_id` = '" . (int)$store_id . "', `layout_id` = '" . (int)$layout_id . "'");
|
||||
}
|
||||
}
|
||||
|
||||
$this->cache->delete('manufacturer');
|
||||
|
||||
return $manufacturer_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $manufacturer_id
|
||||
* @param array $data
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function editManufacturer(int $manufacturer_id, array $data): void {
|
||||
$this->db->query("UPDATE `" . DB_PREFIX . "manufacturer` SET `name` = '" . $this->db->escape((string)$data['name']) . "', `image` = '" . $this->db->escape((string)$data['image']) . "', `sort_order` = '" . (int)$data['sort_order'] . "' WHERE `manufacturer_id` = '" . (int)$manufacturer_id . "'");
|
||||
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "manufacturer_to_store` WHERE `manufacturer_id` = '" . (int)$manufacturer_id . "'");
|
||||
|
||||
if (isset($data['manufacturer_store'])) {
|
||||
foreach ($data['manufacturer_store'] as $store_id) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "manufacturer_to_store` SET `manufacturer_id` = '" . (int)$manufacturer_id . "', `store_id` = '" . (int)$store_id . "'");
|
||||
}
|
||||
}
|
||||
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "seo_url` WHERE `key` = 'manufacturer_id' AND `value` = '" . (int)$manufacturer_id . "'");
|
||||
|
||||
if (isset($data['manufacturer_seo_url'])) {
|
||||
foreach ($data['manufacturer_seo_url'] as $store_id => $language) {
|
||||
foreach ($language as $language_id => $keyword) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "seo_url` SET `store_id` = '" . (int)$store_id . "', `language_id` = '" . (int)$language_id . "', `key` = 'manufacturer_id', `value` = '" . (int)$manufacturer_id . "', `keyword` = '" . $this->db->escape($keyword) . "'");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "manufacturer_to_layout` WHERE `manufacturer_id` = '" . (int)$manufacturer_id . "'");
|
||||
|
||||
if (isset($data['manufacturer_layout'])) {
|
||||
foreach ($data['manufacturer_layout'] as $store_id => $layout_id) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "manufacturer_to_layout` SET `manufacturer_id` = '" . (int)$manufacturer_id . "', `store_id` = '" . (int)$store_id . "', `layout_id` = '" . (int)$layout_id . "'");
|
||||
}
|
||||
}
|
||||
|
||||
$this->cache->delete('manufacturer');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $manufacturer_id
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function deleteManufacturer(int $manufacturer_id): void {
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "manufacturer` WHERE `manufacturer_id` = '" . (int)$manufacturer_id . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "manufacturer_to_store` WHERE `manufacturer_id` = '" . (int)$manufacturer_id . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "manufacturer_to_layout` WHERE `manufacturer_id` = '" . (int)$manufacturer_id . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "seo_url` WHERE `key` = 'manufacturer_id' AND `value` = '" . (int)$manufacturer_id . "'");
|
||||
|
||||
$this->cache->delete('manufacturer');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $manufacturer_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getManufacturer(int $manufacturer_id): array {
|
||||
$query = $this->db->query("SELECT DISTINCT * FROM `" . DB_PREFIX . "manufacturer` WHERE `manufacturer_id` = '" . (int)$manufacturer_id . "'");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getManufacturers(array $data = []): array {
|
||||
$sql = "SELECT * FROM `" . DB_PREFIX . "manufacturer`";
|
||||
|
||||
if (!empty($data['filter_name'])) {
|
||||
$sql .= " WHERE `name` LIKE '" . $this->db->escape((string)$data['filter_name'] . '%') . "'";
|
||||
}
|
||||
|
||||
$sort_data = [
|
||||
'name',
|
||||
'sort_order'
|
||||
];
|
||||
|
||||
if (isset($data['sort']) && in_array($data['sort'], $sort_data)) {
|
||||
$sql .= " ORDER BY " . $data['sort'];
|
||||
} else {
|
||||
$sql .= " ORDER BY `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'];
|
||||
}
|
||||
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
return $query->rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $manufacturer_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getStores(int $manufacturer_id): array {
|
||||
$manufacturer_store_data = [];
|
||||
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "manufacturer_to_store` WHERE `manufacturer_id` = '" . (int)$manufacturer_id . "'");
|
||||
|
||||
foreach ($query->rows as $result) {
|
||||
$manufacturer_store_data[] = $result['store_id'];
|
||||
}
|
||||
|
||||
return $manufacturer_store_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $manufacturer_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getSeoUrls(int $manufacturer_id): array {
|
||||
$manufacturer_seo_url_data = [];
|
||||
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "seo_url` WHERE `key` = 'manufacturer_id' AND `value` = '" . (int)$manufacturer_id . "'");
|
||||
|
||||
foreach ($query->rows as $result) {
|
||||
$manufacturer_seo_url_data[$result['store_id']][$result['language_id']] = $result['keyword'];
|
||||
}
|
||||
|
||||
return $manufacturer_seo_url_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $manufacturer_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getLayouts(int $manufacturer_id): array {
|
||||
$manufacturer_layout_data = [];
|
||||
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "manufacturer_to_layout` WHERE `manufacturer_id` = '" . (int)$manufacturer_id . "'");
|
||||
|
||||
foreach ($query->rows as $result) {
|
||||
$manufacturer_layout_data[$result['store_id']] = $result['layout_id'];
|
||||
}
|
||||
|
||||
return $manufacturer_layout_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalManufacturers(): int {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "manufacturer`");
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $layout_id
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalManufacturersByLayoutId(int $layout_id): int {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "manufacturer_to_layout` WHERE `layout_id` = '" . (int)$layout_id . "'");
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
}
|
231
admininistrator/model/catalog/option.php
Normal file
231
admininistrator/model/catalog/option.php
Normal file
@ -0,0 +1,231 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Model\Catalog;
|
||||
/**
|
||||
* Class Option
|
||||
*
|
||||
* @package Opencart\Admin\Model\Catalog
|
||||
*/
|
||||
class Option extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function addOption(array $data): int {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "option` SET `type` = '" . $this->db->escape((string)$data['type']) . "', `sort_order` = '" . (int)$data['sort_order'] . "'");
|
||||
|
||||
$option_id = $this->db->getLastId();
|
||||
|
||||
foreach ($data['option_description'] as $language_id => $value) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "option_description` SET `option_id` = '" . (int)$option_id . "', `language_id` = '" . (int)$language_id . "', `name` = '" . $this->db->escape($value['name']) . "'");
|
||||
}
|
||||
|
||||
if (isset($data['option_value'])) {
|
||||
foreach ($data['option_value'] as $option_value) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "option_value` SET `option_id` = '" . (int)$option_id . "', `image` = '" . $this->db->escape(html_entity_decode($option_value['image'], ENT_QUOTES, 'UTF-8')) . "', `sort_order` = '" . (int)$option_value['sort_order'] . "'");
|
||||
|
||||
$option_value_id = $this->db->getLastId();
|
||||
|
||||
foreach ($option_value['option_value_description'] as $language_id => $option_value_description) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "option_value_description` SET `option_value_id` = '" . (int)$option_value_id . "', `language_id` = '" . (int)$language_id . "', `option_id` = '" . (int)$option_id . "', `name` = '" . $this->db->escape($option_value_description['name']) . "'");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $option_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $option_id
|
||||
* @param array $data
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function editOption(int $option_id, array $data): void {
|
||||
$this->db->query("UPDATE `" . DB_PREFIX . "option` SET `type` = '" . $this->db->escape((string)$data['type']) . "', `sort_order` = '" . (int)$data['sort_order'] . "' WHERE `option_id` = '" . (int)$option_id . "'");
|
||||
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "option_description` WHERE `option_id` = '" . (int)$option_id . "'");
|
||||
|
||||
foreach ($data['option_description'] as $language_id => $value) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "option_description` SET `option_id` = '" . (int)$option_id . "', `language_id` = '" . (int)$language_id . "', `name` = '" . $this->db->escape($value['name']) . "'");
|
||||
}
|
||||
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "option_value` WHERE `option_id` = '" . (int)$option_id . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "option_value_description` WHERE `option_id` = '" . (int)$option_id . "'");
|
||||
|
||||
if (isset($data['option_value'])) {
|
||||
foreach ($data['option_value'] as $option_value) {
|
||||
if ($option_value['option_value_id']) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "option_value` SET `option_value_id` = '" . (int)$option_value['option_value_id'] . "', `option_id` = '" . (int)$option_id . "', `image` = '" . $this->db->escape(html_entity_decode($option_value['image'], ENT_QUOTES, 'UTF-8')) . "', `sort_order` = '" . (int)$option_value['sort_order'] . "'");
|
||||
} else {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "option_value` SET `option_id` = '" . (int)$option_id . "', `image` = '" . $this->db->escape(html_entity_decode($option_value['image'], ENT_QUOTES, 'UTF-8')) . "', `sort_order` = '" . (int)$option_value['sort_order'] . "'");
|
||||
}
|
||||
|
||||
$option_value_id = $this->db->getLastId();
|
||||
|
||||
foreach ($option_value['option_value_description'] as $language_id => $option_value_description) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "option_value_description` SET `option_value_id` = '" . (int)$option_value_id . "', `language_id` = '" . (int)$language_id . "', `option_id` = '" . (int)$option_id . "', `name` = '" . $this->db->escape($option_value_description['name']) . "'");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $option_id
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function deleteOption(int $option_id): void {
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "option` WHERE `option_id` = '" . (int)$option_id . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "option_description` WHERE `option_id` = '" . (int)$option_id . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "option_value` WHERE `option_id` = '" . (int)$option_id . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "option_value_description` WHERE `option_id` = '" . (int)$option_id . "'");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $option_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getOption(int $option_id): array {
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "option` o LEFT JOIN `" . DB_PREFIX . "option_description` od ON (o.`option_id` = od.`option_id`) WHERE o.`option_id` = '" . (int)$option_id . "' AND od.`language_id` = '" . (int)$this->config->get('config_language_id') . "'");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getOptions(array $data = []): array {
|
||||
$sql = "SELECT * FROM `" . DB_PREFIX . "option` o LEFT JOIN `" . DB_PREFIX . "option_description` od ON (o.`option_id` = od.`option_id`) WHERE od.`language_id` = '" . (int)$this->config->get('config_language_id') . "'";
|
||||
|
||||
if (!empty($data['filter_name'])) {
|
||||
$sql .= " AND od.`name` LIKE '" . $this->db->escape((string)$data['filter_name'] . '%') . "'";
|
||||
}
|
||||
|
||||
$sort_data = [
|
||||
'od.name',
|
||||
'o.type',
|
||||
'o.sort_order'
|
||||
];
|
||||
|
||||
if (isset($data['sort']) && in_array($data['sort'], $sort_data)) {
|
||||
$sql .= " ORDER BY " . $data['sort'];
|
||||
} else {
|
||||
$sql .= " ORDER BY `od`.`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'];
|
||||
}
|
||||
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
return $query->rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $option_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getDescriptions(int $option_id): array {
|
||||
$option_data = [];
|
||||
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "option_description` WHERE `option_id` = '" . (int)$option_id . "'");
|
||||
|
||||
foreach ($query->rows as $result) {
|
||||
$option_data[$result['language_id']] = ['name' => $result['name']];
|
||||
}
|
||||
|
||||
return $option_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $option_value_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getValue(int $option_value_id): array {
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "option_value` ov LEFT JOIN `" . DB_PREFIX . "option_value_description` ovd ON (ov.`option_value_id` = ovd.`option_value_id`) WHERE ov.`option_value_id` = '" . (int)$option_value_id . "' AND ovd.`language_id` = '" . (int)$this->config->get('config_language_id') . "'");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $option_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getValues(int $option_id): array {
|
||||
$option_value_data = [];
|
||||
|
||||
$option_value_query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "option_value` ov LEFT JOIN `" . DB_PREFIX . "option_value_description` ovd ON (ov.`option_value_id` = ovd.`option_value_id`) WHERE ov.`option_id` = '" . (int)$option_id . "' AND ovd.`language_id` = '" . (int)$this->config->get('config_language_id') . "' ORDER BY ov.`sort_order`, ovd.`name`");
|
||||
|
||||
foreach ($option_value_query->rows as $option_value) {
|
||||
$option_value_data[] = [
|
||||
'option_value_id' => $option_value['option_value_id'],
|
||||
'name' => $option_value['name'],
|
||||
'image' => $option_value['image'],
|
||||
'sort_order' => $option_value['sort_order']
|
||||
];
|
||||
}
|
||||
|
||||
return $option_value_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $option_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getValueDescriptions(int $option_id): array {
|
||||
$option_value_data = [];
|
||||
|
||||
$option_value_query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "option_value` WHERE `option_id` = '" . (int)$option_id . "' ORDER BY `sort_order`");
|
||||
|
||||
foreach ($option_value_query->rows as $option_value) {
|
||||
$option_value_description_data = [];
|
||||
|
||||
$option_value_description_query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "option_value_description` WHERE `option_value_id` = '" . (int)$option_value['option_value_id'] . "'");
|
||||
|
||||
foreach ($option_value_description_query->rows as $option_value_description) {
|
||||
$option_value_description_data[$option_value_description['language_id']] = ['name' => $option_value_description['name']];
|
||||
}
|
||||
|
||||
$option_value_data[] = [
|
||||
'option_value_id' => $option_value['option_value_id'],
|
||||
'option_value_description' => $option_value_description_data,
|
||||
'image' => $option_value['image'],
|
||||
'sort_order' => $option_value['sort_order']
|
||||
];
|
||||
}
|
||||
|
||||
return $option_value_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalOptions(): int {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "option`");
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
}
|
1407
admininistrator/model/catalog/product.php
Normal file
1407
admininistrator/model/catalog/product.php
Normal file
File diff suppressed because it is too large
Load Diff
198
admininistrator/model/catalog/review.php
Normal file
198
admininistrator/model/catalog/review.php
Normal file
@ -0,0 +1,198 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Model\Catalog;
|
||||
/**
|
||||
* Class Review
|
||||
*
|
||||
* @package Opencart\Admin\Model\Catalog
|
||||
*/
|
||||
class Review extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function addReview(array $data): int {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "review` SET `author` = '" . $this->db->escape((string)$data['author']) . "', `product_id` = '" . (int)$data['product_id'] . "', `text` = '" . $this->db->escape(strip_tags((string)$data['text'])) . "', `rating` = '" . (int)$data['rating'] . "', `status` = '" . (bool)(isset($data['status']) ? $data['status'] : 0) . "', `date_added` = '" . $this->db->escape((string)$data['date_added']) . "'");
|
||||
|
||||
$review_id = $this->db->getLastId();
|
||||
|
||||
// Update product rating
|
||||
$this->load->model('catalog/product');
|
||||
|
||||
$this->model_catalog_product->editRating($data['product_id'], $this->getRating($data['product_id']));
|
||||
|
||||
$this->cache->delete('product');
|
||||
|
||||
return $review_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $review_id
|
||||
* @param array $data
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function editReview(int $review_id, array $data): void {
|
||||
$this->db->query("UPDATE `" . DB_PREFIX . "review` SET `author` = '" . $this->db->escape((string)$data['author']) . "', `product_id` = '" . (int)$data['product_id'] . "', `text` = '" . $this->db->escape(strip_tags((string)$data['text'])) . "', `rating` = '" . (int)$data['rating'] . "', `status` = '" . (bool)(isset($data['status']) ? $data['status'] : 0) . "', `date_added` = '" . $this->db->escape((string)$data['date_added']) . "', `date_modified` = NOW() WHERE `review_id` = '" . (int)$review_id . "'");
|
||||
|
||||
// Update product rating
|
||||
$this->load->model('catalog/product');
|
||||
|
||||
$this->model_catalog_product->editRating($data['product_id'], $this->getRating($data['product_id']));
|
||||
|
||||
$this->cache->delete('product');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $review_id
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function deleteReview(int $review_id): void {
|
||||
$review_info = $this->getReview($review_id);
|
||||
|
||||
if ($review_info) {
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "review` WHERE `review_id` = '" . (int)$review_info['review_id'] . "'");
|
||||
|
||||
// Update product rating
|
||||
$this->load->model('catalog/product');
|
||||
|
||||
$this->model_catalog_product->editRating($review_info['product_id'], $this->getRating($review_info['product_id']));
|
||||
|
||||
$this->cache->delete('product');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $review_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getReview(int $review_id): array {
|
||||
$query = $this->db->query("SELECT DISTINCT *, (SELECT pd.`name` FROM `" . DB_PREFIX . "product_description` pd WHERE pd.`product_id` = r.`product_id` AND pd.`language_id` = '" . (int)$this->config->get('config_language_id') . "') AS product FROM `" . DB_PREFIX . "review` r WHERE r.`review_id` = '" . (int)$review_id . "'");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $product_id
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getRating(int $product_id): int {
|
||||
$query = $this->db->query("SELECT AVG(`rating`) AS `total` FROM `" . DB_PREFIX . "review` WHERE `product_id` = '" . (int)$product_id . "' AND `status` = '1'");
|
||||
|
||||
if ($query->num_rows) {
|
||||
return (int)$query->row['total'];
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getReviews(array $data = []): array {
|
||||
$sql = "SELECT r.`review_id`, pd.`name`, r.`author`, r.`rating`, r.`status`, r.`date_added` FROM `" . DB_PREFIX . "review` r LEFT JOIN `" . DB_PREFIX . "product_description` pd ON (r.`product_id` = pd.`product_id`) WHERE pd.`language_id` = '" . (int)$this->config->get('config_language_id') . "'";
|
||||
|
||||
if (!empty($data['filter_product'])) {
|
||||
$sql .= " AND pd.`name` LIKE '" . $this->db->escape((string)$data['filter_product'] . '%') . "'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_author'])) {
|
||||
$sql .= " AND r.`author` LIKE '" . $this->db->escape((string)$data['filter_author'] . '%') . "'";
|
||||
}
|
||||
|
||||
if (isset($data['filter_status']) && $data['filter_status'] !== '') {
|
||||
$sql .= " AND r.`status` = '" . (int)$data['filter_status'] . "'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_date_from'])) {
|
||||
$sql .= " AND DATE(r.`date_added`) >= DATE('" . $this->db->escape((string)$data['filter_date_from']) . "')";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_date_to'])) {
|
||||
$sql .= " AND DATE(r.`date_added`) <= DATE('" . $this->db->escape((string)$data['filter_date_to']) . "')";
|
||||
}
|
||||
|
||||
$sort_data = [
|
||||
'pd.name',
|
||||
'r.author',
|
||||
'r.rating',
|
||||
'r.status',
|
||||
'r.date_added'
|
||||
];
|
||||
|
||||
if (isset($data['sort']) && in_array($data['sort'], $sort_data)) {
|
||||
$sql .= " ORDER BY " . $data['sort'];
|
||||
} else {
|
||||
$sql .= " ORDER BY r.`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;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalReviews(array $data = []): int {
|
||||
$sql = "SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "review` r LEFT JOIN `" . DB_PREFIX . "product_description` pd ON (r.`product_id` = pd.`product_id`) WHERE pd.`language_id` = '" . (int)$this->config->get('config_language_id') . "'";
|
||||
|
||||
if (!empty($data['filter_product'])) {
|
||||
$sql .= " AND pd.`name` LIKE '" . $this->db->escape((string)$data['filter_product'] . '%') . "'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_author'])) {
|
||||
$sql .= " AND r.`author` LIKE '" . $this->db->escape((string)$data['filter_author'] . '%') . "'";
|
||||
}
|
||||
|
||||
if (isset($data['filter_status']) && $data['filter_status'] !== '') {
|
||||
$sql .= " AND r.`status` = '" . (int)$data['filter_status'] . "'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_date_from'])) {
|
||||
$sql .= " AND DATE(r.`date_added`) >= DATE('" . $this->db->escape((string)$data['filter_date_from']) . "')";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_date_to'])) {
|
||||
$sql .= " AND DATE(r.`date_added`) <= DATE('" . $this->db->escape((string)$data['filter_date_to']) . "')";
|
||||
}
|
||||
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalReviewsAwaitingApproval(): int {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "review` WHERE `status` = '0'");
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
}
|
149
admininistrator/model/catalog/subscription_plan.php
Normal file
149
admininistrator/model/catalog/subscription_plan.php
Normal file
@ -0,0 +1,149 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Model\Catalog;
|
||||
/**
|
||||
* Class Subscription Plan
|
||||
*
|
||||
* @package Opencart\Admin\Model\Catalog
|
||||
*/
|
||||
class SubscriptionPlan extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function addSubscriptionPlan(array $data): int {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "subscription_plan` SET `trial_frequency` = '" . $this->db->escape((string)$data['trial_frequency']) . "', `trial_duration` = '" . (int)$data['trial_duration'] . "', `trial_cycle` = '" . (int)$data['trial_cycle'] . "', `trial_status` = '" . (int)$data['trial_status'] . "', `frequency` = '" . $this->db->escape((string)$data['frequency']) . "', `duration` = '" . (int)$data['duration'] . "', `cycle` = '" . (int)$data['cycle'] . "', `status` = '" . (bool)(isset($data['status']) ? $data['status'] : 0) . "', `sort_order` = '" . (int)$data['sort_order'] . "'");
|
||||
|
||||
$subscription_plan_id = $this->db->getLastId();
|
||||
|
||||
foreach ($data['subscription_plan_description'] as $language_id => $subscription_plan_description) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "subscription_plan_description` SET `subscription_plan_id` = '" . (int)$subscription_plan_id . "', `language_id` = '" . (int)$language_id . "', `name` = '" . $this->db->escape($subscription_plan_description['name']) . "'");
|
||||
}
|
||||
|
||||
return $subscription_plan_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $subscription_plan_id
|
||||
* @param array $data
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function editSubscriptionPlan(int $subscription_plan_id, array $data): void {
|
||||
$this->db->query("UPDATE `" . DB_PREFIX . "subscription_plan` SET `trial_frequency` = '" . $this->db->escape((string)$data['trial_frequency']) . "', `trial_duration` = '" . (int)$data['trial_duration'] . "', `trial_cycle` = '" . (int)$data['trial_cycle'] . "', `trial_status` = '" . (int)$data['trial_status'] . "', `frequency` = '" . $this->db->escape((string)$data['frequency']) . "', `duration` = '" . (int)$data['duration'] . "', `cycle` = '" . (int)$data['cycle'] . "', `status` = '" . (bool)(isset($data['status']) ? $data['status'] : 0) . "', `sort_order` = '" . (int)$data['sort_order'] . "' WHERE `subscription_plan_id` = '" . (int)$subscription_plan_id . "'");
|
||||
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "subscription_plan_description` WHERE `subscription_plan_id` = '" . (int)$subscription_plan_id . "'");
|
||||
|
||||
foreach ($data['subscription_plan_description'] as $language_id => $subscription_plan_description) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "subscription_plan_description` SET `subscription_plan_id` = '" . (int)$subscription_plan_id . "', `language_id` = '" . (int)$language_id . "', `name` = '" . $this->db->escape($subscription_plan_description['name']) . "'");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $subscription_plan_id
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function copySubscriptionPlan(int $subscription_plan_id): void {
|
||||
$data = $this->getSubscriptionPlan($subscription_plan_id);
|
||||
|
||||
$data['subscription_plan_description'] = $this->getDescription($subscription_plan_id);
|
||||
|
||||
$this->addSubscriptionPlan($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $subscription_plan_id
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function deleteSubscriptionPlan(int $subscription_plan_id): void {
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "subscription_plan` WHERE `subscription_plan_id` = '" . (int)$subscription_plan_id . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "subscription_plan_description` WHERE `subscription_plan_id` = '" . (int)$subscription_plan_id . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "product_subscription` WHERE `subscription_plan_id` = '" . (int)$subscription_plan_id . "'");
|
||||
$this->db->query("UPDATE `" . DB_PREFIX . "subscription` SET `subscription_plan_id` = '0' WHERE `subscription_plan_id` = '" . (int)$subscription_plan_id . "'");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $subscription_plan_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getSubscriptionPlan(int $subscription_plan_id): array {
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "subscription_plan` sp LEFT JOIN `" . DB_PREFIX . "subscription_plan_description` spd ON (sp.`subscription_plan_id` = spd.`subscription_plan_id`) WHERE sp.`subscription_plan_id` = '" . (int)$subscription_plan_id . "' AND spd.`language_id` = '" . (int)$this->config->get('config_language_id') . "'");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $subscription_plan_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getDescription(int $subscription_plan_id): array {
|
||||
$subscription_plan_description_data = [];
|
||||
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "subscription_plan_description` WHERE `subscription_plan_id` = '" . (int)$subscription_plan_id . "'");
|
||||
|
||||
foreach ($query->rows as $result) {
|
||||
$subscription_plan_description_data[$result['language_id']] = ['name' => $result['name']];
|
||||
}
|
||||
|
||||
return $subscription_plan_description_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getSubscriptionPlans(array $data = []): array {
|
||||
$sql = "SELECT * FROM `" . DB_PREFIX . "subscription_plan` sp LEFT JOIN `" . DB_PREFIX . "subscription_plan_description` spd ON (sp.`subscription_plan_id` = spd.`subscription_plan_id`) WHERE spd.`language_id` = '" . (int)$this->config->get('config_language_id') . "'";
|
||||
|
||||
if (!empty($data['filter_name'])) {
|
||||
$sql .= " AND spd.`name` LIKE '" . $this->db->escape((string)$data['filter_name'] . '%') . "'";
|
||||
}
|
||||
|
||||
$sort_data = [
|
||||
'spd.name',
|
||||
'sp.sort_order'
|
||||
];
|
||||
|
||||
if (isset($data['sort']) && in_array($data['sort'], $sort_data)) {
|
||||
$sql .= " ORDER BY " . $data['sort'];
|
||||
} else {
|
||||
$sql .= " ORDER BY `spd`.`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'];
|
||||
}
|
||||
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
return $query->rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalSubscriptionPlans(): int {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "subscription_plan`");
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
}
|
120
admininistrator/model/cms/antispam.php
Normal file
120
admininistrator/model/cms/antispam.php
Normal file
@ -0,0 +1,120 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Model\Cms;
|
||||
/**
|
||||
* Class Country
|
||||
*
|
||||
* @package Opencart\Admin\Model\Cms
|
||||
*/
|
||||
class Antispam extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function addAntispam(array $data = []): int {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "antispam` SET `keyword` = '" . $this->db->escape((string)$data['keyword']) . "'");
|
||||
|
||||
return $this->db->getLastId();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function editAntispam(int $antispam_id, array $data = []): void {
|
||||
$this->db->query("UPDATE `" . DB_PREFIX . "antispam` SET `keyword` = '" . $this->db->escape((string)$data['keyword']) . "' WHERE `antispam_id` = '" . (int)$antispam_id . "'");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $antispam_id
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function deleteAntispam(int $antispam_id): void {
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "antispam` WHERE `antispam_id` = '" . (int)$antispam_id . "'");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $antispam_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getAntispam(int $antispam_id): array {
|
||||
$query = $this->db->query("SELECT DISTINCT * FROM `" . DB_PREFIX . "antispam` WHERE `antispam_id` = '" . (int)$antispam_id . "'");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getAntispams(array $data = []): array {
|
||||
$sql = "SELECT * FROM `" . DB_PREFIX . "antispam`";
|
||||
|
||||
$implode = [];
|
||||
|
||||
if (!empty($data['filter_keyword'])) {
|
||||
$implode[] = "`keyword` LIKE '" . $this->db->escape((string)$data['filter_keyword']) . "'";
|
||||
}
|
||||
|
||||
if ($implode) {
|
||||
$sql .= " WHERE " . implode(" AND ", $implode);
|
||||
}
|
||||
|
||||
$sort_data = ['keyword'];
|
||||
|
||||
if (isset($data['sort']) && in_array($data['sort'], $sort_data)) {
|
||||
$sql .= " ORDER BY " . $data['sort'];
|
||||
} else {
|
||||
$sql .= " ORDER BY `keyword`";
|
||||
}
|
||||
|
||||
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 getTotalAntispams(array $data = []): int {
|
||||
$sql = "SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "antispam`";
|
||||
|
||||
$implode = [];
|
||||
|
||||
if (!empty($data['filter_keyword'])) {
|
||||
$implode[] = "`keyword` LIKE '" . $this->db->escape((string)$data['filter_keyword']) . "'";
|
||||
}
|
||||
|
||||
if ($implode) {
|
||||
$sql .= " WHERE " . implode(" AND ", $implode);
|
||||
}
|
||||
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
}
|
365
admininistrator/model/cms/article.php
Normal file
365
admininistrator/model/cms/article.php
Normal file
@ -0,0 +1,365 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Model\Cms;
|
||||
/**
|
||||
* Class Article
|
||||
*
|
||||
* @package Opencart\Admin\Model\Cms
|
||||
*/
|
||||
class Article extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function addArticle(array $data): int {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "article` SET `topic_id` = '" . (int)$data['topic_id'] . "', `author` = '" . $this->db->escape($data['author']) . "', `status` = '" . (bool)(isset($data['status']) ? $data['status'] : 0) . "', `date_added` = NOW(), `date_modified` = NOW()");
|
||||
|
||||
$article_id = $this->db->getLastId();
|
||||
|
||||
foreach ($data['article_description'] as $language_id => $value) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "article_description` SET `article_id` = '" . (int)$article_id . "', `language_id` = '" . (int)$language_id . "', `image` = '" . $this->db->escape($value['image']) . "', `name` = '" . $this->db->escape($value['name']) . "', `description` = '" . $this->db->escape($value['description']) . "', `tag` = '" . $this->db->escape($value['tag']) . "', `meta_title` = '" . $this->db->escape($value['meta_title']) . "', `meta_description` = '" . $this->db->escape($value['meta_description']) . "', `meta_keyword` = '" . $this->db->escape($value['meta_keyword']) . "'");
|
||||
}
|
||||
|
||||
if (isset($data['article_store'])) {
|
||||
foreach ($data['article_store'] as $store_id) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "article_to_store` SET `article_id` = '" . (int)$article_id . "', `store_id` = '" . (int)$store_id . "'");
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($data['article_seo_url'] as $store_id => $language) {
|
||||
foreach ($language as $language_id => $keyword) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "seo_url` SET `store_id` = '" . (int)$store_id . "', `language_id` = '" . (int)$language_id . "', `key` = 'article_id', `value`= '" . (int)$article_id . "', `keyword` = '" . $this->db->escape($keyword) . "'");
|
||||
}
|
||||
}
|
||||
|
||||
// Set which layout to use with this article
|
||||
if (isset($data['article_layout'])) {
|
||||
foreach ($data['article_layout'] as $store_id => $layout_id) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "article_to_layout` SET `article_id` = '" . (int)$article_id . "', `store_id` = '" . (int)$store_id . "', `layout_id` = '" . (int)$layout_id . "'");
|
||||
}
|
||||
}
|
||||
|
||||
$this->cache->delete('article');
|
||||
|
||||
return $article_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $article_id
|
||||
* @param array $data
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function editArticle(int $article_id, array $data): void {
|
||||
$this->db->query("UPDATE `" . DB_PREFIX . "article` SET `topic_id` = '" . (int)$data['topic_id'] . "', `author` = '" . $this->db->escape($data['author']) . "', `status` = '" . (bool)(isset($data['status']) ? $data['status'] : 0) . "', `date_modified` = NOW() WHERE `article_id` = '" . (int)$article_id . "'");
|
||||
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "article_description` WHERE `article_id` = '" . (int)$article_id . "'");
|
||||
|
||||
foreach ($data['article_description'] as $language_id => $value) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "article_description` SET `article_id` = '" . (int)$article_id . "', `language_id` = '" . (int)$language_id . "', `image` = '" . $this->db->escape($value['image']) . "', `name` = '" . $this->db->escape($value['name']) . "', `description` = '" . $this->db->escape($value['description']) . "', `tag` = '" . $this->db->escape($value['tag']) . "', `meta_title` = '" . $this->db->escape($value['meta_title']) . "', `meta_description` = '" . $this->db->escape($value['meta_description']) . "', `meta_keyword` = '" . $this->db->escape($value['meta_keyword']) . "'");
|
||||
}
|
||||
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "article_to_store` WHERE `article_id` = '" . (int)$article_id . "'");
|
||||
|
||||
if (isset($data['article_store'])) {
|
||||
foreach ($data['article_store'] as $store_id) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "article_to_store` SET `article_id` = '" . (int)$article_id . "', `store_id` = '" . (int)$store_id . "'");
|
||||
}
|
||||
}
|
||||
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "seo_url` WHERE `key` = 'article_id' AND `value` = '" . (int)$article_id . "'");
|
||||
|
||||
foreach ($data['article_seo_url'] as $store_id => $language) {
|
||||
foreach ($language as $language_id => $keyword) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "seo_url` SET `store_id` = '" . (int)$store_id . "', `language_id` = '" . (int)$language_id . "', `key` = 'article_id', `value` = '" . (int)$article_id . "', `keyword` = '" . $this->db->escape($keyword) . "'");
|
||||
}
|
||||
}
|
||||
|
||||
// Layouts
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "article_to_layout` WHERE `article_id` = '" . (int)$article_id . "'");
|
||||
|
||||
if (isset($data['article_layout'])) {
|
||||
foreach ($data['article_layout'] as $store_id => $layout_id) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "article_to_layout` SET `article_id` = '" . (int)$article_id . "', `store_id` = '" . (int)$store_id . "', `layout_id` = '" . (int)$layout_id . "'");
|
||||
}
|
||||
}
|
||||
|
||||
$this->cache->delete('article');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $article_id
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function deleteArticle(int $article_id): void {
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "article` WHERE `article_id` = '" . (int)$article_id . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "article_comment` WHERE `article_id` = '" . (int)$article_id . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "article_description` WHERE `article_id` = '" . (int)$article_id . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "article_to_store` WHERE `article_id` = '" . (int)$article_id . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "article_to_layout` WHERE `article_id` = '" . (int)$article_id . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "seo_url` WHERE `key` = 'article_id' AND `value` = '" . (int)$article_id . "'");
|
||||
|
||||
$this->cache->delete('article');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $article_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getArticle(int $article_id): array {
|
||||
$sql = "SELECT DISTINCT * FROM `" . DB_PREFIX . "article` `a` LEFT JOIN `" . DB_PREFIX . "article_description` `ad` ON (`a`.`article_id` = `ad`.`article_id`) WHERE `a`.`article_id` = '" . (int)$article_id . "' AND `ad`.`language_id` = '" . (int)$this->config->get('config_language_id') . "'";
|
||||
|
||||
$article_data = $this->cache->get('article.'. md5($sql));
|
||||
|
||||
if (!$article_data) {
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
$article_data = $query->row;
|
||||
|
||||
$this->cache->set('article.'. md5($sql), $article_data);
|
||||
}
|
||||
|
||||
return $article_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getArticles(array $data = []): array {
|
||||
$sql = "SELECT * FROM `" . DB_PREFIX . "article` `a` LEFT JOIN `" . DB_PREFIX . "article_description` `ad` ON (`a`.`article_id` = `ad`.`article_id`) WHERE `ad`.`language_id` = '" . (int)$this->config->get('config_language_id') . "'";
|
||||
|
||||
if (!empty($data['filter_name'])) {
|
||||
$sql .= " AND `ad`.`name` LIKE '" . $this->db->escape((string)$data['filter_name']) . "'";
|
||||
}
|
||||
|
||||
$sort_data = [
|
||||
'ad.name',
|
||||
'a.date_added'
|
||||
];
|
||||
|
||||
if (isset($data['sort']) && in_array($data['sort'], $sort_data)) {
|
||||
$sql .= " ORDER BY " . $data['sort'];
|
||||
} else {
|
||||
$sql .= " ORDER BY `a`.`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'];
|
||||
}
|
||||
|
||||
$article_data = $this->cache->get('article.'. md5($sql));
|
||||
|
||||
if (!$article_data) {
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
$article_data = $query->rows;
|
||||
|
||||
$this->cache->set('article.'. md5($sql), $article_data);
|
||||
}
|
||||
|
||||
return $article_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $article_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getDescriptions(int $article_id): array {
|
||||
$article_description_data = [];
|
||||
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "article_description` WHERE `article_id` = '" . (int)$article_id . "'");
|
||||
|
||||
foreach ($query->rows as $result) {
|
||||
$article_description_data[$result['language_id']] = [
|
||||
'image' => $result['image'],
|
||||
'name' => $result['name'],
|
||||
'description' => $result['description'],
|
||||
'tag' => $result['tag'],
|
||||
'meta_title' => $result['meta_title'],
|
||||
'meta_description' => $result['meta_description'],
|
||||
'meta_keyword' => $result['meta_keyword']
|
||||
];
|
||||
}
|
||||
|
||||
return $article_description_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $article_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getSeoUrls(int $article_id): array {
|
||||
$article_seo_url_data = [];
|
||||
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "seo_url` WHERE `key` = 'article_id' AND `value` = '" . (int)$article_id . "'");
|
||||
|
||||
foreach ($query->rows as $result) {
|
||||
$article_seo_url_data[$result['store_id']][$result['language_id']] = $result['keyword'];
|
||||
}
|
||||
|
||||
return $article_seo_url_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $article_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getStores(int $article_id): array {
|
||||
$article_store_data = [];
|
||||
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "article_to_store` WHERE `article_id` = '" . (int)$article_id . "'");
|
||||
|
||||
foreach ($query->rows as $result) {
|
||||
$article_store_data[] = $result['store_id'];
|
||||
}
|
||||
|
||||
return $article_store_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $article_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getLayouts(int $article_id): array {
|
||||
$article_layout_data = [];
|
||||
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "article_to_layout` WHERE `article_id` = '" . (int)$article_id . "'");
|
||||
|
||||
foreach ($query->rows as $result) {
|
||||
$article_layout_data[$result['store_id']] = $result['layout_id'];
|
||||
}
|
||||
|
||||
return $article_layout_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalArticles(): int {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "article`");
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $layout_id
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalArticlesByLayoutId(int $layout_id): int {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "article_to_layout` WHERE `layout_id` = '" . (int)$layout_id . "'");
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $article_comment_id
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function deleteComment(int $article_comment_id): void {
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "article_comment` WHERE `article_comment_id` = '" . (int)$article_comment_id . "'");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $customer_id
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function deleteCommentsByCustomerId(int $customer_id): void {
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "article_comment` WHERE `customer_id` = '" . (int)$customer_id . "'");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $article_comment_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getComment(int $article_comment_id): array {
|
||||
$query = $this->db->query("SELECT DISTINCT * FROM `" . DB_PREFIX . "article_comment` WHERE `article_comment_id` = '" . (int)$article_comment_id . "'");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getComments(array $data = []): array {
|
||||
$sql = "SELECT * FROM `" . DB_PREFIX . "article_comment`";
|
||||
|
||||
$implode = [];
|
||||
|
||||
if (!empty($data['filter_keyword'])) {
|
||||
$implode[] = "LCASE(`comment`) LIKE '" . $this->db->escape('%' . (string)$data['filter_keyword'] . '%') . "'";
|
||||
}
|
||||
|
||||
if ($implode) {
|
||||
$sql .= " WHERE " . implode(" AND ", $implode);
|
||||
}
|
||||
|
||||
$sql .= " ORDER BY `date_added` DESC";
|
||||
|
||||
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 getTotalComments(array $data = []): int {
|
||||
$sql = "SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "article_comment`";
|
||||
|
||||
$implode = [];
|
||||
|
||||
if (!empty($data['filter_keyword'])) {
|
||||
$implode[] = "LCASE(`comment`) LIKE '" . $this->db->escape('%' . (string)$data['filter_keyword'] . '%') . "'";
|
||||
}
|
||||
|
||||
if ($implode) {
|
||||
$sql .= " WHERE " . implode(" AND ", $implode);
|
||||
}
|
||||
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
}
|
225
admininistrator/model/cms/topic.php
Normal file
225
admininistrator/model/cms/topic.php
Normal file
@ -0,0 +1,225 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Model\Cms;
|
||||
/**
|
||||
* Class Topic
|
||||
*
|
||||
* @package Opencart\Admin\Model\Cms
|
||||
*/
|
||||
class Topic extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return int $topic
|
||||
*/
|
||||
public function addTopic(array $data): int {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "topic` SET `sort_order` = '" . (int)$data['sort_order'] . "', `status` = '" . (bool)(isset($data['status']) ? $data['status'] : 0) . "'");
|
||||
|
||||
$topic_id = $this->db->getLastId();
|
||||
|
||||
foreach ($data['topic_description'] as $language_id => $value) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "topic_description` SET `topic_id` = '" . (int)$topic_id . "', `language_id` = '" . (int)$language_id . "', `image` = '" . $this->db->escape((string)$value['image']) . "', `name` = '" . $this->db->escape($value['name']) . "', `description` = '" . $this->db->escape($value['description']) . "', `meta_title` = '" . $this->db->escape($value['meta_title']) . "', `meta_description` = '" . $this->db->escape($value['meta_description']) . "', `meta_keyword` = '" . $this->db->escape($value['meta_keyword']) . "'");
|
||||
}
|
||||
|
||||
if (isset($data['topic_store'])) {
|
||||
foreach ($data['topic_store'] as $store_id) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "topic_to_store` SET `topic_id` = '" . (int)$topic_id . "', `store_id` = '" . (int)$store_id . "'");
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($data['topic_seo_url'] as $store_id => $language) {
|
||||
foreach ($language as $language_id => $keyword) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "seo_url` SET `store_id` = '" . (int)$store_id . "', `language_id` = '" . (int)$language_id . "', `key` = 'topic_id', `value`= '" . (int)$topic_id . "', `keyword` = '" . $this->db->escape($keyword) . "'");
|
||||
}
|
||||
}
|
||||
|
||||
$this->cache->delete('topic');
|
||||
|
||||
return $topic_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $topic_id
|
||||
* @param array $data
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function editTopic(int $topic_id, array $data): void {
|
||||
$this->db->query("UPDATE `" . DB_PREFIX . "topic` SET `sort_order` = '" . (int)$data['sort_order'] . "', `status` = '" . (bool)(isset($data['status']) ? $data['status'] : 0) . "' WHERE `topic_id` = '" . (int)$topic_id . "'");
|
||||
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "topic_description` WHERE `topic_id` = '" . (int)$topic_id . "'");
|
||||
|
||||
foreach ($data['topic_description'] as $language_id => $value) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "topic_description` SET `topic_id` = '" . (int)$topic_id . "', `language_id` = '" . (int)$language_id . "', `image` = '" . $this->db->escape((string)$value['image']) . "', `name` = '" . $this->db->escape($value['name']) . "', `description` = '" . $this->db->escape($value['description']) . "', `meta_title` = '" . $this->db->escape($value['meta_title']) . "', `meta_description` = '" . $this->db->escape($value['meta_description']) . "', `meta_keyword` = '" . $this->db->escape($value['meta_keyword']) . "'");
|
||||
}
|
||||
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "topic_to_store` WHERE `topic_id` = '" . (int)$topic_id . "'");
|
||||
|
||||
if (isset($data['topic_store'])) {
|
||||
foreach ($data['topic_store'] as $store_id) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "topic_to_store` SET `topic_id` = '" . (int)$topic_id . "', `store_id` = '" . (int)$store_id . "'");
|
||||
}
|
||||
}
|
||||
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "seo_url` WHERE `key` = 'topic_id' AND `value` = '" . (int)$topic_id . "'");
|
||||
|
||||
foreach ($data['topic_seo_url'] as $store_id => $language) {
|
||||
foreach ($language as $language_id => $keyword) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "seo_url` SET `store_id` = '" . (int)$store_id . "', `language_id` = '" . (int)$language_id . "', `key` = 'topic_id', `value` = '" . (int)$topic_id . "', `keyword` = '" . $this->db->escape($keyword) . "'");
|
||||
}
|
||||
}
|
||||
|
||||
$this->cache->delete('topic');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $topic_id
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function deleteTopic(int $topic_id): void {
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "topic` WHERE `topic_id` = '" . (int)$topic_id . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "topic_description` WHERE `topic_id` = '" . (int)$topic_id . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "topic_to_store` WHERE `topic_id` = '" . (int)$topic_id . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "seo_url` WHERE `key` = 'topic_id' AND `value` = '" . (int)$topic_id . "'");
|
||||
|
||||
$this->cache->delete('topic');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $topic_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getTopic(int $topic_id): array {
|
||||
$sql = "SELECT DISTINCT * FROM `" . DB_PREFIX . "topic` `t` LEFT JOIN `" . DB_PREFIX . "topic_description` `td` ON (`t`.`topic_id` = `td`.`topic_id`) WHERE `t`.`topic_id` = '" . (int)$topic_id . "' AND `td`.`language_id` = '" . (int)$this->config->get('config_language_id') . "'";
|
||||
|
||||
$topic_data = $this->cache->get('topic.'. md5($sql));
|
||||
|
||||
if (!$topic_data) {
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
$topic_data = $query->row;
|
||||
|
||||
$this->cache->set('topic.'. md5($sql), $topic_data);
|
||||
}
|
||||
|
||||
return $topic_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getTopics(array $data = []): array {
|
||||
$sql = "SELECT * FROM `" . DB_PREFIX . "topic` `t` LEFT JOIN `" . DB_PREFIX . "topic_description` `td` ON (`t`.`topic_id` = `td`.`topic_id`) WHERE `td`.`language_id` = '" . (int)$this->config->get('config_language_id') . "'";
|
||||
|
||||
$sort_data = [
|
||||
'td.name',
|
||||
't.sort_order'
|
||||
];
|
||||
|
||||
if (isset($data['sort']) && in_array($data['sort'], $sort_data)) {
|
||||
$sql .= " ORDER BY " . $data['sort'];
|
||||
} else {
|
||||
$sql .= " ORDER BY `t`.`sort_order`";
|
||||
}
|
||||
|
||||
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'];
|
||||
}
|
||||
|
||||
$topic_data = $this->cache->get('topic.'. md5($sql));
|
||||
|
||||
if (!$topic_data) {
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
$topic_data = $query->rows;
|
||||
|
||||
$this->cache->set('topic.'. md5($sql), $topic_data);
|
||||
}
|
||||
|
||||
return $topic_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $topic_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getDescriptions(int $topic_id): array {
|
||||
$topic_description_data = [];
|
||||
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "topic_description` WHERE `topic_id` = '" . (int)$topic_id . "'");
|
||||
|
||||
foreach ($query->rows as $result) {
|
||||
$topic_description_data[$result['language_id']] = [
|
||||
'image' => $result['image'],
|
||||
'name' => $result['name'],
|
||||
'description' => $result['description'],
|
||||
'meta_title' => $result['meta_title'],
|
||||
'meta_description' => $result['meta_description'],
|
||||
'meta_keyword' => $result['meta_keyword']
|
||||
];
|
||||
}
|
||||
|
||||
return $topic_description_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $topic_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getSeoUrls(int $topic_id): array {
|
||||
$topic_seo_url_data = [];
|
||||
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "seo_url` WHERE `key` = 'topic_id' AND `value` = '" . (int)$topic_id . "'");
|
||||
|
||||
foreach ($query->rows as $result) {
|
||||
$topic_seo_url_data[$result['store_id']][$result['language_id']] = $result['keyword'];
|
||||
}
|
||||
|
||||
return $topic_seo_url_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $topic_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getStores(int $topic_id): array {
|
||||
$topic_store_data = [];
|
||||
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "topic_to_store` WHERE `topic_id` = '" . (int)$topic_id . "'");
|
||||
|
||||
foreach ($query->rows as $result) {
|
||||
$topic_store_data[] = $result['store_id'];
|
||||
}
|
||||
|
||||
return $topic_store_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalTopics(): int {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "topic`");
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
}
|
276
admininistrator/model/customer/custom_field.php
Normal file
276
admininistrator/model/customer/custom_field.php
Normal file
@ -0,0 +1,276 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Model\Customer;
|
||||
/**
|
||||
* Class Custom Field
|
||||
*
|
||||
* @package Opencart\Admin\Model\Customer
|
||||
*/
|
||||
class CustomField extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function addCustomField(array $data): int {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "custom_field` SET `type` = '" . $this->db->escape((string)$data['type']) . "', `value` = '" . $this->db->escape((string)$data['value']) . "', `validation` = '" . $this->db->escape((string)$data['validation']) . "', `location` = '" . $this->db->escape((string)$data['location']) . "', `status` = '" . (bool)(isset($data['status']) ? $data['status'] : 0) . "', `sort_order` = '" . (int)$data['sort_order'] . "'");
|
||||
|
||||
$custom_field_id = $this->db->getLastId();
|
||||
|
||||
foreach ($data['custom_field_description'] as $language_id => $value) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "custom_field_description` SET `custom_field_id` = '" . (int)$custom_field_id . "', `language_id` = '" . (int)$language_id . "', `name` = '" . $this->db->escape($value['name']) . "'");
|
||||
}
|
||||
|
||||
if (isset($data['custom_field_customer_group'])) {
|
||||
foreach ($data['custom_field_customer_group'] as $custom_field_customer_group) {
|
||||
if (isset($custom_field_customer_group['customer_group_id'])) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "custom_field_customer_group` SET `custom_field_id` = '" . (int)$custom_field_id . "', `customer_group_id` = '" . (int)$custom_field_customer_group['customer_group_id'] . "', `required` = '" . (int)(isset($custom_field_customer_group['required']) ? 1 : 0) . "'");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($data['custom_field_value'])) {
|
||||
foreach ($data['custom_field_value'] as $custom_field_value) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "custom_field_value` SET `custom_field_id` = '" . (int)$custom_field_id . "', `sort_order` = '" . (int)$custom_field_value['sort_order'] . "'");
|
||||
|
||||
$custom_field_value_id = $this->db->getLastId();
|
||||
|
||||
foreach ($custom_field_value['custom_field_value_description'] as $language_id => $custom_field_value_description) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "custom_field_value_description` SET `custom_field_value_id` = '" . (int)$custom_field_value_id . "', `language_id` = '" . (int)$language_id . "', `custom_field_id` = '" . (int)$custom_field_id . "', `name` = '" . $this->db->escape($custom_field_value_description['name']) . "'");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $custom_field_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $custom_field_id
|
||||
* @param array $data
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function editCustomField(int $custom_field_id, array $data): void {
|
||||
$this->db->query("UPDATE `" . DB_PREFIX . "custom_field` SET `type` = '" . $this->db->escape((string)$data['type']) . "', `value` = '" . $this->db->escape((string)$data['value']) . "', `validation` = '" . $this->db->escape((string)$data['validation']) . "', `location` = '" . $this->db->escape((string)$data['location']) . "', `status` = '" . (bool)(isset($data['status']) ? $data['status'] : 0) . "', `sort_order` = '" . (int)$data['sort_order'] . "' WHERE `custom_field_id` = '" . (int)$custom_field_id . "'");
|
||||
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "custom_field_description` WHERE `custom_field_id` = '" . (int)$custom_field_id . "'");
|
||||
|
||||
foreach ($data['custom_field_description'] as $language_id => $value) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "custom_field_description` SET `custom_field_id` = '" . (int)$custom_field_id . "', `language_id` = '" . (int)$language_id . "', `name` = '" . $this->db->escape($value['name']) . "'");
|
||||
}
|
||||
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "custom_field_customer_group` WHERE `custom_field_id` = '" . (int)$custom_field_id . "'");
|
||||
|
||||
if (isset($data['custom_field_customer_group'])) {
|
||||
foreach ($data['custom_field_customer_group'] as $custom_field_customer_group) {
|
||||
if (isset($custom_field_customer_group['customer_group_id'])) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "custom_field_customer_group` SET `custom_field_id` = '" . (int)$custom_field_id . "', `customer_group_id` = '" . (int)$custom_field_customer_group['customer_group_id'] . "', `required` = '" . (int)(isset($custom_field_customer_group['required']) ? 1 : 0) . "'");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "custom_field_value` WHERE `custom_field_id` = '" . (int)$custom_field_id . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "custom_field_value_description` WHERE `custom_field_id` = '" . (int)$custom_field_id . "'");
|
||||
|
||||
if (isset($data['custom_field_value'])) {
|
||||
foreach ($data['custom_field_value'] as $custom_field_value) {
|
||||
if ($custom_field_value['custom_field_value_id']) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "custom_field_value` SET `custom_field_value_id` = '" . (int)$custom_field_value['custom_field_value_id'] . "', `custom_field_id` = '" . (int)$custom_field_id . "', `sort_order` = '" . (int)$custom_field_value['sort_order'] . "'");
|
||||
} else {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "custom_field_value` SET `custom_field_id` = '" . (int)$custom_field_id . "', `sort_order` = '" . (int)$custom_field_value['sort_order'] . "'");
|
||||
}
|
||||
|
||||
$custom_field_value_id = $this->db->getLastId();
|
||||
|
||||
foreach ($custom_field_value['custom_field_value_description'] as $language_id => $custom_field_value_description) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "custom_field_value_description` SET `custom_field_value_id` = '" . (int)$custom_field_value_id . "', `language_id` = '" . (int)$language_id . "', `custom_field_id` = '" . (int)$custom_field_id . "', `name` = '" . $this->db->escape($custom_field_value_description['name']) . "'");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $custom_field_id
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function deleteCustomField(int $custom_field_id): void {
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "custom_field` WHERE `custom_field_id` = '" . (int)$custom_field_id . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "custom_field_description` WHERE `custom_field_id` = '" . (int)$custom_field_id . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "custom_field_customer_group` WHERE `custom_field_id` = '" . (int)$custom_field_id . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "custom_field_value` WHERE `custom_field_id` = '" . (int)$custom_field_id . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "custom_field_value_description` WHERE `custom_field_id` = '" . (int)$custom_field_id . "'");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $custom_field_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getCustomField(int $custom_field_id): array {
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "custom_field` cf LEFT JOIN `" . DB_PREFIX . "custom_field_description` cfd ON (cf.`custom_field_id` = cfd.`custom_field_id`) WHERE cf.`custom_field_id` = '" . (int)$custom_field_id . "' AND cfd.`language_id` = '" . (int)$this->config->get('config_language_id') . "'");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getCustomFields(array $data = []): array {
|
||||
if (empty($data['filter_customer_group_id'])) {
|
||||
$sql = "SELECT * FROM `" . DB_PREFIX . "custom_field` cf LEFT JOIN `" . DB_PREFIX . "custom_field_description` cfd ON (cf.`custom_field_id` = cfd.`custom_field_id`) WHERE cfd.`language_id` = '" . (int)$this->config->get('config_language_id') . "'";
|
||||
} else {
|
||||
$sql = "SELECT * FROM `" . DB_PREFIX . "custom_field_customer_group` cfcg LEFT JOIN `" . DB_PREFIX . "custom_field` cf ON (cfcg.`custom_field_id` = cf.`custom_field_id`) LEFT JOIN `" . DB_PREFIX . "custom_field_description` cfd ON (cf.`custom_field_id` = cfd.`custom_field_id`) WHERE cfd.`language_id` = '" . (int)$this->config->get('config_language_id') . "'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_name'])) {
|
||||
$sql .= " AND cfd.`name` LIKE '" . $this->db->escape((string)$data['filter_name'] . '%') . "'";
|
||||
}
|
||||
|
||||
if (isset($data['filter_status'])) {
|
||||
$sql .= " AND cf.`status` = '" . (int)$data['filter_status'] . "'";
|
||||
}
|
||||
|
||||
if (isset($data['filter_location'])) {
|
||||
$sql .= " AND cf.`location` = '" . $this->db->escape((string)$data['filter_location']) . "'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_customer_group_id'])) {
|
||||
$sql .= " AND cfcg.`customer_group_id` = '" . (int)$data['filter_customer_group_id'] . "'";
|
||||
}
|
||||
|
||||
$sort_data = [
|
||||
'cfd.name',
|
||||
'cf.type',
|
||||
'cf.location',
|
||||
'cf.status',
|
||||
'cf.sort_order'
|
||||
];
|
||||
|
||||
if (isset($data['sort']) && in_array($data['sort'], $sort_data)) {
|
||||
$sql .= " ORDER BY " . $data['sort'];
|
||||
} else {
|
||||
$sql .= " ORDER BY cfd.`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'];
|
||||
}
|
||||
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
return $query->rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $custom_field_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getDescriptions(int $custom_field_id): array {
|
||||
$custom_field_data = [];
|
||||
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "custom_field_description` WHERE `custom_field_id` = '" . (int)$custom_field_id . "'");
|
||||
|
||||
foreach ($query->rows as $result) {
|
||||
$custom_field_data[$result['language_id']] = ['name' => $result['name']];
|
||||
}
|
||||
|
||||
return $custom_field_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $custom_field_value_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getValue(int $custom_field_value_id): array {
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "custom_field_value` cfv LEFT JOIN `" . DB_PREFIX . "custom_field_value_description` cfvd ON (cfv.`custom_field_value_id` = cfvd.`custom_field_value_id`) WHERE cfv.`custom_field_value_id` = '" . (int)$custom_field_value_id . "' AND cfvd.`language_id` = '" . (int)$this->config->get('config_language_id') . "'");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $custom_field_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getValues(int $custom_field_id): array {
|
||||
$custom_field_value_data = [];
|
||||
|
||||
$custom_field_value_query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "custom_field_value` cfv LEFT JOIN `" . DB_PREFIX . "custom_field_value_description` cfvd ON (cfv.`custom_field_value_id` = cfvd.`custom_field_value_id`) WHERE cfv.`custom_field_id` = '" . (int)$custom_field_id . "' AND cfvd.`language_id` = '" . (int)$this->config->get('config_language_id') . "' ORDER BY cfv.`sort_order` ASC");
|
||||
|
||||
foreach ($custom_field_value_query->rows as $custom_field_value) {
|
||||
$custom_field_value_data[$custom_field_value['custom_field_value_id']] = [
|
||||
'custom_field_value_id' => $custom_field_value['custom_field_value_id'],
|
||||
'name' => $custom_field_value['name']
|
||||
];
|
||||
}
|
||||
|
||||
return $custom_field_value_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $custom_field_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getCustomerGroups(int $custom_field_id): array {
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "custom_field_customer_group` WHERE `custom_field_id` = '" . (int)$custom_field_id . "'");
|
||||
|
||||
return $query->rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $custom_field_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getValueDescriptions(int $custom_field_id): array {
|
||||
$custom_field_value_data = [];
|
||||
|
||||
$custom_field_value_query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "custom_field_value` WHERE `custom_field_id` = '" . (int)$custom_field_id . "'");
|
||||
|
||||
foreach ($custom_field_value_query->rows as $custom_field_value) {
|
||||
$custom_field_value_description_data = [];
|
||||
|
||||
$custom_field_value_description_query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "custom_field_value_description` WHERE `custom_field_value_id` = '" . (int)$custom_field_value['custom_field_value_id'] . "'");
|
||||
|
||||
foreach ($custom_field_value_description_query->rows as $custom_field_value_description) {
|
||||
$custom_field_value_description_data[$custom_field_value_description['language_id']] = ['name' => $custom_field_value_description['name']];
|
||||
}
|
||||
|
||||
$custom_field_value_data[] = [
|
||||
'custom_field_value_id' => $custom_field_value['custom_field_value_id'],
|
||||
'custom_field_value_description' => $custom_field_value_description_data,
|
||||
'sort_order' => $custom_field_value['sort_order']
|
||||
];
|
||||
}
|
||||
|
||||
return $custom_field_value_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalCustomFields(): int {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "custom_field`");
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
}
|
613
admininistrator/model/customer/customer.php
Normal file
613
admininistrator/model/customer/customer.php
Normal file
@ -0,0 +1,613 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Model\Customer;
|
||||
/**
|
||||
* Class Customer
|
||||
*
|
||||
* @package Opencart\Admin\Model\Customer
|
||||
*/
|
||||
class Customer extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function addCustomer(array $data): int {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "customer` SET `store_id` = '" . (int)$data['store_id'] . "', `customer_group_id` = '" . (int)$data['customer_group_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']) . "', `custom_field` = '" . $this->db->escape(isset($data['custom_field']) ? json_encode($data['custom_field']) : json_encode([])) . "', `newsletter` = '" . (isset($data['newsletter']) ? (bool)$data['newsletter'] : 0) . "', `password` = '" . $this->db->escape(password_hash(html_entity_decode($data['password'], ENT_QUOTES, 'UTF-8'), PASSWORD_DEFAULT)) . "', `status` = '" . (isset($data['status']) ? (bool)$data['status'] : 0) . "', `safe` = '" . (isset($data['safe']) ? (bool)$data['safe'] : 0) . "', `date_added` = NOW()");
|
||||
|
||||
$customer_id = $this->db->getLastId();
|
||||
|
||||
if (isset($data['address'])) {
|
||||
foreach ($data['address'] as $address) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "address` SET `customer_id` = '" . (int)$customer_id . "', `firstname` = '" . $this->db->escape($address['firstname']) . "', `lastname` = '" . $this->db->escape($address['lastname']) . "', `company` = '" . $this->db->escape($address['company']) . "', `address_1` = '" . $this->db->escape($address['address_1']) . "', `address_2` = '" . $this->db->escape($address['address_2']) . "', `city` = '" . $this->db->escape($address['city']) . "', `postcode` = '" . $this->db->escape($address['postcode']) . "', `country_id` = '" . (int)$address['country_id'] . "', `zone_id` = '" . (int)$address['zone_id'] . "', `custom_field` = '" . $this->db->escape(isset($address['custom_field']) ? json_encode($address['custom_field']) : json_encode([])) . "', `default` = '" . (isset($address['default']) ? (int)$address['default'] : 0) . "'");
|
||||
}
|
||||
}
|
||||
|
||||
return $customer_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $customer_id
|
||||
* @param array $data
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function editCustomer(int $customer_id, array $data): void {
|
||||
$this->db->query("UPDATE `" . DB_PREFIX . "customer` SET `store_id` = '" . (int)$data['store_id'] . "', `customer_group_id` = '" . (int)$data['customer_group_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']) . "', `custom_field` = '" . $this->db->escape(isset($data['custom_field']) ? json_encode($data['custom_field']) : json_encode([])) . "', `newsletter` = '" . (isset($data['newsletter']) ? (bool)$data['newsletter'] : 0) . "', `status` = '" . (isset($data['status']) ? (bool)$data['status'] : 0) . "', `safe` = '" . (isset($data['safe']) ? (bool)$data['safe'] : 0) . "' WHERE `customer_id` = '" . (int)$customer_id . "'");
|
||||
|
||||
if ($data['password']) {
|
||||
$this->db->query("UPDATE `" . DB_PREFIX . "customer` SET `password` = '" . $this->db->escape(password_hash(html_entity_decode($data['password'], ENT_QUOTES, 'UTF-8'), PASSWORD_DEFAULT)) . "' WHERE `customer_id` = '" . (int)$customer_id . "'");
|
||||
}
|
||||
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "address` WHERE `customer_id` = '" . (int)$customer_id . "'");
|
||||
|
||||
if (isset($data['address'])) {
|
||||
foreach ($data['address'] as $address) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "address` SET `address_id` = '" . (int)$address['address_id'] . "', `customer_id` = '" . (int)$customer_id . "', `firstname` = '" . $this->db->escape($address['firstname']) . "', `lastname` = '" . $this->db->escape($address['lastname']) . "', `company` = '" . $this->db->escape($address['company']) . "', `address_1` = '" . $this->db->escape($address['address_1']) . "', `address_2` = '" . $this->db->escape($address['address_2']) . "', `city` = '" . $this->db->escape($address['city']) . "', `postcode` = '" . $this->db->escape($address['postcode']) . "', `country_id` = '" . (int)$address['country_id'] . "', `zone_id` = '" . (int)$address['zone_id'] . "', `custom_field` = '" . $this->db->escape(isset($address['custom_field']) ? json_encode($address['custom_field']) : json_encode([])) . "', `default` = '" . (isset($address['default']) ? (int)$address['default'] : 0) . "'");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $customer_id
|
||||
* @param string $token
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function editToken(int $customer_id, string $token): void {
|
||||
$this->db->query("UPDATE `" . DB_PREFIX . "customer` SET `token` = '" . $this->db->escape($token) . "' WHERE `customer_id` = '" . (int)$customer_id . "'");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $customer_id
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function deleteCustomer(int $customer_id): void {
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "customer` WHERE `customer_id` = '" . (int)$customer_id . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "customer_activity` WHERE `customer_id` = '" . (int)$customer_id . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "customer_affiliate` WHERE `customer_id` = '" . (int)$customer_id . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "customer_affiliate_report` WHERE `customer_id` = '" . (int)$customer_id . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "customer_approval` WHERE `customer_id` = '" . (int)$customer_id . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "customer_history` WHERE `customer_id` = '" . (int)$customer_id . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "customer_reward` WHERE `customer_id` = '" . (int)$customer_id . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "customer_transaction` WHERE `customer_id` = '" . (int)$customer_id . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "customer_wishlist` WHERE `customer_id` = '" . (int)$customer_id . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "customer_ip` WHERE `customer_id` = '" . (int)$customer_id . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "address` WHERE `customer_id` = '" . (int)$customer_id . "'");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $customer_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getCustomer(int $customer_id): array {
|
||||
$query = $this->db->query("SELECT DISTINCT * FROM `" . DB_PREFIX . "customer` WHERE `customer_id` = '" . (int)$customer_id . "'");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $email
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getCustomerByEmail(string $email): array {
|
||||
$query = $this->db->query("SELECT DISTINCT * FROM `" . DB_PREFIX . "customer` WHERE LCASE(`email`) = '" . $this->db->escape(oc_strtolower($email)) . "'");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getCustomers(array $data = []): array {
|
||||
$sql = "SELECT *, CONCAT(c.`firstname`, ' ', c.`lastname`) AS `name`, cgd.`name` AS `customer_group` FROM `" . DB_PREFIX . "customer` c LEFT JOIN `" . DB_PREFIX . "customer_group_description` cgd ON (c.`customer_group_id` = cgd.`customer_group_id`)";
|
||||
|
||||
$sql .= " WHERE cgd.`language_id` = '" . (int)$this->config->get('config_language_id') . "'";
|
||||
|
||||
if (!empty($data['filter_name'])) {
|
||||
$sql .= " AND CONCAT(c.`firstname`, ' ', c.`lastname`) LIKE '" . $this->db->escape('%' . (string)$data['filter_name'] . '%') . "'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_email'])) {
|
||||
$sql .= " AND c.`email` LIKE '" . $this->db->escape((string)$data['filter_email'] . '%') . "'";
|
||||
}
|
||||
|
||||
if (isset($data['filter_newsletter']) && $data['filter_newsletter'] !== '') {
|
||||
$sql .= " AND c.`newsletter` = '" . (int)$data['filter_newsletter'] . "'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_customer_group_id'])) {
|
||||
$sql .= " AND c.`customer_group_id` = '" . (int)$data['filter_customer_group_id'] . "'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_ip'])) {
|
||||
$sql .= " AND c.`customer_id` IN (SELECT `customer_id` FROM `" . DB_PREFIX . "customer_ip` WHERE `ip` = '" . $this->db->escape((string)$data['filter_ip']) . "')";
|
||||
}
|
||||
|
||||
if (isset($data['filter_status']) && $data['filter_status'] !== '') {
|
||||
$sql .= " AND c.`status` = '" . (int)$data['filter_status'] . "'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_date_from'])) {
|
||||
$sql .= " AND DATE(c.`date_added`) >= DATE('" . $this->db->escape((string)$data['filter_date_from']) . "')";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_date_to'])) {
|
||||
$sql .= " AND DATE(c.`date_added`) <= DATE('" . $this->db->escape((string)$data['filter_date_to']) . "')";
|
||||
}
|
||||
|
||||
$sort_data = [
|
||||
'name',
|
||||
'c.email',
|
||||
'customer_group',
|
||||
'c.status',
|
||||
'c.ip',
|
||||
'c.date_added'
|
||||
];
|
||||
|
||||
if (isset($data['sort']) && in_array($data['sort'], $sort_data)) {
|
||||
$sql .= " ORDER BY " . $data['sort'];
|
||||
} else {
|
||||
$sql .= " ORDER BY 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'];
|
||||
}
|
||||
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
return $query->rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalCustomers(array $data = []): int {
|
||||
$sql = "SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "customer` c";
|
||||
|
||||
$implode = [];
|
||||
|
||||
if (!empty($data['filter_name'])) {
|
||||
$implode[] = "CONCAT(c.`firstname`, ' ', c.`lastname`) LIKE '" . $this->db->escape('%' . (string)$data['filter_name'] . '%') . "'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_email'])) {
|
||||
$implode[] = "c.`email` LIKE '" . $this->db->escape((string)$data['filter_email'] . '%') . "'";
|
||||
}
|
||||
|
||||
if (isset($data['filter_newsletter']) && $data['filter_newsletter'] !== '') {
|
||||
$implode[] = "c.`newsletter` = '" . (int)$data['filter_newsletter'] . "'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_customer_group_id'])) {
|
||||
$implode[] = "c.`customer_group_id` = '" . (int)$data['filter_customer_group_id'] . "'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_ip'])) {
|
||||
$implode[] = "c.`customer_id` IN (SELECT `customer_id` FROM " . DB_PREFIX . "customer_ip WHERE `ip` = '" . $this->db->escape((string)$data['filter_ip']) . "')";
|
||||
}
|
||||
|
||||
if (isset($data['filter_status']) && $data['filter_status'] !== '') {
|
||||
$implode[] = "c.`status` = '" . (int)$data['filter_status'] . "'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_date_from'])) {
|
||||
$implode[] = "DATE(c.`date_added`) >= DATE('" . $this->db->escape((string)$data['filter_date_from']) . "')";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_date_to'])) {
|
||||
$implode[] = "DATE(c.`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 $address_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getAddress(int $address_id): array {
|
||||
$address_query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "address` WHERE `address_id` = '" . (int)$address_id . "'");
|
||||
|
||||
if ($address_query->num_rows) {
|
||||
$country_query = $this->db->query("SELECT *, c.name FROM `" . DB_PREFIX . "country` c LEFT JOIN `" . DB_PREFIX . "address_format` af ON (c.`address_format_id` = af.`address_format_id`) WHERE `country_id` = '" . (int)$address_query->row['country_id'] . "'");
|
||||
|
||||
if ($country_query->num_rows) {
|
||||
$country = $country_query->row['name'];
|
||||
$iso_code_2 = $country_query->row['iso_code_2'];
|
||||
$iso_code_3 = $country_query->row['iso_code_3'];
|
||||
$address_format = $country_query->row['address_format'];
|
||||
} else {
|
||||
$country = '';
|
||||
$iso_code_2 = '';
|
||||
$iso_code_3 = '';
|
||||
$address_format = '';
|
||||
}
|
||||
|
||||
$zone_query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "zone` WHERE `zone_id` = '" . (int)$address_query->row['zone_id'] . "'");
|
||||
|
||||
if ($zone_query->num_rows) {
|
||||
$zone = $zone_query->row['name'];
|
||||
$zone_code = $zone_query->row['code'];
|
||||
} else {
|
||||
$zone = '';
|
||||
$zone_code = '';
|
||||
}
|
||||
|
||||
return [
|
||||
'address_id' => $address_query->row['address_id'],
|
||||
'customer_id' => $address_query->row['customer_id'],
|
||||
'firstname' => $address_query->row['firstname'],
|
||||
'lastname' => $address_query->row['lastname'],
|
||||
'company' => $address_query->row['company'],
|
||||
'address_1' => $address_query->row['address_1'],
|
||||
'address_2' => $address_query->row['address_2'],
|
||||
'postcode' => $address_query->row['postcode'],
|
||||
'city' => $address_query->row['city'],
|
||||
'zone_id' => $address_query->row['zone_id'],
|
||||
'zone' => $zone,
|
||||
'zone_code' => $zone_code,
|
||||
'country_id' => $address_query->row['country_id'],
|
||||
'country' => $country,
|
||||
'iso_code_2' => $iso_code_2,
|
||||
'iso_code_3' => $iso_code_3,
|
||||
'address_format' => $address_format,
|
||||
'custom_field' => json_decode($address_query->row['custom_field'], true),
|
||||
'default' => $address_query->row['default']
|
||||
];
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $customer_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getAddresses(int $customer_id): array {
|
||||
$address_data = [];
|
||||
|
||||
$query = $this->db->query("SELECT `address_id` FROM `" . DB_PREFIX . "address` WHERE `customer_id` = '" . (int)$customer_id . "'");
|
||||
|
||||
foreach ($query->rows as $result) {
|
||||
$address_info = $this->getAddress($result['address_id']);
|
||||
|
||||
if ($address_info) {
|
||||
$address_data[] = $address_info;
|
||||
}
|
||||
}
|
||||
|
||||
return $address_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $customer_id
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalAddressesByCustomerId(int $customer_id): int {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "address` WHERE `customer_id` = '" . (int)$customer_id . "'");
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $country_id
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalAddressesByCountryId(int $country_id): int {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "address` WHERE `country_id` = '" . (int)$country_id . "'");
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $zone_id
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalAddressesByZoneId(int $zone_id): int {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "address` WHERE `zone_id` = '" . (int)$zone_id . "'");
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $customer_group_id
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalCustomersByCustomerGroupId(int $customer_group_id): int {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "customer` WHERE `customer_group_id` = '" . (int)$customer_group_id . "'");
|
||||
|
||||
if ($query->num_rows) {
|
||||
return (int)$query->row['total'];
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $customer_id
|
||||
* @param string $comment
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function addHistory(int $customer_id, string $comment): void {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "customer_history` SET `customer_id` = '" . (int)$customer_id . "', `comment` = '" . $this->db->escape(strip_tags($comment)) . "', `date_added` = NOW()");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $customer_id
|
||||
* @param int $start
|
||||
* @param int $limit
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getHistories(int $customer_id, int $start = 0, int $limit = 10): array {
|
||||
if ($start < 0) {
|
||||
$start = 0;
|
||||
}
|
||||
|
||||
if ($limit < 1) {
|
||||
$limit = 10;
|
||||
}
|
||||
|
||||
$query = $this->db->query("SELECT `comment`, `date_added` FROM `" . DB_PREFIX . "customer_history` WHERE `customer_id` = '" . (int)$customer_id . "' ORDER BY `date_added` DESC LIMIT " . (int)$start . "," . (int)$limit);
|
||||
|
||||
return $query->rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $customer_id
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalHistories(int $customer_id): int {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "customer_history` WHERE `customer_id` = '" . (int)$customer_id . "'");
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $customer_id
|
||||
* @param string $description
|
||||
* @param float $amount
|
||||
* @param int $order_id
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function addTransaction(int $customer_id, string $description = '', float $amount = 0, int $order_id = 0): void {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "customer_transaction` SET `customer_id` = '" . (int)$customer_id . "', `order_id` = '" . (int)$order_id . "', `description` = '" . $this->db->escape($description) . "', `amount` = '" . (float)$amount . "', `date_added` = NOW()");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $order_id
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function deleteTransactionByOrderId(int $order_id): void {
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "customer_transaction` WHERE `order_id` = '" . (int)$order_id . "'");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $customer_id
|
||||
* @param int $start
|
||||
* @param int $limit
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getTransactions(int $customer_id, int $start = 0, int $limit = 10): array {
|
||||
if ($start < 0) {
|
||||
$start = 0;
|
||||
}
|
||||
|
||||
if ($limit < 1) {
|
||||
$limit = 10;
|
||||
}
|
||||
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "customer_transaction` WHERE `customer_id` = '" . (int)$customer_id . "' ORDER BY `date_added` DESC LIMIT " . (int)$start . "," . (int)$limit);
|
||||
|
||||
return $query->rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $customer_id
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalTransactions(int $customer_id): int {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "customer_transaction` WHERE `customer_id` = '" . (int)$customer_id . "'");
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $customer_id
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public function getTransactionTotal(int $customer_id): float {
|
||||
$query = $this->db->query("SELECT SUM(`amount`) AS `total` FROM `" . DB_PREFIX . "customer_transaction` WHERE `customer_id` = '" . (int)$customer_id . "'");
|
||||
|
||||
return (float)$query->row['total'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $order_id
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalTransactionsByOrderId(int $order_id): int {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "customer_transaction` WHERE `order_id` = '" . (int)$order_id . "'");
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $customer_id
|
||||
* @param string $description
|
||||
* @param int $points
|
||||
* @param int $order_id
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function addReward(int $customer_id, string $description = '', int $points = 0, int $order_id = 0): void {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "customer_reward` SET `customer_id` = '" . (int)$customer_id . "', `order_id` = '" . (int)$order_id . "', `points` = '" . (int)$points . "', `description` = '" . $this->db->escape($description) . "', `date_added` = NOW()");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $order_id
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function deleteReward(int $order_id): void {
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "customer_reward` WHERE `order_id` = '" . (int)$order_id . "' AND `points` > '0'");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $customer_id
|
||||
* @param int $start
|
||||
* @param int $limit
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getRewards(int $customer_id, int $start = 0, int $limit = 10): array {
|
||||
if ($start < 0) {
|
||||
$start = 0;
|
||||
}
|
||||
|
||||
if ($limit < 1) {
|
||||
$limit = 10;
|
||||
}
|
||||
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "customer_reward` WHERE `customer_id` = '" . (int)$customer_id . "' ORDER BY `date_added` DESC LIMIT " . (int)$start . "," . (int)$limit);
|
||||
|
||||
return $query->rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $customer_id
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalRewards(int $customer_id): int {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "customer_reward` WHERE `customer_id` = '" . (int)$customer_id . "'");
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $customer_id
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getRewardTotal(int $customer_id): int {
|
||||
$query = $this->db->query("SELECT SUM(points) AS `total` FROM `" . DB_PREFIX . "customer_reward` WHERE `customer_id` = '" . (int)$customer_id . "'");
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $order_id
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalRewardsByOrderId(int $order_id): int {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "customer_reward` WHERE `order_id` = '" . (int)$order_id . "' AND `points` > '0'");
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $customer_id
|
||||
* @param int $start
|
||||
* @param int $limit
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getIps(int $customer_id, int $start = 0, int $limit = 10): array {
|
||||
if ($start < 0) {
|
||||
$start = 0;
|
||||
}
|
||||
if ($limit < 1) {
|
||||
$limit = 10;
|
||||
}
|
||||
|
||||
$query = $this->db->query("SELECT `ip`, `store_id`, `country`, `date_added` FROM `" . DB_PREFIX . "customer_ip` WHERE `customer_id` = '" . (int)$customer_id . "' ORDER BY `date_added` DESC LIMIT " . (int)$start . "," . (int)$limit);
|
||||
|
||||
return $query->rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $customer_id
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalIps(int $customer_id): int {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "customer_ip` WHERE `customer_id` = '" . (int)$customer_id . "'");
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $ip
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalCustomersByIp(string $ip): int {
|
||||
$query = $this->db->query("SELECT COUNT(DISTINCT `customer_id`) AS `total` FROM `" . DB_PREFIX . "customer_ip` WHERE `ip` = '" . $this->db->escape($ip) . "'");
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $email
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getTotalLoginAttempts(string $email): array {
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "customer_login` WHERE `email` = '" . $this->db->escape(oc_strtolower($email)) . "'");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $email
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function deleteLoginAttempts(string $email): void {
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "customer_login` WHERE `email` = '" . $this->db->escape(oc_strtolower($email)) . "'");
|
||||
}
|
||||
}
|
151
admininistrator/model/customer/customer_approval.php
Normal file
151
admininistrator/model/customer/customer_approval.php
Normal file
@ -0,0 +1,151 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Model\Customer;
|
||||
/**
|
||||
* Class Customer Approval
|
||||
*
|
||||
* @package Opencart\Admin\Model\Customer
|
||||
*/
|
||||
class CustomerApproval extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getCustomerApprovals(array $data = []): array {
|
||||
$sql = "SELECT *, CONCAT(c.`firstname`, ' ', c.`lastname`) AS customer, cgd.`name` AS customer_group, ca.`type` FROM `" . DB_PREFIX . "customer_approval` ca LEFT JOIN `" . DB_PREFIX . "customer` c ON (ca.`customer_id` = c.`customer_id`) LEFT JOIN `" . DB_PREFIX . "customer_group_description` cgd ON (c.`customer_group_id` = cgd.`customer_group_id`) WHERE cgd.`language_id` = '" . (int)$this->config->get('config_language_id') . "'";
|
||||
|
||||
if (!empty($data['filter_customer'])) {
|
||||
$sql .= " AND CONCAT(c.`firstname`, ' ', c.`lastname`) LIKE '" . $this->db->escape('%' . (string)$data['filter_customer'] . '%') . "'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_email'])) {
|
||||
$sql .= " AND c.`email` LIKE '" . $this->db->escape((string)$data['filter_email'] . '%') . "'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_customer_group_id'])) {
|
||||
$sql .= " AND c.`customer_group_id` = '" . (int)$data['filter_customer_group_id'] . "'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_type'])) {
|
||||
$sql .= " AND ca.`type` = '" . $this->db->escape((string)$data['filter_type']) . "'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_date_from'])) {
|
||||
$sql .= " AND DATE(c.`date_added`) >= DATE('" . $this->db->escape((string)$data['filter_date_from']) . "')";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_date_to'])) {
|
||||
$sql .= " AND DATE(c.`date_added`) <= DATE('" . $this->db->escape((string)$data['filter_date_to']) . "')";
|
||||
}
|
||||
|
||||
$sql .= " ORDER BY c.`date_added` DESC";
|
||||
|
||||
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 $customer_approval_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getCustomerApproval(int $customer_approval_id): array {
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "customer_approval` WHERE `customer_approval_id` = '" . (int)$customer_approval_id . "'");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalCustomerApprovals(array $data = []): int {
|
||||
$sql = "SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "customer_approval` ca LEFT JOIN `" . DB_PREFIX . "customer` c ON (ca.`customer_id` = c.`customer_id`)";
|
||||
|
||||
$implode = [];
|
||||
|
||||
if (!empty($data['filter_customer'])) {
|
||||
$implode[] = "CONCAT(c.`firstname`, ' ', c.`lastname`) LIKE '" . $this->db->escape('%' . (string)$data['filter_customer'] . '%') . "'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_email'])) {
|
||||
$implode[] = "c.`email` LIKE '" . $this->db->escape((string)$data['filter_email'] . '%') . "'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_customer_group_id'])) {
|
||||
$implode[] = "c.`customer_group_id` = '" . (int)$data['filter_customer_group_id'] . "'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_type'])) {
|
||||
$implode[] = "ca.`type` = '" . $this->db->escape((string)$data['filter_type']) . "'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_date_from'])) {
|
||||
$implode[] = "DATE(c.`date_added`) >= DATE('" . $this->db->escape((string)$data['filter_date_from']) . "')";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_date_to'])) {
|
||||
$implode[] = "DATE(c.`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 $customer_id
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function approveCustomer(int $customer_id): void {
|
||||
$this->db->query("UPDATE `" . DB_PREFIX . "customer` SET `status` = '1' WHERE `customer_id` = '" . (int)$customer_id . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "customer_approval` WHERE `customer_id` = '" . (int)$customer_id . "' AND `type` = 'customer'");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $customer_id
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function denyCustomer(int $customer_id): void {
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "customer_approval` WHERE `customer_id` = '" . (int)$customer_id . "' AND `type` = 'customer'");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $customer_id
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function approveAffiliate(int $customer_id): void {
|
||||
$this->db->query("UPDATE `" . DB_PREFIX . "customer_affiliate` SET `status` = '1' WHERE `customer_id` = '" . (int)$customer_id . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "customer_approval` WHERE `customer_id` = '" . (int)$customer_id . "' AND `type` = 'affiliate'");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $customer_id
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function denyAffiliate(int $customer_id): void {
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "customer_approval` WHERE `customer_id` = '" . (int)$customer_id . "' AND `type` = 'affiliate'");
|
||||
}
|
||||
}
|
137
admininistrator/model/customer/customer_group.php
Normal file
137
admininistrator/model/customer/customer_group.php
Normal file
@ -0,0 +1,137 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Model\Customer;
|
||||
/**
|
||||
* Class Customer Group
|
||||
*
|
||||
* @package Opencart\Admin\Model\Customer
|
||||
*/
|
||||
class CustomerGroup extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function addCustomerGroup(array $data): int {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "customer_group` SET `approval` = '" . (isset($data['approval']) ? (bool)$data['approval'] : 0) . "', `sort_order` = '" . (int)$data['sort_order'] . "'");
|
||||
|
||||
$customer_group_id = $this->db->getLastId();
|
||||
|
||||
foreach ($data['customer_group_description'] as $language_id => $value) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "customer_group_description` SET `customer_group_id` = '" . (int)$customer_group_id . "', `language_id` = '" . (int)$language_id . "', `name` = '" . $this->db->escape($value['name']) . "', `description` = '" . $this->db->escape($value['description']) . "'");
|
||||
}
|
||||
|
||||
return $customer_group_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $customer_group_id
|
||||
* @param array $data
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function editCustomerGroup(int $customer_group_id, array $data): void {
|
||||
$this->db->query("UPDATE `" . DB_PREFIX . "customer_group` SET `approval` = '" . (isset($data['approval']) ? (bool)$data['approval'] : 0) . "', `sort_order` = '" . (int)$data['sort_order'] . "' WHERE `customer_group_id` = '" . (int)$customer_group_id . "'");
|
||||
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "customer_group_description` WHERE `customer_group_id` = '" . (int)$customer_group_id . "'");
|
||||
|
||||
foreach ($data['customer_group_description'] as $language_id => $value) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "customer_group_description` SET `customer_group_id` = '" . (int)$customer_group_id . "', `language_id` = '" . (int)$language_id . "', `name` = '" . $this->db->escape($value['name']) . "', `description` = '" . $this->db->escape($value['description']) . "'");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $customer_group_id
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function deleteCustomerGroup(int $customer_group_id): void {
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "customer_group` WHERE `customer_group_id` = '" . (int)$customer_group_id . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "customer_group_description` WHERE `customer_group_id` = '" . (int)$customer_group_id . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "product_discount` WHERE `customer_group_id` = '" . (int)$customer_group_id . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "product_special` WHERE `customer_group_id` = '" . (int)$customer_group_id . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "product_reward` WHERE `customer_group_id` = '" . (int)$customer_group_id . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "tax_rate_to_customer_group` WHERE `customer_group_id` = '" . (int)$customer_group_id . "'");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $customer_group_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getCustomerGroup(int $customer_group_id): array {
|
||||
$query = $this->db->query("SELECT DISTINCT * FROM `" . DB_PREFIX . "customer_group` cg LEFT JOIN `" . DB_PREFIX . "customer_group_description` cgd ON (cg.`customer_group_id` = cgd.`customer_group_id`) WHERE cg.`customer_group_id` = '" . (int)$customer_group_id . "' AND cgd.`language_id` = '" . (int)$this->config->get('config_language_id') . "'");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getCustomerGroups(array $data = []): array {
|
||||
$sql = "SELECT * FROM `" . DB_PREFIX . "customer_group` cg LEFT JOIN `" . DB_PREFIX . "customer_group_description` cgd ON (cg.`customer_group_id` = cgd.`customer_group_id`) WHERE cgd.`language_id` = '" . (int)$this->config->get('config_language_id') . "'";
|
||||
|
||||
$sort_data = [
|
||||
'cgd.name',
|
||||
'cg.sort_order'
|
||||
];
|
||||
|
||||
if (isset($data['sort']) && in_array($data['sort'], $sort_data)) {
|
||||
$sql .= " ORDER BY " . $data['sort'];
|
||||
} else {
|
||||
$sql .= " ORDER BY cgd.`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'];
|
||||
}
|
||||
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
return $query->rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $customer_group_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getDescriptions(int $customer_group_id): array {
|
||||
$customer_group_data = [];
|
||||
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "customer_group_description` WHERE `customer_group_id` = '" . (int)$customer_group_id . "'");
|
||||
|
||||
foreach ($query->rows as $result) {
|
||||
$customer_group_data[$result['language_id']] = [
|
||||
'name' => $result['name'],
|
||||
'description' => $result['description']
|
||||
];
|
||||
}
|
||||
|
||||
return $customer_group_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalCustomerGroups(): int {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "customer_group`");
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
}
|
139
admininistrator/model/customer/gdpr.php
Normal file
139
admininistrator/model/customer/gdpr.php
Normal file
@ -0,0 +1,139 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Model\Customer;
|
||||
/**
|
||||
* Class GDPR
|
||||
*
|
||||
* @package Opencart\Admin\Model\Customer
|
||||
*/
|
||||
class Gdpr extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @param int $gdpr_id
|
||||
* @param int $status
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function editStatus(int $gdpr_id, int $status): void {
|
||||
$this->db->query("UPDATE `" . DB_PREFIX . "gdpr` SET `status` = '" . (int)$status . "' WHERE `gdpr_id` = '" . (int)$gdpr_id . "'");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $gdpr_id
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function deleteGdpr(int $gdpr_id): void {
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "gdpr` WHERE `gdpr_id` = '" . (int)$gdpr_id . "'");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getGdprs(array $data = []): array {
|
||||
$sql = "SELECT * FROM `" . DB_PREFIX . "gdpr`";
|
||||
|
||||
$implode = [];
|
||||
|
||||
if (!empty($data['filter_email'])) {
|
||||
$implode[] = "`email` LIKE '" . $this->db->escape((string)$data['filter_email']) . "'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_action'])) {
|
||||
$implode[] = "`action` = '" . $this->db->escape((string)$data['filter_action']) . "'";
|
||||
}
|
||||
|
||||
if (isset($data['filter_status']) && $data['filter_status'] !== '') {
|
||||
$implode[] = "`status` = '" . (int)$data['filter_status'] . "'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_date_from'])) {
|
||||
$implode[] = "DATE(`date_added`) >= DATE('" . $this->db->escape((string)$data['filter_date_from']) . "')";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_date_to'])) {
|
||||
$implode[] = "DATE(`date_added`) <= DATE('" . $this->db->escape((string)$data['filter_date_to']) . "')";
|
||||
}
|
||||
|
||||
if ($implode) {
|
||||
$sql .= " WHERE " . implode(" AND ", $implode);
|
||||
}
|
||||
|
||||
$sql .= " ORDER BY `date_added` DESC";
|
||||
|
||||
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 $gdpr_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getGdpr(int $gdpr_id): array {
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "gdpr` WHERE `gdpr_id` = '" . (int)$gdpr_id . "'");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalGdprs(array $data = []): int {
|
||||
$sql = "SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "gdpr`";
|
||||
|
||||
$implode = [];
|
||||
|
||||
if (!empty($data['filter_email'])) {
|
||||
$implode[] = "`email` LIKE '" . $this->db->escape((string)$data['filter_email']) . "'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_action'])) {
|
||||
$implode[] = "`action` = '" . $this->db->escape((string)$data['filter_action']) . "'";
|
||||
}
|
||||
|
||||
if (isset($data['filter_status']) && $data['filter_status'] !== '') {
|
||||
$implode[] = "`status` = '" . (int)$data['filter_status'] . "'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_date_from'])) {
|
||||
$implode[] = "DATE(`date_added`) >= DATE('" . $this->db->escape((string)$data['filter_date_from']) . "')";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_date_to'])) {
|
||||
$implode[] = "DATE(`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'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getExpires(): array {
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "gdpr` WHERE `status` = '2' AND DATE(`date_added`) <= DATE('" . $this->db->escape(date('Y-m-d', strtotime('+' . (int)$this->config->get('config_gdpr_limit') . ' days'))) . "') ORDER BY `date_added` DESC");
|
||||
|
||||
return $query->rows;
|
||||
}
|
||||
}
|
143
admininistrator/model/design/banner.php
Normal file
143
admininistrator/model/design/banner.php
Normal file
@ -0,0 +1,143 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Model\Design;
|
||||
/**
|
||||
* Class Banner
|
||||
*
|
||||
* @package Opencart\Admin\Model\Design
|
||||
*/
|
||||
class Banner extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function addBanner(array $data): int {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "banner` SET `name` = '" . $this->db->escape((string)$data['name']) . "', `status` = '" . (bool)(isset($data['status']) ? $data['status'] : 0) . "'");
|
||||
|
||||
$banner_id = $this->db->getLastId();
|
||||
|
||||
if (isset($data['banner_image'])) {
|
||||
foreach ($data['banner_image'] as $language_id => $value) {
|
||||
foreach ($value as $banner_image) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "banner_image` SET `banner_id` = '" . (int)$banner_id . "', `language_id` = '" . (int)$language_id . "', `title` = '" . $this->db->escape($banner_image['title']) . "', `link` = '" . $this->db->escape($banner_image['link']) . "', `image` = '" . $this->db->escape($banner_image['image']) . "', `sort_order` = '" . (int)$banner_image['sort_order'] . "'");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $banner_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $banner_id
|
||||
* @param array $data
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function editBanner(int $banner_id, array $data): void {
|
||||
$this->db->query("UPDATE `" . DB_PREFIX . "banner` SET `name` = '" . $this->db->escape((string)$data['name']) . "', `status` = '" . (bool)(isset($data['status']) ? $data['status'] : 0) . "' WHERE `banner_id` = '" . (int)$banner_id . "'");
|
||||
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "banner_image` WHERE `banner_id` = '" . (int)$banner_id . "'");
|
||||
|
||||
if (isset($data['banner_image'])) {
|
||||
foreach ($data['banner_image'] as $language_id => $value) {
|
||||
foreach ($value as $banner_image) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "banner_image` SET `banner_id` = '" . (int)$banner_id . "', `language_id` = '" . (int)$language_id . "', `title` = '" . $this->db->escape($banner_image['title']) . "', `link` = '" . $this->db->escape($banner_image['link']) . "', `image` = '" . $this->db->escape($banner_image['image']) . "', `sort_order` = '" . (int)$banner_image['sort_order'] . "'");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $banner_id
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function deleteBanner(int $banner_id): void {
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "banner` WHERE `banner_id` = '" . (int)$banner_id . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "banner_image` WHERE `banner_id` = '" . (int)$banner_id . "'");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $banner_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getBanner(int $banner_id): array {
|
||||
$query = $this->db->query("SELECT DISTINCT * FROM `" . DB_PREFIX . "banner` WHERE `banner_id` = '" . (int)$banner_id . "'");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getBanners(array $data = []): array {
|
||||
$sql = "SELECT * FROM `" . DB_PREFIX . "banner`";
|
||||
|
||||
$sort_data = [
|
||||
'name',
|
||||
'status'
|
||||
];
|
||||
|
||||
if (isset($data['sort']) && in_array($data['sort'], $sort_data)) {
|
||||
$sql .= " ORDER BY " . $data['sort'];
|
||||
} else {
|
||||
$sql .= " ORDER BY `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'];
|
||||
}
|
||||
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
return $query->rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $banner_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getImages(int $banner_id): array {
|
||||
$banner_image_data = [];
|
||||
|
||||
$banner_image_query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "banner_image` WHERE `banner_id` = '" . (int)$banner_id . "' ORDER BY `sort_order` ASC");
|
||||
|
||||
foreach ($banner_image_query->rows as $banner_image) {
|
||||
$banner_image_data[$banner_image['language_id']][] = [
|
||||
'title' => $banner_image['title'],
|
||||
'link' => $banner_image['link'],
|
||||
'image' => $banner_image['image'],
|
||||
'sort_order' => $banner_image['sort_order']
|
||||
];
|
||||
}
|
||||
|
||||
return $banner_image_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalBanners(): int {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "banner`");
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
}
|
156
admininistrator/model/design/layout.php
Normal file
156
admininistrator/model/design/layout.php
Normal file
@ -0,0 +1,156 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Model\Design;
|
||||
/**
|
||||
* Class Layout
|
||||
*
|
||||
* @package Opencart\Admin\Model\Design
|
||||
*/
|
||||
class Layout extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function addLayout(array $data): int {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "layout` SET `name` = '" . $this->db->escape((string)$data['name']) . "'");
|
||||
|
||||
$layout_id = $this->db->getLastId();
|
||||
|
||||
if (isset($data['layout_route'])) {
|
||||
foreach ($data['layout_route'] as $layout_route) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "layout_route` SET `layout_id` = '" . (int)$layout_id . "', `store_id` = '" . (int)$layout_route['store_id'] . "', `route` = '" . $this->db->escape($layout_route['route']) . "'");
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($data['layout_module'])) {
|
||||
foreach ($data['layout_module'] as $layout_module) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "layout_module` SET `layout_id` = '" . (int)$layout_id . "', `code` = '" . $this->db->escape($layout_module['code']) . "', `position` = '" . $this->db->escape($layout_module['position']) . "', `sort_order` = '" . (int)$layout_module['sort_order'] . "'");
|
||||
}
|
||||
}
|
||||
|
||||
return $layout_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $layout_id
|
||||
* @param array $data
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function editLayout(int $layout_id, array $data): void {
|
||||
$this->db->query("UPDATE `" . DB_PREFIX . "layout` SET `name` = '" . $this->db->escape((string)$data['name']) . "' WHERE `layout_id` = '" . (int)$layout_id . "'");
|
||||
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "layout_route` WHERE `layout_id` = '" . (int)$layout_id . "'");
|
||||
|
||||
if (isset($data['layout_route'])) {
|
||||
foreach ($data['layout_route'] as $layout_route) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "layout_route` SET `layout_id` = '" . (int)$layout_id . "', `store_id` = '" . (int)$layout_route['store_id'] . "', `route` = '" . $this->db->escape($layout_route['route']) . "'");
|
||||
}
|
||||
}
|
||||
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "layout_module` WHERE `layout_id` = '" . (int)$layout_id . "'");
|
||||
|
||||
if (isset($data['layout_module'])) {
|
||||
foreach ($data['layout_module'] as $layout_module) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "layout_module` SET `layout_id` = '" . (int)$layout_id . "', `code` = '" . $this->db->escape($layout_module['code']) . "', `position` = '" . $this->db->escape($layout_module['position']) . "', `sort_order` = '" . (int)$layout_module['sort_order'] . "'");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $layout_id
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function deleteLayout(int $layout_id): void {
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "layout` WHERE `layout_id` = '" . (int)$layout_id . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "layout_route` WHERE `layout_id` = '" . (int)$layout_id . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "layout_module` WHERE `layout_id` = '" . (int)$layout_id . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "category_to_layout` WHERE `layout_id` = '" . (int)$layout_id . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "product_to_layout` WHERE `layout_id` = '" . (int)$layout_id . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "information_to_layout` WHERE `layout_id` = '" . (int)$layout_id . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "blog_to_layout` WHERE `layout_id` = '" . (int)$layout_id . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "blog_category_to_layout` WHERE `layout_id` = '" . (int)$layout_id . "'");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $layout_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getLayout(int $layout_id): array {
|
||||
$query = $this->db->query("SELECT DISTINCT * FROM `" . DB_PREFIX . "layout` WHERE `layout_id` = '" . (int)$layout_id . "'");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getLayouts(array $data = []): array {
|
||||
$sql = "SELECT * FROM `" . DB_PREFIX . "layout`";
|
||||
|
||||
$sort_data = ['name'];
|
||||
|
||||
if (isset($data['sort']) && in_array($data['sort'], $sort_data)) {
|
||||
$sql .= " ORDER BY " . $data['sort'];
|
||||
} else {
|
||||
$sql .= " ORDER BY `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'];
|
||||
}
|
||||
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
return $query->rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $layout_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getRoutes(int $layout_id): array {
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "layout_route` WHERE `layout_id` = '" . (int)$layout_id . "'");
|
||||
|
||||
return $query->rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $layout_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getModules(int $layout_id): array {
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "layout_module` WHERE `layout_id` = '" . (int)$layout_id . "' ORDER BY `position` ASC, `sort_order` ASC");
|
||||
|
||||
return $query->rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalLayouts(): int {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "layout`");
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
}
|
193
admininistrator/model/design/seo_url.php
Normal file
193
admininistrator/model/design/seo_url.php
Normal file
@ -0,0 +1,193 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Model\Design;
|
||||
/**
|
||||
* Class Seo Url
|
||||
*
|
||||
* @package Opencart\Admin\Model\Design
|
||||
*/
|
||||
class SeoUrl extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function addSeoUrl(array $data): int {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "seo_url` SET `store_id` = '" . (int)$data['store_id'] . "', `language_id` = '" . (int)$data['language_id'] . "', `key` = '" . $this->db->escape((string)$data['key']) . "', `value` = '" . $this->db->escape((string)$data['value']) . "', `keyword` = '" . $this->db->escape((string)$data['keyword']) . "', `sort_order` = '" . (int)$data['sort_order'] . "'");
|
||||
|
||||
return $this->db->getLastId();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $seo_url_id
|
||||
* @param array $data
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function editSeoUrl(int $seo_url_id, array $data): void {
|
||||
$this->db->query("UPDATE `" . DB_PREFIX . "seo_url` SET `store_id` = '" . (int)$data['store_id'] . "', `language_id` = '" . (int)$data['language_id'] . "', `key` = '" . $this->db->escape((string)$data['key']) . "', `value` = '" . $this->db->escape((string)$data['value']) . "', `keyword` = '" . $this->db->escape((string)$data['keyword']) . "', `sort_order` = '" . (int)$data['sort_order'] . "' WHERE `seo_url_id` = '" . (int)$seo_url_id . "'");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $seo_url_id
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function deleteSeoUrl(int $seo_url_id): void {
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "seo_url` WHERE `seo_url_id` = '" . (int)$seo_url_id . "'");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $seo_url_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getSeoUrl(int $seo_url_id): array {
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "seo_url` WHERE `seo_url_id` = '" . (int)$seo_url_id . "'");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getSeoUrls(array $data = []): array {
|
||||
$sql = "SELECT *, (SELECT `name` FROM `" . DB_PREFIX . "store` s WHERE s.`store_id` = su.`store_id`) AS `store`, (SELECT `name` FROM `" . DB_PREFIX . "language` l WHERE l.`language_id` = su.`language_id`) AS `language` FROM `" . DB_PREFIX . "seo_url` su";
|
||||
|
||||
$implode = [];
|
||||
|
||||
if (!empty($data['filter_keyword'])) {
|
||||
$implode[] = "`keyword` LIKE '" . $this->db->escape((string)$data['filter_keyword']) . "'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_key'])) {
|
||||
$implode[] = "`key` = '" . $this->db->escape((string)$data['filter_key']) . "'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_value'])) {
|
||||
$implode[] = "`value` LIKE '" . $this->db->escape((string)$data['filter_value']) . "'";
|
||||
}
|
||||
|
||||
if (isset($data['filter_store_id']) && $data['filter_store_id'] !== '') {
|
||||
$implode[] = "`store_id` = '" . (int)$data['filter_store_id'] . "'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_language_id']) && $data['filter_language_id'] !== '') {
|
||||
$implode[] = "`language_id` = '" . (int)$data['filter_language_id'] . "'";
|
||||
}
|
||||
|
||||
if ($implode) {
|
||||
$sql .= " WHERE " . implode(" AND ", $implode);
|
||||
}
|
||||
|
||||
$sort_data = [
|
||||
'keyword',
|
||||
'key',
|
||||
'value',
|
||||
'sort_order',
|
||||
'store_id',
|
||||
'language_id'
|
||||
];
|
||||
|
||||
if (isset($data['sort']) && in_array($data['sort'], $sort_data)) {
|
||||
$sql .= " ORDER BY `" . $data['sort'] . "`";
|
||||
} else {
|
||||
$sql .= " ORDER BY `key`";
|
||||
}
|
||||
|
||||
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 getTotalSeoUrls(array $data = []): int {
|
||||
$sql = "SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "seo_url`";
|
||||
|
||||
$implode = [];
|
||||
|
||||
if (!empty($data['filter_keyword'])) {
|
||||
$implode[] = "`keyword` LIKE '" . $this->db->escape((string)$data['filter_keyword']) . "'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_key'])) {
|
||||
$implode[] = "`key` = '" . $this->db->escape((string)$data['filter_key']) . "'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_value'])) {
|
||||
$implode[] = "`value` LIKE '" . $this->db->escape((string)$data['filter_value']) . "'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_store_id']) && $data['filter_store_id'] !== '') {
|
||||
$implode[] = "`store_id` = '" . (int)$data['filter_store_id'] . "'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_language_id']) && $data['filter_language_id'] !== '') {
|
||||
$implode[] = "`language_id` = '" . (int)$data['filter_language_id'] . "'";
|
||||
}
|
||||
|
||||
if ($implode) {
|
||||
$sql .= " WHERE " . implode(" AND ", $implode);
|
||||
}
|
||||
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $key
|
||||
* @param string $value
|
||||
* @param int $store_id
|
||||
* @param int $language_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getSeoUrlByKeyValue(string $key, string $value, int $store_id, int $language_id): array {
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "seo_url` WHERE `key` = '" . $this->db->escape($key) . "' AND `value` = '" . $this->db->escape($value) . "' AND `store_id` = '" . (int)$store_id . "' AND `language_id` = '" . (int)$language_id . "'");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $keyword
|
||||
* @param int $store_id
|
||||
* @param int $language_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getSeoUrlByKeyword(string $keyword, int $store_id, int $language_id = 0): array {
|
||||
$sql = "SELECT * FROM `" . DB_PREFIX . "seo_url` WHERE (`keyword` = '" . $this->db->escape($keyword) . "' OR `keyword` LIKE '" . $this->db->escape('%/' . $keyword) . "') AND `store_id` = '" . (int)$store_id . "'";
|
||||
|
||||
if ($language_id) {
|
||||
$sql .= " AND `language_id` = '" . (int)$language_id . "'";
|
||||
}
|
||||
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
}
|
71
admininistrator/model/design/theme.php
Normal file
71
admininistrator/model/design/theme.php
Normal file
@ -0,0 +1,71 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Model\Design;
|
||||
/**
|
||||
* Class Theme
|
||||
*
|
||||
* @package Opencart\Admin\Model\Design
|
||||
*/
|
||||
class Theme extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @param int $store_id
|
||||
* @param string $route
|
||||
* @param string $code
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function editTheme(int $store_id, string $route, string $code): void {
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "theme` WHERE `store_id` = '" . (int)$store_id . "' AND `route` = '" . $this->db->escape($route) . "'");
|
||||
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "theme` SET `store_id` = '" . (int)$store_id . "', `route` = '" . $this->db->escape($route) . "', `code` = '" . $this->db->escape($code) . "', `date_added` = NOW()");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $theme_id
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function deleteTheme(int $theme_id): void {
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "theme` WHERE `theme_id` = '" . (int)$theme_id . "'");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $store_id
|
||||
* @param string $route
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getTheme(int $store_id, string $route): array {
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "theme` WHERE `store_id` = '" . (int)$store_id . "' AND `route` = '" . $this->db->escape($route) . "'");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $start
|
||||
* @param int $limit
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getThemes(int $start = 0, int $limit = 10): array {
|
||||
if ($start < 0) {
|
||||
$start = 0;
|
||||
}
|
||||
|
||||
if ($limit < 1) {
|
||||
$limit = 10;
|
||||
}
|
||||
|
||||
$query = $this->db->query("SELECT *, (SELECT `name` FROM `" . DB_PREFIX . "store` s WHERE s.`store_id` = t.`store_id`) AS `store` FROM `" . DB_PREFIX . "theme` t ORDER BY t.`date_added` DESC LIMIT " . (int)$start . "," . (int)$limit);
|
||||
|
||||
return $query->rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalThemes(): int {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "theme`");
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
}
|
101
admininistrator/model/design/translation.php
Normal file
101
admininistrator/model/design/translation.php
Normal file
@ -0,0 +1,101 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Model\Design;
|
||||
/**
|
||||
* Class Translation
|
||||
*
|
||||
* @package Opencart\Admin\Model\Design
|
||||
*/
|
||||
class Translation extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function addTranslation(array $data): void {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "translation` SET `store_id` = '" . (int)$data['store_id'] . "', `language_id` = '" . (int)$data['language_id'] . "', `route` = '" . $this->db->escape((string)$data['route']) . "', `key` = '" . $this->db->escape((string)$data['key']) . "', `value` = '" . $this->db->escape((string)$data['value']) . "', `date_added` = NOW()");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $translation_id
|
||||
* @param array $data
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function editTranslation(int $translation_id, array $data): void {
|
||||
$this->db->query("UPDATE `" . DB_PREFIX . "translation` SET `store_id` = '" . (int)$data['store_id'] . "', `language_id` = '" . (int)$data['language_id'] . "', `route` = '" . $this->db->escape((string)$data['route']) . "', `key` = '" . $this->db->escape((string)$data['key']) . "', `value` = '" . $this->db->escape((string)$data['value']) . "' WHERE `translation_id` = '" . (int)$translation_id . "'");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $translation_id
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function deleteTranslation(int $translation_id): void {
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "translation` WHERE `translation_id` = '" . (int)$translation_id . "'");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $translation_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getTranslation(int $translation_id): array {
|
||||
$query = $this->db->query("SELECT DISTINCT * FROM `" . DB_PREFIX . "translation` WHERE `translation_id` = '" . (int)$translation_id . "'");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getTranslations(array $data = []): array {
|
||||
$sql = "SELECT *, (SELECT s.`name` FROM `" . DB_PREFIX . "store` s WHERE s.`store_id` = t.`store_id`) AS store, (SELECT l.`name` FROM `" . DB_PREFIX . "language` l WHERE l.`language_id` = t.`language_id`) AS language FROM `" . DB_PREFIX . "translation` t";
|
||||
|
||||
$sort_data = [
|
||||
'store',
|
||||
'language',
|
||||
'route',
|
||||
'key',
|
||||
'value'
|
||||
];
|
||||
|
||||
if (isset($data['sort']) && in_array($data['sort'], $sort_data)) {
|
||||
$sql .= " ORDER BY " . $data['sort'];
|
||||
} else {
|
||||
$sql .= " ORDER BY store";
|
||||
}
|
||||
|
||||
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 getTotalTranslations(): int {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "translation`");
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
}
|
85
admininistrator/model/localisation/address_format.php
Normal file
85
admininistrator/model/localisation/address_format.php
Normal file
@ -0,0 +1,85 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Model\Localisation;
|
||||
/**
|
||||
* Class Address Format
|
||||
*
|
||||
* @package Opencart\Admin\Model\Localisation
|
||||
*/
|
||||
class AddressFormat extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function addAddressFormat(array $data): int {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "address_format` SET `name` = '" . $this->db->escape((string)$data['name']) . "', `address_format` = '" . $this->db->escape((string)$data['address_format']) . "'");
|
||||
|
||||
return $this->db->getLastId();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $address_format_id
|
||||
* @param array $data
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function editAddressFormat(int $address_format_id, array $data): void {
|
||||
$this->db->query("UPDATE `" . DB_PREFIX . "address_format` SET `name` = '" . $this->db->escape((string)$data['name']) . "', `address_format` = '" . $this->db->escape((string)$data['address_format']) . "' WHERE `address_format_id` = '" . (int)$address_format_id . "'");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $address_format_id
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function deleteAddressFormat(int $address_format_id): void {
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "address_format` WHERE `address_format_id` = '" . (int)$address_format_id . "'");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $address_format_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getAddressFormat(int $address_format_id): array {
|
||||
$query = $this->db->query("SELECT DISTINCT * FROM `" . DB_PREFIX . "address_format` WHERE `address_format_id` = '" . (int)$address_format_id . "'");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getAddressFormats(array $data = []): array {
|
||||
$sql = "SELECT * FROM `" . DB_PREFIX . "address_format`";
|
||||
|
||||
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 getTotalAddressFormats(array $data = []): int {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "address_format`");
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
}
|
188
admininistrator/model/localisation/country.php
Normal file
188
admininistrator/model/localisation/country.php
Normal file
@ -0,0 +1,188 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Model\Localisation;
|
||||
/**
|
||||
* Class Country
|
||||
*
|
||||
* @package Opencart\Admin\Model\Localisation
|
||||
*/
|
||||
class Country extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function addCountry(array $data): int {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "country` SET `name` = '" . $this->db->escape((string)$data['name']) . "', `iso_code_2` = '" . $this->db->escape((string)$data['iso_code_2']) . "', `iso_code_3` = '" . $this->db->escape((string)$data['iso_code_3']) . "', `address_format_id` = '" . (int)$data['address_format_id'] . "', `postcode_required` = '" . (int)$data['postcode_required'] . "', `status` = '" . (bool)(isset($data['status']) ? $data['status'] : 0) . "'");
|
||||
|
||||
$this->cache->delete('country');
|
||||
|
||||
return $this->db->getLastId();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $country_id
|
||||
* @param array $data
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function editCountry(int $country_id, array $data): void {
|
||||
$this->db->query("UPDATE `" . DB_PREFIX . "country` SET `name` = '" . $this->db->escape((string)$data['name']) . "', `iso_code_2` = '" . $this->db->escape((string)$data['iso_code_2']) . "', `iso_code_3` = '" . $this->db->escape((string)$data['iso_code_3']) . "', `address_format_id` = '" . (int)$data['address_format_id'] . "', `postcode_required` = '" . (int)$data['postcode_required'] . "', `status` = '" . (bool)(isset($data['status']) ? $data['status'] : 0) . "' WHERE `country_id` = '" . (int)$country_id . "'");
|
||||
|
||||
$this->cache->delete('country');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $country_id
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function deleteCountry(int $country_id): void {
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "country` WHERE `country_id` = '" . (int)$country_id . "'");
|
||||
|
||||
$this->cache->delete('country');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $country_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getCountry(int $country_id): array {
|
||||
$query = $this->db->query("SELECT DISTINCT * FROM `" . DB_PREFIX . "country` WHERE `country_id` = '" . (int)$country_id . "'");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $iso_code_2
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getCountryByIsoCode2($iso_code_2): array {
|
||||
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "country WHERE `iso_code_2` = '" . $this->db->escape($iso_code_2) . "' AND `status` = '1'");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $iso_code_3
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getCountryByIsoCode3($iso_code_3): array {
|
||||
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "country WHERE `iso_code_3` = '" . $this->db->escape($iso_code_3) . "' AND `status` = '1'");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getCountries(array $data = []): array {
|
||||
$sql = "SELECT * FROM `" . DB_PREFIX . "country`";
|
||||
|
||||
$implode = [];
|
||||
|
||||
if (!empty($data['filter_name'])) {
|
||||
$implode[] = "`name` LIKE '" . $this->db->escape((string)$data['filter_name'] . '%') . "'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_iso_code_2'])) {
|
||||
$implode[] = "`iso_code_2` LIKE '" . $this->db->escape((string)$data['filter_iso_code_2'] . '%') . "'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_iso_code_3'])) {
|
||||
$implode[] = "`iso_code_3` LIKE '" . $this->db->escape((string)$data['filter_iso_code_3'] . '%') . "'";
|
||||
}
|
||||
|
||||
if ($implode) {
|
||||
$sql .= " WHERE " . implode(" AND ", $implode);
|
||||
}
|
||||
|
||||
$sort_data = [
|
||||
'name',
|
||||
'iso_code_2',
|
||||
'iso_code_3'
|
||||
];
|
||||
|
||||
if (isset($data['sort']) && in_array($data['sort'], $sort_data)) {
|
||||
$sql .= " ORDER BY " . $data['sort'];
|
||||
} else {
|
||||
$sql .= " ORDER BY `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'];
|
||||
}
|
||||
|
||||
$country_data = $this->cache->get('country.' . md5($sql));
|
||||
|
||||
if (!$country_data) {
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
$country_data = $query->rows;
|
||||
|
||||
$this->cache->set('country.' . md5($sql), $country_data);
|
||||
}
|
||||
|
||||
return $country_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalCountries(array $data = []): int {
|
||||
$sql = "SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "country`";
|
||||
|
||||
$implode = [];
|
||||
|
||||
if (!empty($data['filter_name'])) {
|
||||
$implode[] = "`name` LIKE '" . $this->db->escape((string)$data['filter_name'] . '%') . "'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_iso_code_2'])) {
|
||||
$implode[] = "`iso_code_2` LIKE '" . $this->db->escape((string)$data['filter_iso_code_2'] . '%') . "'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_iso_code_3'])) {
|
||||
$implode[] = "`iso_code_3` LIKE '" . $this->db->escape((string)$data['filter_iso_code_3'] . '%') . "'";
|
||||
}
|
||||
|
||||
if ($implode) {
|
||||
$sql .= " WHERE " . implode(" AND ", $implode);
|
||||
}
|
||||
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $address_format_id
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalCountriesByAddressFormatId(int $address_format_id): int {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "country` WHERE `address_format_id` = '" . (int)$address_format_id . "'");
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
}
|
155
admininistrator/model/localisation/currency.php
Normal file
155
admininistrator/model/localisation/currency.php
Normal file
@ -0,0 +1,155 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Model\Localisation;
|
||||
/**
|
||||
* Class Currency
|
||||
*
|
||||
* @package Opencart\Admin\Model\Localisation
|
||||
*/
|
||||
class Currency extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function addCurrency(array $data): int {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "currency` SET `title` = '" . $this->db->escape((string)$data['title']) . "', `code` = '" . $this->db->escape((string)$data['code']) . "', `symbol_left` = '" . $this->db->escape((string)$data['symbol_left']) . "', `symbol_right` = '" . $this->db->escape((string)$data['symbol_right']) . "', `decimal_place` = '" . (int)$data['decimal_place'] . "', `value` = '" . (float)$data['value'] . "', `status` = '" . (bool)(isset($data['status']) ? $data['status'] : 0) . "', `date_modified` = NOW()");
|
||||
|
||||
$this->cache->delete('currency');
|
||||
|
||||
return $this->db->getLastId();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $currency_id
|
||||
* @param array $data
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function editCurrency(int $currency_id, array $data): void {
|
||||
$this->db->query("UPDATE `" . DB_PREFIX . "currency` SET `title` = '" . $this->db->escape((string)$data['title']) . "', `code` = '" . $this->db->escape((string)$data['code']) . "', `symbol_left` = '" . $this->db->escape((string)$data['symbol_left']) . "', `symbol_right` = '" . $this->db->escape((string)$data['symbol_right']) . "', `decimal_place` = '" . (int)$data['decimal_place'] . "', `value` = '" . (float)$data['value'] . "', `status` = '" . (bool)(isset($data['status']) ? $data['status'] : 0) . "', `date_modified` = NOW() WHERE `currency_id` = '" . (int)$currency_id . "'");
|
||||
|
||||
$this->cache->delete('currency');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $code
|
||||
* @param float $value
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function editValueByCode(string $code, float $value): void {
|
||||
$this->db->query("UPDATE `" . DB_PREFIX . "currency` SET `value` = '" . (float)$value . "', `date_modified` = NOW() WHERE `code` = '" . $this->db->escape($code) . "'");
|
||||
|
||||
$this->cache->delete('currency');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $currency_id
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function deleteCurrency(int $currency_id): void {
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "currency` WHERE `currency_id` = '" . (int)$currency_id . "'");
|
||||
|
||||
$this->cache->delete('currency');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $currency_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getCurrency(int $currency_id): array {
|
||||
$query = $this->db->query("SELECT DISTINCT * FROM `" . DB_PREFIX . "currency` WHERE `currency_id` = '" . (int)$currency_id . "'");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $currency
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getCurrencyByCode(string $currency): array {
|
||||
$query = $this->db->query("SELECT DISTINCT * FROM `" . DB_PREFIX . "currency` WHERE `code` = '" . $this->db->escape($currency) . "'");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getCurrencies(array $data = []): array {
|
||||
$sql = "SELECT * FROM `" . DB_PREFIX . "currency`";
|
||||
|
||||
$sort_data = [
|
||||
'title',
|
||||
'code',
|
||||
'value',
|
||||
'date_modified'
|
||||
];
|
||||
|
||||
if (isset($data['sort']) && in_array($data['sort'], $sort_data)) {
|
||||
$sql .= " ORDER BY " . $data['sort'];
|
||||
} else {
|
||||
$sql .= " ORDER BY `title`";
|
||||
}
|
||||
|
||||
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'];
|
||||
}
|
||||
|
||||
$results = (array)$this->cache->get('currency.' . md5($sql));
|
||||
|
||||
if (!$results) {
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
$results = $query->rows;
|
||||
|
||||
$this->cache->set('currency.' . md5($sql), $results);
|
||||
}
|
||||
|
||||
$currency_data = [];
|
||||
|
||||
foreach ($results as $result) {
|
||||
$currency_data[$result['code']] = [
|
||||
'currency_id' => $result['currency_id'],
|
||||
'title' => $result['title'],
|
||||
'code' => $result['code'],
|
||||
'symbol_left' => $result['symbol_left'],
|
||||
'symbol_right' => $result['symbol_right'],
|
||||
'decimal_place' => $result['decimal_place'],
|
||||
'value' => $result['value'],
|
||||
'status' => $result['status'],
|
||||
'date_modified' => $result['date_modified']
|
||||
];
|
||||
}
|
||||
|
||||
return $currency_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalCurrencies(): int {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "currency`");
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
}
|
179
admininistrator/model/localisation/geo_zone.php
Normal file
179
admininistrator/model/localisation/geo_zone.php
Normal file
@ -0,0 +1,179 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Model\Localisation;
|
||||
/**
|
||||
* Class GeoZone
|
||||
*
|
||||
* @package Opencart\Admin\Model\Localisation
|
||||
*/
|
||||
class GeoZone extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function addGeoZone(array $data): int {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "geo_zone` SET `name` = '" . $this->db->escape((string)$data['name']) . "', `description` = '" . $this->db->escape((string)$data['description']) . "', `date_added` = NOW()");
|
||||
|
||||
$geo_zone_id = $this->db->getLastId();
|
||||
|
||||
if (isset($data['zone_to_geo_zone'])) {
|
||||
foreach ($data['zone_to_geo_zone'] as $value) {
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "zone_to_geo_zone` WHERE `geo_zone_id` = '" . (int)$geo_zone_id . "' AND `country_id` = '" . (int)$value['country_id'] . "' AND `zone_id` = '" . (int)$value['zone_id'] . "'");
|
||||
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "zone_to_geo_zone` SET `country_id` = '" . (int)$value['country_id'] . "', `zone_id` = '" . (int)$value['zone_id'] . "', `geo_zone_id` = '" . (int)$geo_zone_id . "', `date_added` = NOW()");
|
||||
}
|
||||
}
|
||||
|
||||
$this->cache->delete('geo_zone');
|
||||
|
||||
return $geo_zone_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $geo_zone_id
|
||||
* @param array $data
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function editGeoZone(int $geo_zone_id, array $data): void {
|
||||
$this->db->query("UPDATE `" . DB_PREFIX . "geo_zone` SET `name` = '" . $this->db->escape((string)$data['name']) . "', `description` = '" . $this->db->escape((string)$data['description']) . "', `date_modified` = NOW() WHERE `geo_zone_id` = '" . (int)$geo_zone_id . "'");
|
||||
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "zone_to_geo_zone` WHERE `geo_zone_id` = '" . (int)$geo_zone_id . "'");
|
||||
|
||||
if (isset($data['zone_to_geo_zone'])) {
|
||||
foreach ($data['zone_to_geo_zone'] as $value) {
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "zone_to_geo_zone` WHERE `geo_zone_id` = '" . (int)$geo_zone_id . "' AND `country_id` = '" . (int)$value['country_id'] . "' AND `zone_id` = '" . (int)$value['zone_id'] . "'");
|
||||
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "zone_to_geo_zone` SET `country_id` = '" . (int)$value['country_id'] . "', `zone_id` = '" . (int)$value['zone_id'] . "', `geo_zone_id` = '" . (int)$geo_zone_id . "', `date_added` = NOW()");
|
||||
}
|
||||
}
|
||||
|
||||
$this->cache->delete('geo_zone');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $geo_zone_id
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function deleteGeoZone(int $geo_zone_id): void {
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "geo_zone` WHERE `geo_zone_id` = '" . (int)$geo_zone_id . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "zone_to_geo_zone` WHERE `geo_zone_id` = '" . (int)$geo_zone_id . "'");
|
||||
|
||||
$this->cache->delete('geo_zone');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $geo_zone_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getGeoZone(int $geo_zone_id): array {
|
||||
$query = $this->db->query("SELECT DISTINCT * FROM `" . DB_PREFIX . "geo_zone` WHERE `geo_zone_id` = '" . (int)$geo_zone_id . "'");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getGeoZones(array $data = []): array {
|
||||
$sql = "SELECT * FROM `" . DB_PREFIX . "geo_zone`";
|
||||
|
||||
$sort_data = [
|
||||
'name',
|
||||
'description'
|
||||
];
|
||||
|
||||
if (isset($data['sort']) && in_array($data['sort'], $sort_data)) {
|
||||
$sql .= " ORDER BY " . $data['sort'];
|
||||
} else {
|
||||
$sql .= " ORDER BY `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'];
|
||||
}
|
||||
|
||||
$geo_zone_data = $this->cache->get('geo_zone.' . md5($sql));
|
||||
|
||||
if (!$geo_zone_data) {
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
$geo_zone_data = $query->rows;
|
||||
|
||||
$this->cache->set('geo_zone.' . md5($sql), $geo_zone_data);
|
||||
}
|
||||
|
||||
return $geo_zone_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalGeoZones(): int {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "geo_zone`");
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $geo_zone_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getZoneToGeoZones(int $geo_zone_id): array {
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "zone_to_geo_zone` WHERE `geo_zone_id` = '" . (int)$geo_zone_id . "'");
|
||||
|
||||
return $query->rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $geo_zone_id
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalZoneToGeoZoneByGeoZoneId(int $geo_zone_id): int {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "zone_to_geo_zone` WHERE `geo_zone_id` = '" . (int)$geo_zone_id . "'");
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $country_id
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalZoneToGeoZoneByCountryId(int $country_id): int {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "zone_to_geo_zone` WHERE `country_id` = '" . (int)$country_id . "'");
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $zone_id
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalZoneToGeoZoneByZoneId(int $zone_id): int {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "zone_to_geo_zone` WHERE `zone_id` = '" . (int)$zone_id . "'");
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
}
|
428
admininistrator/model/localisation/language.php
Normal file
428
admininistrator/model/localisation/language.php
Normal file
@ -0,0 +1,428 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Model\Localisation;
|
||||
/**
|
||||
* Class Language
|
||||
*
|
||||
* @package Opencart\Admin\Model\Localisation
|
||||
*/
|
||||
class Language extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function addLanguage(array $data): int {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "language` SET `name` = '" . $this->db->escape((string)$data['name']) . "', `code` = '" . $this->db->escape((string)$data['code']) . "', `locale` = '" . $this->db->escape((string)$data['locale']) . "', `extension` = '" . $this->db->escape((string)$data['extension']) . "', `sort_order` = '" . (int)$data['sort_order'] . "', `status` = '" . (bool)(isset($data['status']) ? $data['status'] : 0) . "'");
|
||||
|
||||
$this->cache->delete('language');
|
||||
|
||||
$language_id = $this->db->getLastId();
|
||||
|
||||
// Attribute
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "attribute_description` WHERE `language_id` = '" . (int)$this->config->get('config_language_id') . "'");
|
||||
|
||||
foreach ($query->rows as $attribute) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "attribute_description` SET `attribute_id` = '" . (int)$attribute['attribute_id'] . "', `language_id` = '" . (int)$language_id . "', `name` = '" . $this->db->escape($attribute['name']) . "'");
|
||||
}
|
||||
|
||||
// Attribute Group
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "attribute_group_description` WHERE `language_id` = '" . (int)$this->config->get('config_language_id') . "'");
|
||||
|
||||
foreach ($query->rows as $attribute_group) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "attribute_group_description` SET `attribute_group_id` = '" . (int)$attribute_group['attribute_group_id'] . "', `language_id` = '" . (int)$language_id . "', `name` = '" . $this->db->escape($attribute_group['name']) . "'");
|
||||
}
|
||||
|
||||
$this->cache->delete('attribute');
|
||||
|
||||
// Banner
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "banner_image` WHERE `language_id` = '" . (int)$this->config->get('config_language_id') . "'");
|
||||
|
||||
foreach ($query->rows as $banner_image) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "banner_image` SET `banner_id` = '" . (int)$banner_image['banner_id'] . "', `language_id` = '" . (int)$language_id . "', `title` = '" . $this->db->escape($banner_image['title']) . "', `link` = '" . $this->db->escape($banner_image['link']) . "', `image` = '" . $this->db->escape($banner_image['image']) . "', `sort_order` = '" . (int)$banner_image['sort_order'] . "'");
|
||||
}
|
||||
|
||||
$this->cache->delete('banner');
|
||||
|
||||
// Category
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "category_description` WHERE `language_id` = '" . (int)$this->config->get('config_language_id') . "'");
|
||||
|
||||
foreach ($query->rows as $category) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "category_description` SET `category_id` = '" . (int)$category['category_id'] . "', `language_id` = '" . (int)$language_id . "', `name` = '" . $this->db->escape($category['name']) . "', `description` = '" . $this->db->escape($category['description']) . "', `meta_title` = '" . $this->db->escape($category['meta_title']) . "', `meta_description` = '" . $this->db->escape($category['meta_description']) . "', `meta_keyword` = '" . $this->db->escape($category['meta_keyword']) . "'");
|
||||
}
|
||||
|
||||
// Customer Group
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "customer_group_description` WHERE `language_id` = '" . (int)$this->config->get('config_language_id') . "'");
|
||||
|
||||
foreach ($query->rows as $customer_group) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "customer_group_description` SET `customer_group_id` = '" . (int)$customer_group['customer_group_id'] . "', `language_id` = '" . (int)$language_id . "', `name` = '" . $this->db->escape($customer_group['name']) . "', `description` = '" . $this->db->escape($customer_group['description']) . "'");
|
||||
}
|
||||
|
||||
// Custom Field
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "custom_field_description` WHERE `language_id` = '" . (int)$this->config->get('config_language_id') . "'");
|
||||
|
||||
foreach ($query->rows as $custom_field) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "custom_field_description` SET `custom_field_id` = '" . (int)$custom_field['custom_field_id'] . "', `language_id` = '" . (int)$language_id . "', `name` = '" . $this->db->escape($custom_field['name']) . "'");
|
||||
}
|
||||
|
||||
// Custom Field Value
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "custom_field_value_description` WHERE `language_id` = '" . (int)$this->config->get('config_language_id') . "'");
|
||||
|
||||
foreach ($query->rows as $custom_field_value) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "custom_field_value_description` SET `custom_field_value_id` = '" . (int)$custom_field_value['custom_field_value_id'] . "', `language_id` = '" . (int)$language_id . "', `custom_field_id` = '" . (int)$custom_field_value['custom_field_id'] . "', `name` = '" . $this->db->escape($custom_field_value['name']) . "'");
|
||||
}
|
||||
|
||||
// Download
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "download_description` WHERE `language_id` = '" . (int)$this->config->get('config_language_id') . "'");
|
||||
|
||||
foreach ($query->rows as $download) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "download_description` SET `download_id` = '" . (int)$download['download_id'] . "', `language_id` = '" . (int)$language_id . "', `name` = '" . $this->db->escape($download['name']) . "'");
|
||||
}
|
||||
|
||||
// Filter
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "filter_description` WHERE `language_id` = '" . (int)$this->config->get('config_language_id') . "'");
|
||||
|
||||
foreach ($query->rows as $filter) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "filter_description` SET `filter_id` = '" . (int)$filter['filter_id'] . "', `language_id` = '" . (int)$language_id . "', `filter_group_id` = '" . (int)$filter['filter_group_id'] . "', `name` = '" . $this->db->escape($filter['name']) . "'");
|
||||
}
|
||||
|
||||
// Filter Group
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "filter_group_description` WHERE `language_id` = '" . (int)$this->config->get('config_language_id') . "'");
|
||||
|
||||
foreach ($query->rows as $filter_group) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "filter_group_description` SET `filter_group_id` = '" . (int)$filter_group['filter_group_id'] . "', `language_id` = '" . (int)$language_id . "', `name` = '" . $this->db->escape($filter_group['name']) . "'");
|
||||
}
|
||||
|
||||
// Information
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "information_description` WHERE `language_id` = '" . (int)$this->config->get('config_language_id') . "'");
|
||||
|
||||
foreach ($query->rows as $information) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "information_description` SET `information_id` = '" . (int)$information['information_id'] . "', `language_id` = '" . (int)$language_id . "', `title` = '" . $this->db->escape($information['title']) . "', `description` = '" . $this->db->escape($information['description']) . "', `meta_title` = '" . $this->db->escape($information['meta_title']) . "', `meta_description` = '" . $this->db->escape($information['meta_description']) . "', `meta_keyword` = '" . $this->db->escape($information['meta_keyword']) . "'");
|
||||
}
|
||||
|
||||
$this->cache->delete('information');
|
||||
|
||||
// Length
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "length_class_description` WHERE `language_id` = '" . (int)$this->config->get('config_language_id') . "'");
|
||||
|
||||
foreach ($query->rows as $length) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "length_class_description` SET `length_class_id` = '" . (int)$length['length_class_id'] . "', `language_id` = '" . (int)$language_id . "', `title` = '" . $this->db->escape($length['title']) . "', `unit` = '" . $this->db->escape($length['unit']) . "'");
|
||||
}
|
||||
|
||||
$this->cache->delete('length_class');
|
||||
|
||||
// Option
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "option_description` WHERE `language_id` = '" . (int)$this->config->get('config_language_id') . "'");
|
||||
|
||||
foreach ($query->rows as $option) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "option_description` SET `option_id` = '" . (int)$option['option_id'] . "', `language_id` = '" . (int)$language_id . "', `name` = '" . $this->db->escape($option['name']) . "'");
|
||||
}
|
||||
|
||||
// Option Value
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "option_value_description` WHERE `language_id` = '" . (int)$this->config->get('config_language_id') . "'");
|
||||
|
||||
foreach ($query->rows as $option_value) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "option_value_description` SET `option_value_id` = '" . (int)$option_value['option_value_id'] . "', `language_id` = '" . (int)$language_id . "', `option_id` = '" . (int)$option_value['option_id'] . "', `name` = '" . $this->db->escape($option_value['name']) . "'");
|
||||
}
|
||||
|
||||
// Order Status
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "order_status` WHERE `language_id` = '" . (int)$this->config->get('config_language_id') . "'");
|
||||
|
||||
foreach ($query->rows as $order_status) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "order_status` SET `order_status_id` = '" . (int)$order_status['order_status_id'] . "', `language_id` = '" . (int)$language_id . "', `name` = '" . $this->db->escape($order_status['name']) . "'");
|
||||
}
|
||||
|
||||
$this->cache->delete('order_status');
|
||||
|
||||
// Product
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "product_description` WHERE `language_id` = '" . (int)$this->config->get('config_language_id') . "'");
|
||||
|
||||
foreach ($query->rows as $product) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "product_description` SET `product_id` = '" . (int)$product['product_id'] . "', `language_id` = '" . (int)$language_id . "', `name` = '" . $this->db->escape($product['name']) . "', `description` = '" . $this->db->escape($product['description']) . "', `tag` = '" . $this->db->escape($product['tag']) . "', `meta_title` = '" . $this->db->escape($product['meta_title']) . "', `meta_description` = '" . $this->db->escape($product['meta_description']) . "', `meta_keyword` = '" . $this->db->escape($product['meta_keyword']) . "'");
|
||||
}
|
||||
|
||||
$this->cache->delete('product');
|
||||
|
||||
// Product Attribute
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "product_attribute` WHERE `language_id` = '" . (int)$this->config->get('config_language_id') . "'");
|
||||
|
||||
foreach ($query->rows as $product_attribute) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "product_attribute` SET `product_id` = '" . (int)$product_attribute['product_id'] . "', `attribute_id` = '" . (int)$product_attribute['attribute_id'] . "', `language_id` = '" . (int)$language_id . "', `text` = '" . $this->db->escape($product_attribute['text']) . "'");
|
||||
}
|
||||
|
||||
// Return Action
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "return_action` WHERE `language_id` = '" . (int)$this->config->get('config_language_id') . "'");
|
||||
|
||||
foreach ($query->rows as $return_action) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "return_action` SET `return_action_id` = '" . (int)$return_action['return_action_id'] . "', `language_id` = '" . (int)$language_id . "', `name` = '" . $this->db->escape($return_action['name']) . "'");
|
||||
}
|
||||
|
||||
// Return Reason
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "return_reason` WHERE `language_id` = '" . (int)$this->config->get('config_language_id') . "'");
|
||||
|
||||
foreach ($query->rows as $return_reason) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "return_reason` SET `return_reason_id` = '" . (int)$return_reason['return_reason_id'] . "', `language_id` = '" . (int)$language_id . "', `name` = '" . $this->db->escape($return_reason['name']) . "'");
|
||||
}
|
||||
|
||||
// Return Status
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "return_status` WHERE `language_id` = '" . (int)$this->config->get('config_language_id') . "'");
|
||||
|
||||
foreach ($query->rows as $return_status) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "return_status` SET `return_status_id` = '" . (int)$return_status['return_status_id'] . "', `language_id` = '" . (int)$language_id . "', `name` = '" . $this->db->escape($return_status['name']) . "'");
|
||||
}
|
||||
|
||||
// Stock Status
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "stock_status` WHERE `language_id` = '" . (int)$this->config->get('config_language_id') . "'");
|
||||
|
||||
foreach ($query->rows as $stock_status) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "stock_status` SET `stock_status_id` = '" . (int)$stock_status['stock_status_id'] . "', `language_id` = '" . (int)$language_id . "', `name` = '" . $this->db->escape($stock_status['name']) . "'");
|
||||
}
|
||||
|
||||
$this->cache->delete('stock_status');
|
||||
|
||||
// Voucher Theme
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "voucher_theme_description` WHERE `language_id` = '" . (int)$this->config->get('config_language_id') . "'");
|
||||
|
||||
foreach ($query->rows as $voucher_theme) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "voucher_theme_description` SET `voucher_theme_id` = '" . (int)$voucher_theme['voucher_theme_id'] . "', `language_id` = '" . (int)$language_id . "', `name` = '" . $this->db->escape($voucher_theme['name']) . "'");
|
||||
}
|
||||
|
||||
$this->cache->delete('voucher_theme');
|
||||
|
||||
// Weight Class
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "weight_class_description` WHERE `language_id` = '" . (int)$this->config->get('config_language_id') . "'");
|
||||
|
||||
foreach ($query->rows as $weight_class) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "weight_class_description` SET `weight_class_id` = '" . (int)$weight_class['weight_class_id'] . "', `language_id` = '" . (int)$language_id . "', `title` = '" . $this->db->escape($weight_class['title']) . "', `unit` = '" . $this->db->escape($weight_class['unit']) . "'");
|
||||
}
|
||||
|
||||
$this->cache->delete('weight_class');
|
||||
|
||||
// Subscription
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "subscription_status` WHERE `language_id` = '" . (int)$this->config->get('config_language_id') . "'");
|
||||
|
||||
foreach ($query->rows as $subscription) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "subscription_status` SET `subscription_status_id` = '" . (int)$subscription['subscription_status_id'] . "', `language_id` = '" . (int)$language_id . "', `name` = '" . $this->db->escape($subscription['name']) . "'");
|
||||
}
|
||||
|
||||
// SEO URL
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "seo_url` WHERE `language_id` = '" . (int)$this->config->get('config_language_id') . "'");
|
||||
|
||||
foreach ($query->rows as $seo_url) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "seo_url` SET `store_id` = '" . (int)$seo_url['store_id'] . "', `language_id` = '" . (int)$language_id . "', `key` = '" . $this->db->escape($seo_url['key']) . "', `value` = '" . $this->db->escape($seo_url['value']) . "', `keyword` = '" . $this->db->escape($seo_url['keyword']) . "', `sort_order` = '" . (int)$seo_url['sort_order'] . "'");
|
||||
}
|
||||
|
||||
return $language_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $language_id
|
||||
* @param array $data
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function editLanguage(int $language_id, array $data): void {
|
||||
$this->db->query("UPDATE `" . DB_PREFIX . "language` SET `name` = '" . $this->db->escape((string)$data['name']) . "', `code` = '" . $this->db->escape((string)$data['code']) . "', `locale` = '" . $this->db->escape((string)$data['locale']) . "', `extension` = '" . $this->db->escape((string)$data['extension']) . "', `sort_order` = '" . (int)$data['sort_order'] . "', `status` = '" . (bool)(isset($data['status']) ? $data['status'] : 0) . "' WHERE `language_id` = '" . (int)$language_id . "'");
|
||||
|
||||
$this->cache->delete('language');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $language_id
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function deleteLanguage(int $language_id): void {
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "language` WHERE `language_id` = '" . (int)$language_id . "'");
|
||||
|
||||
$this->cache->delete('language');
|
||||
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "attribute_description` WHERE `language_id` = '" . (int)$language_id . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "attribute_group_description` WHERE `language_id` = '" . (int)$language_id . "'");
|
||||
|
||||
$this->cache->delete('attribute');
|
||||
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "banner_image` WHERE `language_id` = '" . (int)$language_id . "'");
|
||||
|
||||
$this->cache->delete('banner');
|
||||
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "category_description` WHERE `language_id` = '" . (int)$language_id . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "customer_group_description` WHERE `language_id` = '" . (int)$language_id . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "custom_field_description` WHERE `language_id` = '" . (int)$language_id . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "custom_field_value_description` WHERE `language_id` = '" . (int)$language_id . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "download_description` WHERE `language_id` = '" . (int)$language_id . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "filter_description` WHERE `language_id` = '" . (int)$language_id . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "filter_group_description` WHERE `language_id` = '" . (int)$language_id . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "information_description` WHERE `language_id` = '" . (int)$language_id . "'");
|
||||
|
||||
$this->cache->delete('information');
|
||||
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "length_class_description` WHERE `language_id` = '" . (int)$language_id . "'");
|
||||
|
||||
$this->cache->delete('length_class');
|
||||
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "option_description` WHERE `language_id` = '" . (int)$language_id . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "option_value_description` WHERE `language_id` = '" . (int)$language_id . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "order_status` WHERE `language_id` = '" . (int)$language_id . "'");
|
||||
|
||||
$this->cache->delete('order_status');
|
||||
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "product_description` WHERE `language_id` = '" . (int)$language_id . "'");
|
||||
|
||||
$this->cache->delete('product');
|
||||
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "product_attribute` WHERE `language_id` = '" . (int)$language_id . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "return_action` WHERE `language_id` = '" . (int)$language_id . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "return_reason` WHERE `language_id` = '" . (int)$language_id . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "return_status` WHERE `language_id` = '" . (int)$language_id . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "stock_status` WHERE `language_id` = '" . (int)$language_id . "'");
|
||||
|
||||
$this->cache->delete('stock_status');
|
||||
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "voucher_theme_description` WHERE `language_id` = '" . (int)$language_id . "'");
|
||||
|
||||
$this->cache->delete('voucher_theme');
|
||||
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "weight_class_description` WHERE `language_id` = '" . (int)$language_id . "'");
|
||||
|
||||
$this->cache->delete('weight_class');
|
||||
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "subscription_status` WHERE `language_id` = '" . (int)$language_id . "'");
|
||||
|
||||
$this->cache->delete('subscription_status');
|
||||
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "seo_url` WHERE `language_id` = '" . (int)$language_id . "'");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $language_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getLanguage(int $language_id): array {
|
||||
$query = $this->db->query("SELECT DISTINCT * FROM `" . DB_PREFIX . "language` WHERE `language_id` = '" . (int)$language_id . "'");
|
||||
|
||||
$language = $query->row;
|
||||
|
||||
if ($language) {
|
||||
$language['image'] = HTTP_CATALOG;
|
||||
|
||||
if (!$language['extension']) {
|
||||
$language['image'] .= 'catalog/';
|
||||
} else {
|
||||
$language['image'] .= 'extension/' . $language['extension'] . '/catalog/';
|
||||
}
|
||||
|
||||
$language['image'] .= 'language/' . $language['code'] . '/' . $language['code'] . '.png';
|
||||
}
|
||||
|
||||
return $language;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $code
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getLanguageByCode(string $code): array {
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "language` WHERE `code` = '" . $this->db->escape($code) . "'");
|
||||
|
||||
$language = $query->row;
|
||||
|
||||
if ($language) {
|
||||
$language['image'] = HTTP_CATALOG;
|
||||
|
||||
if (!$language['extension']) {
|
||||
$language['image'] .= 'catalog/';
|
||||
} else {
|
||||
$language['image'] .= 'extension/' . $language['extension'] . '/catalog/';
|
||||
}
|
||||
|
||||
$language['image'] .= 'language/' . $language['code'] . '/' . $language['code'] . '.png';
|
||||
}
|
||||
|
||||
return $language;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getLanguages(array $data = []): array {
|
||||
$sql = "SELECT * FROM `" . DB_PREFIX . "language`";
|
||||
|
||||
$sort_data = [
|
||||
'name',
|
||||
'code',
|
||||
'sort_order'
|
||||
];
|
||||
|
||||
if (isset($data['sort']) && in_array($data['sort'], $sort_data)) {
|
||||
$sql .= " ORDER BY " . $data['sort'];
|
||||
} else {
|
||||
$sql .= " ORDER BY `sort_order`, `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'];
|
||||
}
|
||||
|
||||
$results = (array)$this->cache->get('language.' . md5($sql));
|
||||
|
||||
if (!$results) {
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
$results = $query->rows;
|
||||
|
||||
$this->cache->set('language.' . md5($sql), $results);
|
||||
}
|
||||
|
||||
$language_data = [];
|
||||
|
||||
foreach ($results as $result) {
|
||||
$image = HTTP_CATALOG;
|
||||
|
||||
if (!$result['extension']) {
|
||||
$image .= 'catalog/';
|
||||
} else {
|
||||
$image .= 'extension/' . $result['extension'] . '/catalog/';
|
||||
}
|
||||
|
||||
$language_data[$result['code']] = [
|
||||
'language_id' => $result['language_id'],
|
||||
'name' => $result['name'],
|
||||
'code' => $result['code'],
|
||||
'image' => $image . 'language/' . $result['code'] . '/' . $result['code'] . '.png',
|
||||
'locale' => $result['locale'],
|
||||
'extension' => $result['extension'],
|
||||
'sort_order' => $result['sort_order'],
|
||||
'status' => $result['status']
|
||||
];
|
||||
}
|
||||
|
||||
return $language_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalLanguages(): int {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "language`");
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
}
|
159
admininistrator/model/localisation/length_class.php
Normal file
159
admininistrator/model/localisation/length_class.php
Normal file
@ -0,0 +1,159 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Model\Localisation;
|
||||
/**
|
||||
* Class Length Class
|
||||
*
|
||||
* @package Opencart\Admin\Model\Localisation
|
||||
*/
|
||||
class LengthClass extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function addLengthClass(array $data): int {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "length_class` SET `value` = '" . (float)$data['value'] . "'");
|
||||
|
||||
$length_class_id = $this->db->getLastId();
|
||||
|
||||
foreach ($data['length_class_description'] as $language_id => $value) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "length_class_description` SET `length_class_id` = '" . (int)$length_class_id . "', `language_id` = '" . (int)$language_id . "', `title` = '" . $this->db->escape($value['title']) . "', `unit` = '" . $this->db->escape($value['unit']) . "'");
|
||||
}
|
||||
|
||||
$this->cache->delete('length_class');
|
||||
|
||||
return $length_class_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $length_class_id
|
||||
* @param array $data
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function editLengthClass(int $length_class_id, array $data): void {
|
||||
$this->db->query("UPDATE `" . DB_PREFIX . "length_class` SET `value` = '" . (float)$data['value'] . "' WHERE `length_class_id` = '" . (int)$length_class_id . "'");
|
||||
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "length_class_description` WHERE `length_class_id` = '" . (int)$length_class_id . "'");
|
||||
|
||||
foreach ($data['length_class_description'] as $language_id => $value) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "length_class_description` SET `length_class_id` = '" . (int)$length_class_id . "', `language_id` = '" . (int)$language_id . "', `title` = '" . $this->db->escape($value['title']) . "', `unit` = '" . $this->db->escape($value['unit']) . "'");
|
||||
}
|
||||
|
||||
$this->cache->delete('length_class');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $length_class_id
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function deleteLengthClass(int $length_class_id): void {
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "length_class` WHERE `length_class_id` = '" . (int)$length_class_id . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "length_class_description` WHERE `length_class_id` = '" . (int)$length_class_id . "'");
|
||||
|
||||
$this->cache->delete('length_class');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getLengthClasses(array $data = []): array {
|
||||
$sql = "SELECT * FROM `" . DB_PREFIX . "length_class` lc LEFT JOIN `" . DB_PREFIX . "length_class_description` lcd ON (lc.`length_class_id` = lcd.`length_class_id`) WHERE lcd.`language_id` = '" . (int)$this->config->get('config_language_id') . "'";
|
||||
|
||||
$sort_data = [
|
||||
'title',
|
||||
'unit',
|
||||
'value'
|
||||
];
|
||||
|
||||
if (isset($data['sort']) && in_array($data['sort'], $sort_data)) {
|
||||
$sql .= " ORDER BY " . $data['sort'];
|
||||
} else {
|
||||
$sql .= " ORDER BY `title`";
|
||||
}
|
||||
|
||||
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'];
|
||||
}
|
||||
|
||||
$length_class_data = $this->cache->get('length_class.' . md5($sql));
|
||||
|
||||
if (!$length_class_data) {
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
$length_class_data = $query->rows;
|
||||
|
||||
$this->cache->set('length_class.' . md5($sql), $length_class_data);
|
||||
}
|
||||
|
||||
return $length_class_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $length_class_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getLengthClass(int $length_class_id): array {
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "length_class` lc LEFT JOIN `" . DB_PREFIX . "length_class_description` lcd ON (lc.`length_class_id` = lcd.`length_class_id`) WHERE lc.`length_class_id` = '" . (int)$length_class_id . "' AND lcd.`language_id` = '" . (int)$this->config->get('config_language_id') . "'");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $unit
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getDescriptionByUnit(string $unit): array {
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "length_class_description` WHERE `unit` = '" . $this->db->escape($unit) . "' AND `language_id` = '" . (int)$this->config->get('config_language_id') . "'");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $length_class_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getDescriptions(int $length_class_id): array {
|
||||
$length_class_data = [];
|
||||
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "length_class_description` WHERE `length_class_id` = '" . (int)$length_class_id . "'");
|
||||
|
||||
foreach ($query->rows as $result) {
|
||||
$length_class_data[$result['language_id']] = [
|
||||
'title' => $result['title'],
|
||||
'unit' => $result['unit']
|
||||
];
|
||||
}
|
||||
|
||||
return $length_class_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalLengthClasses(): int {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "length_class`");
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
}
|
100
admininistrator/model/localisation/location.php
Normal file
100
admininistrator/model/localisation/location.php
Normal file
@ -0,0 +1,100 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Model\Localisation;
|
||||
/**
|
||||
* Class Location
|
||||
*
|
||||
* @package Opencart\Admin\Model\Localisation
|
||||
*/
|
||||
class Location extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function addLocation(array $data): int {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "location` SET `name` = '" . $this->db->escape((string)$data['name']) . "', address = '" . $this->db->escape((string)$data['address']) . "', `geocode` = '" . $this->db->escape((string)$data['geocode']) . "', `telephone` = '" . $this->db->escape((string)$data['telephone']) . "', `image` = '" . $this->db->escape((string)$data['image']) . "', `open` = '" . $this->db->escape((string)$data['open']) . "', `comment` = '" . $this->db->escape((string)$data['comment']) . "'");
|
||||
|
||||
return $this->db->getLastId();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $location_id
|
||||
* @param array $data
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function editLocation(int $location_id, array $data): void {
|
||||
$this->db->query("UPDATE `" . DB_PREFIX . "location` SET `name` = '" . $this->db->escape((string)$data['name']) . "', `address` = '" . $this->db->escape((string)$data['address']) . "', `geocode` = '" . $this->db->escape((string)$data['geocode']) . "', `telephone` = '" . $this->db->escape((string)$data['telephone']) . "', `image` = '" . $this->db->escape((string)$data['image']) . "', `open` = '" . $this->db->escape((string)$data['open']) . "', `comment` = '" . $this->db->escape((string)$data['comment']) . "' WHERE `location_id` = '" . (int)$location_id . "'");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $location_id
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function deleteLocation(int $location_id): void {
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "location` WHERE `location_id` = '" . (int)$location_id . "'");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $location_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getLocation(int $location_id): array {
|
||||
$query = $this->db->query("SELECT DISTINCT * FROM `" . DB_PREFIX . "location` WHERE `location_id` = '" . (int)$location_id . "'");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getLocations(array $data = []): array {
|
||||
$sql = "SELECT `location_id`, `name`, `address` FROM `" . DB_PREFIX . "location`";
|
||||
|
||||
$sort_data = [
|
||||
'name',
|
||||
'address',
|
||||
];
|
||||
|
||||
if (isset($data['sort']) && in_array($data['sort'], $sort_data)) {
|
||||
$sql .= " ORDER BY " . $data['sort'];
|
||||
} else {
|
||||
$sql .= " ORDER BY `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'];
|
||||
}
|
||||
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
return $query->rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalLocations(): int {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "location`");
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
}
|
132
admininistrator/model/localisation/order_status.php
Normal file
132
admininistrator/model/localisation/order_status.php
Normal file
@ -0,0 +1,132 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Model\Localisation;
|
||||
/**
|
||||
* Class OrderStatus
|
||||
*
|
||||
* @package Opencart\Admin\Model\Localisation
|
||||
*/
|
||||
class OrderStatus extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function addOrderStatus(array $data): int {
|
||||
foreach ($data['order_status'] as $language_id => $value) {
|
||||
if (isset($order_status_id)) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "order_status` SET `order_status_id` = '" . (int)$order_status_id . "', `language_id` = '" . (int)$language_id . "', `name` = '" . $this->db->escape($value['name']) . "'");
|
||||
} else {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "order_status` SET `language_id` = '" . (int)$language_id . "', `name` = '" . $this->db->escape($value['name']) . "'");
|
||||
|
||||
$order_status_id = $this->db->getLastId();
|
||||
}
|
||||
}
|
||||
|
||||
$this->cache->delete('order_status');
|
||||
|
||||
return $order_status_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $order_status_id
|
||||
* @param array $data
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function editOrderStatus(int $order_status_id, array $data): void {
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "order_status` WHERE `order_status_id` = '" . (int)$order_status_id . "'");
|
||||
|
||||
foreach ($data['order_status'] as $language_id => $value) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "order_status` SET `order_status_id` = '" . (int)$order_status_id . "', `language_id` = '" . (int)$language_id . "', `name` = '" . $this->db->escape($value['name']) . "'");
|
||||
}
|
||||
|
||||
$this->cache->delete('order_status');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $order_status_id
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function deleteOrderStatus(int $order_status_id): void {
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "order_status` WHERE `order_status_id` = '" . (int)$order_status_id . "'");
|
||||
|
||||
$this->cache->delete('order_status');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $order_status_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getOrderStatus(int $order_status_id): array {
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "order_status` WHERE `order_status_id` = '" . (int)$order_status_id . "' AND `language_id` = '" . (int)$this->config->get('config_language_id') . "'");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getOrderStatuses(array $data = []): array {
|
||||
$sql = "SELECT * FROM `" . DB_PREFIX . "order_status` WHERE `language_id` = '" . (int)$this->config->get('config_language_id') . "' ORDER BY `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'];
|
||||
}
|
||||
|
||||
$order_status_data = $this->cache->get('order_status.' . md5($sql));
|
||||
|
||||
if (!$order_status_data) {
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
$order_status_data = $query->rows;
|
||||
|
||||
$this->cache->set('order_status.' . md5($sql), $order_status_data);
|
||||
}
|
||||
|
||||
return $order_status_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $order_status_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getDescriptions(int $order_status_id): array {
|
||||
$order_status_data = [];
|
||||
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "order_status` WHERE `order_status_id` = '" . (int)$order_status_id . "'");
|
||||
|
||||
foreach ($query->rows as $result) {
|
||||
$order_status_data[$result['language_id']] = ['name' => $result['name']];
|
||||
}
|
||||
|
||||
return $order_status_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalOrderStatuses(): int {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "order_status` WHERE `language_id` = '" . (int)$this->config->get('config_language_id') . "'");
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
}
|
132
admininistrator/model/localisation/return_action.php
Normal file
132
admininistrator/model/localisation/return_action.php
Normal file
@ -0,0 +1,132 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Model\Localisation;
|
||||
/**
|
||||
* Class ReturnAction
|
||||
*
|
||||
* @package Opencart\Admin\Model\Localisation
|
||||
*/
|
||||
class ReturnAction extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function addReturnAction(array $data): int {
|
||||
foreach ($data['return_action'] as $language_id => $value) {
|
||||
if (isset($return_action_id)) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "return_action` SET `return_action_id` = '" . (int)$return_action_id . "', `language_id` = '" . (int)$language_id . "', `name` = '" . $this->db->escape($value['name']) . "'");
|
||||
} else {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "return_action` SET `language_id` = '" . (int)$language_id . "', `name` = '" . $this->db->escape($value['name']) . "'");
|
||||
|
||||
$return_action_id = $this->db->getLastId();
|
||||
}
|
||||
}
|
||||
|
||||
$this->cache->delete('return_action');
|
||||
|
||||
return $return_action_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $return_action_id
|
||||
* @param array $data
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function editReturnAction(int $return_action_id, array $data): void {
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "return_action` WHERE `return_action_id` = '" . (int)$return_action_id . "'");
|
||||
|
||||
foreach ($data['return_action'] as $language_id => $value) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "return_action` SET `return_action_id` = '" . (int)$return_action_id . "', `language_id` = '" . (int)$language_id . "', `name` = '" . $this->db->escape($value['name']) . "'");
|
||||
}
|
||||
|
||||
$this->cache->delete('return_action');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $return_action_id
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function deleteReturnAction(int $return_action_id): void {
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "return_action` WHERE `return_action_id` = '" . (int)$return_action_id . "'");
|
||||
|
||||
$this->cache->delete('return_action');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $return_action_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getReturnAction(int $return_action_id): array {
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "return_action` WHERE `return_action_id` = '" . (int)$return_action_id . "' AND `language_id` = '" . (int)$this->config->get('config_language_id') . "'");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getReturnActions(array $data = []): array {
|
||||
$sql = "SELECT * FROM `" . DB_PREFIX . "return_action` WHERE `language_id` = '" . (int)$this->config->get('config_language_id') . "' ORDER BY `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'];
|
||||
}
|
||||
|
||||
$return_action_data = $this->cache->get('return_action.' . md5($sql));
|
||||
|
||||
if (!$return_action_data) {
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
$return_action_data = $query->rows;
|
||||
|
||||
$this->cache->set('return_action.' . md5($sql), $return_action_data);
|
||||
}
|
||||
|
||||
return $return_action_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $return_action_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getDescriptions(int $return_action_id): array {
|
||||
$return_action_data = [];
|
||||
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "return_action` WHERE `return_action_id` = '" . (int)$return_action_id . "'");
|
||||
|
||||
foreach ($query->rows as $result) {
|
||||
$return_action_data[$result['language_id']] = ['name' => $result['name']];
|
||||
}
|
||||
|
||||
return $return_action_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalReturnActions(): int {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "return_action` WHERE `language_id` = '" . (int)$this->config->get('config_language_id') . "'");
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
}
|
132
admininistrator/model/localisation/return_reason.php
Normal file
132
admininistrator/model/localisation/return_reason.php
Normal file
@ -0,0 +1,132 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Model\Localisation;
|
||||
/**
|
||||
* Class ReturnReason
|
||||
*
|
||||
* @package Opencart\Admin\Model\Localisation
|
||||
*/
|
||||
class ReturnReason extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function addReturnReason(array $data): int {
|
||||
foreach ($data['return_reason'] as $language_id => $value) {
|
||||
if (isset($return_reason_id)) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "return_reason` SET `return_reason_id` = '" . (int)$return_reason_id . "', `language_id` = '" . (int)$language_id . "', `name` = '" . $this->db->escape($value['name']) . "'");
|
||||
} else {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "return_reason` SET `language_id` = '" . (int)$language_id . "', `name` = '" . $this->db->escape($value['name']) . "'");
|
||||
|
||||
$return_reason_id = $this->db->getLastId();
|
||||
}
|
||||
}
|
||||
|
||||
$this->cache->delete('return_reason');
|
||||
|
||||
return $return_reason_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $return_reason_id
|
||||
* @param array $data
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function editReturnReason(int $return_reason_id, array $data): void {
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "return_reason` WHERE `return_reason_id` = '" . (int)$return_reason_id . "'");
|
||||
|
||||
foreach ($data['return_reason'] as $language_id => $value) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "return_reason` SET `return_reason_id` = '" . (int)$return_reason_id . "', `language_id` = '" . (int)$language_id . "', `name` = '" . $this->db->escape($value['name']) . "'");
|
||||
}
|
||||
|
||||
$this->cache->delete('return_reason');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $return_reason_id
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function deleteReturnReason(int $return_reason_id): void {
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "return_reason` WHERE `return_reason_id` = '" . (int)$return_reason_id . "'");
|
||||
|
||||
$this->cache->delete('return_reason');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $return_reason_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getReturnReason(int $return_reason_id): array {
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "return_reason` WHERE `return_reason_id` = '" . (int)$return_reason_id . "' AND `language_id` = '" . (int)$this->config->get('config_language_id') . "'");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getReturnReasons(array $data = []): array {
|
||||
$sql = "SELECT * FROM `" . DB_PREFIX . "return_reason` WHERE `language_id` = '" . (int)$this->config->get('config_language_id') . "' ORDER BY `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'];
|
||||
}
|
||||
|
||||
$return_reason_data = $this->cache->get('return_reason.' . md5($sql));
|
||||
|
||||
if (!$return_reason_data) {
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
$return_reason_data = $query->rows;
|
||||
|
||||
$this->cache->set('return_reason.' . md5($sql), $return_reason_data);
|
||||
}
|
||||
|
||||
return $return_reason_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $return_reason_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getDescriptions(int $return_reason_id): array {
|
||||
$return_reason_data = [];
|
||||
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "return_reason` WHERE `return_reason_id` = '" . (int)$return_reason_id . "'");
|
||||
|
||||
foreach ($query->rows as $result) {
|
||||
$return_reason_data[$result['language_id']] = ['name' => $result['name']];
|
||||
}
|
||||
|
||||
return $return_reason_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalReturnReasons(): int {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "return_reason` WHERE `language_id` = '" . (int)$this->config->get('config_language_id') . "'");
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
}
|
132
admininistrator/model/localisation/return_status.php
Normal file
132
admininistrator/model/localisation/return_status.php
Normal file
@ -0,0 +1,132 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Model\Localisation;
|
||||
/**
|
||||
* Class ReturnStatus
|
||||
*
|
||||
* @package Opencart\Admin\Model\Localisation
|
||||
*/
|
||||
class ReturnStatus extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function addReturnStatus(array $data): int {
|
||||
foreach ($data['return_status'] as $language_id => $value) {
|
||||
if (isset($return_status_id)) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "return_status` SET `return_status_id` = '" . (int)$return_status_id . "', `language_id` = '" . (int)$language_id . "', `name` = '" . $this->db->escape($value['name']) . "'");
|
||||
} else {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "return_status` SET `language_id` = '" . (int)$language_id . "', `name` = '" . $this->db->escape($value['name']) . "'");
|
||||
|
||||
$return_status_id = $this->db->getLastId();
|
||||
}
|
||||
}
|
||||
|
||||
$this->cache->delete('return_status');
|
||||
|
||||
return $return_status_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $return_status_id
|
||||
* @param array $data
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function editReturnStatus(int $return_status_id, array $data) : void{
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "return_status` WHERE `return_status_id` = '" . (int)$return_status_id . "'");
|
||||
|
||||
foreach ($data['return_status'] as $language_id => $value) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "return_status` SET `return_status_id` = '" . (int)$return_status_id . "', `language_id` = '" . (int)$language_id . "', `name` = '" . $this->db->escape($value['name']) . "'");
|
||||
}
|
||||
|
||||
$this->cache->delete('return_status');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $return_status_id
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function deleteReturnStatus(int $return_status_id): void {
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "return_status` WHERE `return_status_id` = '" . (int)$return_status_id . "'");
|
||||
|
||||
$this->cache->delete('return_status');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $return_status_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getReturnStatus(int $return_status_id): array {
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "return_status` WHERE `return_status_id` = '" . (int)$return_status_id . "' AND `language_id` = '" . (int)$this->config->get('config_language_id') . "'");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getReturnStatuses(array $data = []): array {
|
||||
$sql = "SELECT * FROM `" . DB_PREFIX . "return_status` WHERE `language_id` = '" . (int)$this->config->get('config_language_id') . "' ORDER BY `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'];
|
||||
}
|
||||
|
||||
$return_status_data = $this->cache->get('return_status.' . md5($sql));
|
||||
|
||||
if (!$return_status_data) {
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
$return_status_data = $query->rows;
|
||||
|
||||
$this->cache->set('return_status.' . md5($sql), $return_status_data);
|
||||
}
|
||||
|
||||
return $return_status_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $return_status_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getDescriptions(int $return_status_id): array {
|
||||
$return_status_data = [];
|
||||
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "return_status` WHERE `return_status_id` = '" . (int)$return_status_id . "'");
|
||||
|
||||
foreach ($query->rows as $result) {
|
||||
$return_status_data[$result['language_id']] = ['name' => $result['name']];
|
||||
}
|
||||
|
||||
return $return_status_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalReturnStatuses(): int {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "return_status` WHERE `language_id` = '" . (int)$this->config->get('config_language_id') . "'");
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
}
|
132
admininistrator/model/localisation/stock_status.php
Normal file
132
admininistrator/model/localisation/stock_status.php
Normal file
@ -0,0 +1,132 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Model\Localisation;
|
||||
/**
|
||||
* Class StockStatus
|
||||
*
|
||||
* @package Opencart\Admin\Model\Localisation
|
||||
*/
|
||||
class StockStatus extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function addStockStatus(array $data): int {
|
||||
foreach ($data['stock_status'] as $language_id => $value) {
|
||||
if (isset($stock_status_id)) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "stock_status` SET `stock_status_id` = '" . (int)$stock_status_id . "', `language_id` = '" . (int)$language_id . "', `name` = '" . $this->db->escape($value['name']) . "'");
|
||||
} else {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "stock_status` SET `language_id` = '" . (int)$language_id . "', `name` = '" . $this->db->escape($value['name']) . "'");
|
||||
|
||||
$stock_status_id = $this->db->getLastId();
|
||||
}
|
||||
}
|
||||
|
||||
$this->cache->delete('stock_status');
|
||||
|
||||
return $stock_status_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $stock_status_id
|
||||
* @param array $data
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function editStockStatus(int $stock_status_id, array $data): void {
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "stock_status` WHERE `stock_status_id` = '" . (int)$stock_status_id . "'");
|
||||
|
||||
foreach ($data['stock_status'] as $language_id => $value) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "stock_status` SET `stock_status_id` = '" . (int)$stock_status_id . "', `language_id` = '" . (int)$language_id . "', `name` = '" . $this->db->escape($value['name']) . "'");
|
||||
}
|
||||
|
||||
$this->cache->delete('stock_status');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $stock_status_id
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function deleteStockStatus(int $stock_status_id): void {
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "stock_status` WHERE `stock_status_id` = '" . (int)$stock_status_id . "'");
|
||||
|
||||
$this->cache->delete('stock_status');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $stock_status_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getStockStatus(int $stock_status_id): array {
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "stock_status` WHERE `stock_status_id` = '" . (int)$stock_status_id . "' AND `language_id` = '" . (int)$this->config->get('config_language_id') . "'");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getStockStatuses(array $data = []): array {
|
||||
$sql = "SELECT * FROM `" . DB_PREFIX . "stock_status` WHERE `language_id` = '" . (int)$this->config->get('config_language_id') . "' ORDER BY `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'];
|
||||
}
|
||||
|
||||
$stock_status_data = $this->cache->get('stock_status.' . md5($sql));
|
||||
|
||||
if (!$stock_status_data) {
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
$stock_status_data = $query->rows;
|
||||
|
||||
$this->cache->set('stock_status.' . md5($sql), $stock_status_data);
|
||||
}
|
||||
|
||||
return $stock_status_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $stock_status_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getDescriptions(int $stock_status_id): array {
|
||||
$stock_status_data = [];
|
||||
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "stock_status` WHERE `stock_status_id` = '" . (int)$stock_status_id . "'");
|
||||
|
||||
foreach ($query->rows as $result) {
|
||||
$stock_status_data[$result['language_id']] = ['name' => $result['name']];
|
||||
}
|
||||
|
||||
return $stock_status_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalStockStatuses(): int {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "stock_status` WHERE `language_id` = '" . (int)$this->config->get('config_language_id') . "'");
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
}
|
132
admininistrator/model/localisation/subscription_status.php
Normal file
132
admininistrator/model/localisation/subscription_status.php
Normal file
@ -0,0 +1,132 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Model\Localisation;
|
||||
/**
|
||||
* Class SubscriptionStatus
|
||||
*
|
||||
* @package Opencart\Admin\Model\Localisation
|
||||
*/
|
||||
class SubscriptionStatus extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function addSubscriptionStatus(array $data): int {
|
||||
foreach ($data['subscription_status'] as $language_id => $value) {
|
||||
if (isset($subscription_status_id)) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "subscription_status` SET `subscription_status_id` = '" . (int)$subscription_status_id . "', `language_id` = '" . (int)$language_id . "', `name` = '" . $this->db->escape($value['name']) . "'");
|
||||
} else {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "subscription_status` SET `language_id` = '" . (int)$language_id . "', `name` = '" . $this->db->escape($value['name']) . "'");
|
||||
|
||||
$subscription_status_id = $this->db->getLastId();
|
||||
}
|
||||
}
|
||||
|
||||
$this->cache->delete('subscription_status');
|
||||
|
||||
return $subscription_status_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $subscription_status_id
|
||||
* @param array $data
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function editSubscriptionStatus(int $subscription_status_id, array $data): void {
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "subscription_status` WHERE `subscription_status_id` = '" . (int)$subscription_status_id . "'");
|
||||
|
||||
foreach ($data['subscription_status'] as $language_id => $value) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "subscription_status` SET `subscription_status_id` = '" . (int)$subscription_status_id . "', `language_id` = '" . (int)$language_id . "', `name` = '" . $this->db->escape($value['name']) . "'");
|
||||
}
|
||||
|
||||
$this->cache->delete('subscription_status');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $subscription_status_id
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function deleteSubscriptionStatus(int $subscription_status_id): void {
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "subscription_status` WHERE `subscription_status_id` = '" . (int)$subscription_status_id . "'");
|
||||
|
||||
$this->cache->delete('subscription_status');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $subscription_status_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getSubscriptionStatus(int $subscription_status_id): array {
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "subscription_status` WHERE `subscription_status_id` = '" . (int)$subscription_status_id . "' AND `language_id` = '" . (int)$this->config->get('config_language_id') . "'");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getSubscriptionStatuses(array $data = []): array {
|
||||
$sql = "SELECT * FROM `" . DB_PREFIX . "subscription_status` WHERE `language_id` = '" . (int)$this->config->get('config_language_id') . "' ORDER BY `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'];
|
||||
}
|
||||
|
||||
$subscription_status_data = $this->cache->get('subscription_status.' . md5($sql));
|
||||
|
||||
if (!$subscription_status_data) {
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
$subscription_status_data = $query->rows;
|
||||
|
||||
$this->cache->set('subscription_status.' . md5($sql), $subscription_status_data);
|
||||
}
|
||||
|
||||
return $subscription_status_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $subscription_status_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getDescriptions(int $subscription_status_id): array {
|
||||
$subscription_status_data = [];
|
||||
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "subscription_status` WHERE `subscription_status_id` = '" . (int)$subscription_status_id . "'");
|
||||
|
||||
foreach ($query->rows as $result) {
|
||||
$subscription_status_data[$result['language_id']] = ['name' => $result['name']];
|
||||
}
|
||||
|
||||
return $subscription_status_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalSubscriptionStatuses(): int {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "subscription_status` WHERE `language_id` = '" . (int)$this->config->get('config_language_id') . "'");
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
}
|
142
admininistrator/model/localisation/tax_class.php
Normal file
142
admininistrator/model/localisation/tax_class.php
Normal file
@ -0,0 +1,142 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Model\Localisation;
|
||||
/**
|
||||
* Class TaxClass
|
||||
*
|
||||
* @package Opencart\Admin\Model\Localisation
|
||||
*/
|
||||
class TaxClass extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function addTaxClass(array $data): int {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "tax_class` SET `title` = '" . $this->db->escape((string)$data['title']) . "', `description` = '" . $this->db->escape((string)$data['description']) . "', `date_added` = NOW()");
|
||||
|
||||
$tax_class_id = $this->db->getLastId();
|
||||
|
||||
if (isset($data['tax_rule'])) {
|
||||
foreach ($data['tax_rule'] as $tax_rule) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "tax_rule` SET `tax_class_id` = '" . (int)$tax_class_id . "', `tax_rate_id` = '" . (int)$tax_rule['tax_rate_id'] . "', `based` = '" . $this->db->escape($tax_rule['based']) . "', `priority` = '" . (int)$tax_rule['priority'] . "'");
|
||||
}
|
||||
}
|
||||
|
||||
$this->cache->delete('tax_class');
|
||||
|
||||
return $tax_class_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $tax_class_id
|
||||
* @param array $data
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function editTaxClass(int $tax_class_id, array $data): void {
|
||||
$this->db->query("UPDATE `" . DB_PREFIX . "tax_class` SET `title` = '" . $this->db->escape((string)$data['title']) . "', `description` = '" . $this->db->escape((string)$data['description']) . "', `date_modified` = NOW() WHERE `tax_class_id` = '" . (int)$tax_class_id . "'");
|
||||
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "tax_rule` WHERE `tax_class_id` = '" . (int)$tax_class_id . "'");
|
||||
|
||||
if (isset($data['tax_rule'])) {
|
||||
foreach ($data['tax_rule'] as $tax_rule) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "tax_rule` SET `tax_class_id` = '" . (int)$tax_class_id . "', `tax_rate_id` = '" . (int)$tax_rule['tax_rate_id'] . "', `based` = '" . $this->db->escape($tax_rule['based']) . "', `priority` = '" . (int)$tax_rule['priority'] . "'");
|
||||
}
|
||||
}
|
||||
|
||||
$this->cache->delete('tax_class');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $tax_class_id
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function deleteTaxClass(int $tax_class_id): void {
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "tax_class` WHERE `tax_class_id` = '" . (int)$tax_class_id . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "tax_rule` WHERE `tax_class_id` = '" . (int)$tax_class_id . "'");
|
||||
|
||||
$this->cache->delete('tax_class');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $tax_class_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getTaxClass(int $tax_class_id): array {
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "tax_class` WHERE `tax_class_id` = '" . (int)$tax_class_id . "'");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getTaxClasses(array $data = []): array {
|
||||
$sql = "SELECT * FROM `" . DB_PREFIX . "tax_class` ORDER BY `title`";
|
||||
|
||||
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'];
|
||||
}
|
||||
|
||||
$tax_class_data = $this->cache->get('tax_class.'. md5($sql));
|
||||
|
||||
if (!$tax_class_data) {
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
$tax_class_data = $query->rows;
|
||||
|
||||
$this->cache->set('tax_class.'. md5($sql), $tax_class_data);
|
||||
}
|
||||
|
||||
return $tax_class_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalTaxClasses(): int {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "tax_class`");
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $tax_class_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getTaxRules(int $tax_class_id): array {
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "tax_rule` WHERE `tax_class_id` = '" . (int)$tax_class_id . "' ORDER BY `priority` ASC");
|
||||
|
||||
return $query->rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $tax_rate_id
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalTaxRulesByTaxRateId(int $tax_rate_id): int {
|
||||
$query = $this->db->query("SELECT COUNT(DISTINCT `tax_class_id`) AS `total` FROM `" . DB_PREFIX . "tax_rule` WHERE `tax_rate_id` = '" . (int)$tax_rate_id . "'");
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
}
|
149
admininistrator/model/localisation/tax_rate.php
Normal file
149
admininistrator/model/localisation/tax_rate.php
Normal file
@ -0,0 +1,149 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Model\Localisation;
|
||||
/**
|
||||
* Class TaxRate
|
||||
*
|
||||
* @package Opencart\Admin\Model\Localisation
|
||||
*/
|
||||
class TaxRate extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function addTaxRate(array $data): int {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "tax_rate` SET `name` = '" . $this->db->escape((string)$data['name']) . "', `rate` = '" . (float)$data['rate'] . "', `type` = '" . $this->db->escape((string)$data['type']) . "', `geo_zone_id` = '" . (int)$data['geo_zone_id'] . "', `date_added` = NOW(), `date_modified` = NOW()");
|
||||
|
||||
$tax_rate_id = $this->db->getLastId();
|
||||
|
||||
if (isset($data['tax_rate_customer_group'])) {
|
||||
foreach ($data['tax_rate_customer_group'] as $customer_group_id) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "tax_rate_to_customer_group` SET `tax_rate_id` = '" . (int)$tax_rate_id . "', `customer_group_id` = '" . (int)$customer_group_id . "'");
|
||||
}
|
||||
}
|
||||
|
||||
return $tax_rate_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $tax_rate_id
|
||||
* @param array $data
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function editTaxRate(int $tax_rate_id, array $data): void {
|
||||
$this->db->query("UPDATE `" . DB_PREFIX . "tax_rate` SET `name` = '" . $this->db->escape((string)$data['name']) . "', `rate` = '" . (float)$data['rate'] . "', `type` = '" . $this->db->escape((string)$data['type']) . "', `geo_zone_id` = '" . (int)$data['geo_zone_id'] . "', `date_modified` = NOW() WHERE `tax_rate_id` = '" . (int)$tax_rate_id . "'");
|
||||
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "tax_rate_to_customer_group` WHERE `tax_rate_id` = '" . (int)$tax_rate_id . "'");
|
||||
|
||||
if (isset($data['tax_rate_customer_group'])) {
|
||||
foreach ($data['tax_rate_customer_group'] as $customer_group_id) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "tax_rate_to_customer_group` SET `tax_rate_id` = '" . (int)$tax_rate_id . "', `customer_group_id` = '" . (int)$customer_group_id . "'");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $tax_rate_id
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function deleteTaxRate(int $tax_rate_id): void {
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "tax_rate` WHERE `tax_rate_id` = '" . (int)$tax_rate_id . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "tax_rate_to_customer_group` WHERE `tax_rate_id` = '" . (int)$tax_rate_id . "'");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $tax_rate_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getTaxRate(int $tax_rate_id): array {
|
||||
$query = $this->db->query("SELECT tr.`tax_rate_id`, tr.`name` AS name, tr.`rate`, tr.`type`, tr.`geo_zone_id`, gz.`name` AS geo_zone, tr.`date_added`, tr.`date_modified` FROM `" . DB_PREFIX . "tax_rate` tr LEFT JOIN `" . DB_PREFIX . "geo_zone` gz ON (tr.`geo_zone_id` = gz.`geo_zone_id`) WHERE tr.`tax_rate_id` = '" . (int)$tax_rate_id . "'");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getTaxRates(array $data = []): array {
|
||||
$sql = "SELECT tr.`tax_rate_id`, tr.`name` AS name, tr.`rate`, tr.`type`, gz.`name` AS geo_zone, tr.`date_added`, tr.`date_modified` FROM `" . DB_PREFIX . "tax_rate` tr LEFT JOIN `" . DB_PREFIX . "geo_zone` gz ON (tr.`geo_zone_id` = gz.`geo_zone_id`)";
|
||||
|
||||
$sort_data = [
|
||||
'tr.name',
|
||||
'tr.rate',
|
||||
'tr.type',
|
||||
'gz.name',
|
||||
'tr.date_added',
|
||||
'tr.date_modified'
|
||||
];
|
||||
|
||||
if (isset($data['sort']) && in_array($data['sort'], $sort_data)) {
|
||||
$sql .= " ORDER BY " . $data['sort'];
|
||||
} else {
|
||||
$sql .= " ORDER BY tr.`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'];
|
||||
}
|
||||
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
return $query->rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $tax_rate_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getCustomerGroups(int $tax_rate_id): array {
|
||||
$tax_customer_group_data = [];
|
||||
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "tax_rate_to_customer_group` WHERE `tax_rate_id` = '" . (int)$tax_rate_id . "'");
|
||||
|
||||
foreach ($query->rows as $result) {
|
||||
$tax_customer_group_data[] = $result['customer_group_id'];
|
||||
}
|
||||
|
||||
return $tax_customer_group_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalTaxRates(): int {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "tax_rate`");
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $geo_zone_id
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalTaxRatesByGeoZoneId(int $geo_zone_id): int {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "tax_rate` WHERE `geo_zone_id` = '" . (int)$geo_zone_id . "'");
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
}
|
159
admininistrator/model/localisation/weight_class.php
Normal file
159
admininistrator/model/localisation/weight_class.php
Normal file
@ -0,0 +1,159 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Model\Localisation;
|
||||
/**
|
||||
* Class WeightClass
|
||||
*
|
||||
* @package Opencart\Admin\Model\Localisation
|
||||
*/
|
||||
class WeightClass extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function addWeightClass(array $data): int {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "weight_class` SET `value` = '" . (float)$data['value'] . "'");
|
||||
|
||||
$weight_class_id = $this->db->getLastId();
|
||||
|
||||
foreach ($data['weight_class_description'] as $language_id => $value) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "weight_class_description` SET `weight_class_id` = '" . (int)$weight_class_id . "', `language_id` = '" . (int)$language_id . "', `title` = '" . $this->db->escape($value['title']) . "', `unit` = '" . $this->db->escape($value['unit']) . "'");
|
||||
}
|
||||
|
||||
$this->cache->delete('weight_class');
|
||||
|
||||
return $weight_class_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $weight_class_id
|
||||
* @param array $data
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function editWeightClass(int $weight_class_id, array $data): void {
|
||||
$this->db->query("UPDATE `" . DB_PREFIX . "weight_class` SET `value` = '" . (float)$data['value'] . "' WHERE `weight_class_id` = '" . (int)$weight_class_id . "'");
|
||||
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "weight_class_description` WHERE `weight_class_id` = '" . (int)$weight_class_id . "'");
|
||||
|
||||
foreach ($data['weight_class_description'] as $language_id => $value) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "weight_class_description` SET `weight_class_id` = '" . (int)$weight_class_id . "', `language_id` = '" . (int)$language_id . "', `title` = '" . $this->db->escape($value['title']) . "', `unit` = '" . $this->db->escape($value['unit']) . "'");
|
||||
}
|
||||
|
||||
$this->cache->delete('weight_class');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $weight_class_id
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function deleteWeightClass(int $weight_class_id): void {
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "weight_class` WHERE `weight_class_id` = '" . (int)$weight_class_id . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "weight_class_description` WHERE `weight_class_id` = '" . (int)$weight_class_id . "'");
|
||||
|
||||
$this->cache->delete('weight_class');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getWeightClasses(array $data = []): array {
|
||||
$sql = "SELECT * FROM `" . DB_PREFIX . "weight_class` wc LEFT JOIN `" . DB_PREFIX . "weight_class_description` wcd ON (wc.`weight_class_id` = wcd.`weight_class_id`) WHERE wcd.`language_id` = '" . (int)$this->config->get('config_language_id') . "'";
|
||||
|
||||
$sort_data = [
|
||||
'title',
|
||||
'unit',
|
||||
'value'
|
||||
];
|
||||
|
||||
if (isset($data['sort']) && in_array($data['sort'], $sort_data)) {
|
||||
$sql .= " ORDER BY " . $data['sort'];
|
||||
} else {
|
||||
$sql .= " ORDER BY `title`";
|
||||
}
|
||||
|
||||
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'];
|
||||
}
|
||||
|
||||
$weight_class_data = $this->cache->get('weight_class.' . md5($sql));
|
||||
|
||||
if (!$weight_class_data) {
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
$weight_class_data = $query->rows;
|
||||
|
||||
$this->cache->set('weight_class.' . md5($sql), $weight_class_data);
|
||||
}
|
||||
|
||||
return $weight_class_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $weight_class_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getWeightClass(int $weight_class_id): array {
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "weight_class` wc LEFT JOIN `" . DB_PREFIX . "weight_class_description` wcd ON (wc.`weight_class_id` = wcd.`weight_class_id`) WHERE wc.`weight_class_id` = '" . (int)$weight_class_id . "' AND wcd.`language_id` = '" . (int)$this->config->get('config_language_id') . "'");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $unit
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getDescriptionByUnit(string $unit): array {
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "weight_class_description` WHERE `unit` = '" . $this->db->escape($unit) . "' AND `language_id` = '" . (int)$this->config->get('config_language_id') . "'");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $weight_class_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getDescriptions(int $weight_class_id): array {
|
||||
$weight_class_data = [];
|
||||
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "weight_class_description` WHERE `weight_class_id` = '" . (int)$weight_class_id . "'");
|
||||
|
||||
foreach ($query->rows as $result) {
|
||||
$weight_class_data[$result['language_id']] = [
|
||||
'title' => $result['title'],
|
||||
'unit' => $result['unit']
|
||||
];
|
||||
}
|
||||
|
||||
return $weight_class_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalWeightClasses(): int {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "weight_class`");
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
}
|
183
admininistrator/model/localisation/zone.php
Normal file
183
admininistrator/model/localisation/zone.php
Normal file
@ -0,0 +1,183 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Model\Localisation;
|
||||
/**
|
||||
* Class Zone
|
||||
*
|
||||
* @package Opencart\Admin\Model\Localisation
|
||||
*/
|
||||
class Zone extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function addZone(array $data): int {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "zone` SET `name` = '" . $this->db->escape((string)$data['name']) . "', `code` = '" . $this->db->escape((string)$data['code']) . "', `country_id` = '" . (int)$data['country_id'] . "', `status` = '" . (bool)(isset($data['status']) ? $data['status'] : 0) . "'");
|
||||
|
||||
$this->cache->delete('zone');
|
||||
|
||||
return $this->db->getLastId();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $zone_id
|
||||
* @param array $data
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function editZone(int $zone_id, array $data): void {
|
||||
$this->db->query("UPDATE `" . DB_PREFIX . "zone` SET `name` = '" . $this->db->escape((string)$data['name']) . "', `code` = '" . $this->db->escape((string)$data['code']) . "', `country_id` = '" . (int)$data['country_id'] . "', `status` = '" . (bool)(isset($data['status']) ? $data['status'] : 0) . "' WHERE `zone_id` = '" . (int)$zone_id . "'");
|
||||
|
||||
$this->cache->delete('zone');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $zone_id
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function deleteZone(int $zone_id): void {
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "zone` WHERE `zone_id` = '" . (int)$zone_id . "'");
|
||||
|
||||
$this->cache->delete('zone');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $zone_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getZone(int $zone_id): array {
|
||||
$query = $this->db->query("SELECT DISTINCT * FROM `" . DB_PREFIX . "zone` WHERE `zone_id` = '" . (int)$zone_id . "'");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getZones(array $data = []): array {
|
||||
$sql = "SELECT *, z.`name`, c.`name` AS country FROM `" . DB_PREFIX . "zone` z LEFT JOIN `" . DB_PREFIX . "country` c ON (z.`country_id` = c.`country_id`)";
|
||||
|
||||
$implode = [];
|
||||
|
||||
if (!empty($data['filter_name'])) {
|
||||
$implode[] = "z.`name` LIKE '" . $this->db->escape((string)$data['filter_name'] . '%') . "'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_country'])) {
|
||||
$implode[] = "c.`name` LIKE '" . $this->db->escape((string)$data['filter_country'] . '%') . "'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_code'])) {
|
||||
$implode[] = "z.`code` LIKE '" . $this->db->escape((string)$data['filter_code'] . '%') . "'";
|
||||
}
|
||||
|
||||
if ($implode) {
|
||||
$sql .= " WHERE " . implode(" AND ", $implode);
|
||||
}
|
||||
|
||||
$sort_data = [
|
||||
'c.name',
|
||||
'z.name',
|
||||
'z.code'
|
||||
];
|
||||
|
||||
if (isset($data['sort']) && in_array($data['sort'], $sort_data)) {
|
||||
$sql .= " ORDER BY " . $data['sort'];
|
||||
} else {
|
||||
$sql .= " ORDER BY c.`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'];
|
||||
}
|
||||
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
return $query->rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $country_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getZonesByCountryId(int $country_id): array {
|
||||
$sql = "SELECT * FROM `" . DB_PREFIX . "zone` WHERE `country_id` = '" . (int)$country_id . "' AND `status` = '1' ORDER BY `name`";
|
||||
|
||||
$zone_data = $this->cache->get('zone.' . md5($sql));
|
||||
|
||||
if (!$zone_data) {
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
$zone_data = $query->rows;
|
||||
|
||||
$this->cache->set('zone.' . md5($sql), $zone_data);
|
||||
}
|
||||
|
||||
return $zone_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalZones(array $data = []): int {
|
||||
$sql = "SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "zone` z";
|
||||
|
||||
if (!empty($data['filter_country'])) {
|
||||
$sql .= " LEFT JOIN `" . DB_PREFIX . "country` c ON (z.`country_id` = c.`country_id`)";
|
||||
}
|
||||
|
||||
$implode = [];
|
||||
|
||||
if (!empty($data['filter_name'])) {
|
||||
$implode[] = "z.`name` LIKE '" . $this->db->escape((string)$data['filter_name'] . '%') . "'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_country'])) {
|
||||
$implode[] = "c.`name` LIKE '" . $this->db->escape((string)$data['filter_country'] . '%') . "'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_code'])) {
|
||||
$implode[] = "z.`code` LIKE '" . $this->db->escape((string)$data['filter_code'] . '%') . "'";
|
||||
}
|
||||
|
||||
if ($implode) {
|
||||
$sql .= " WHERE " . implode(" AND ", $implode);
|
||||
}
|
||||
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $country_id
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalZonesByCountryId(int $country_id): int {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "zone` WHERE `country_id` = '" . (int)$country_id . "'");
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
}
|
227
admininistrator/model/marketing/affiliate.php
Normal file
227
admininistrator/model/marketing/affiliate.php
Normal file
@ -0,0 +1,227 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Model\Marketing;
|
||||
/**
|
||||
* Class Affiliate
|
||||
*
|
||||
* @package Opencart\Admin\Model\Marketing
|
||||
*/
|
||||
class Affiliate extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function addAffiliate(array $data): void {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "customer_affiliate` SET `customer_id` = '" . (int)$data['customer_id'] . "', `company` = '" . $this->db->escape((string)$data['company']) . "', `website` = '" . $this->db->escape((string)$data['website']) . "', `tracking` = '" . $this->db->escape((string)$data['tracking']) . "', `commission` = '" . (float)$data['commission'] . "', `tax` = '" . $this->db->escape((string)$data['tax']) . "', `payment_method` = '" . $this->db->escape((string)$data['payment_method']) . "', `cheque` = '" . $this->db->escape((string)$data['cheque']) . "', `paypal` = '" . $this->db->escape((string)$data['paypal']) . "', `bank_name` = '" . $this->db->escape((string)$data['bank_name']) . "', `bank_branch_number` = '" . $this->db->escape((string)$data['bank_branch_number']) . "', `bank_swift_code` = '" . $this->db->escape((string)$data['bank_swift_code']) . "', `bank_account_name` = '" . $this->db->escape((string)$data['bank_account_name']) . "', `bank_account_number` = '" . $this->db->escape((string)$data['bank_account_number']) . "', `custom_field` = '" . $this->db->escape(isset($data['custom_field']) ? json_encode($data['custom_field']) : json_encode([])) . "', `status` = '" . (bool)(isset($data['status']) ? $data['status'] : 0) . "', `date_added` = NOW()");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $customer_id
|
||||
* @param array $data
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function editAffiliate(int $customer_id, array $data): void {
|
||||
$this->db->query("UPDATE `" . DB_PREFIX . "customer_affiliate` SET `company` = '" . $this->db->escape((string)$data['company']) . "', `website` = '" . $this->db->escape((string)$data['website']) . "', `tracking` = '" . $this->db->escape((string)$data['tracking']) . "', `commission` = '" . (float)$data['commission'] . "', `tax` = '" . $this->db->escape((string)$data['tax']) . "', `payment_method` = '" . $this->db->escape((string)$data['payment_method']) . "', `cheque` = '" . $this->db->escape((string)$data['cheque']) . "', `paypal` = '" . $this->db->escape((string)$data['paypal']) . "', `bank_name` = '" . $this->db->escape((string)$data['bank_name']) . "', `bank_branch_number` = '" . $this->db->escape((string)$data['bank_branch_number']) . "', `bank_swift_code` = '" . $this->db->escape((string)$data['bank_swift_code']) . "', `bank_account_name` = '" . $this->db->escape((string)$data['bank_account_name']) . "', `bank_account_number` = '" . $this->db->escape((string)$data['bank_account_number']) . "', `custom_field` = '" . $this->db->escape(isset($data['custom_field']) ? json_encode($data['custom_field']) : json_encode([])) . "', `status` = '" . (bool)(isset($data['status']) ? $data['status'] : 0) . "' WHERE `customer_id` = '" . (int)$customer_id . "'");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $customer_id
|
||||
* @param float $amount
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function editBalance(int $customer_id, float $amount): void {
|
||||
$this->db->query("UPDATE `" . DB_PREFIX . "customer_affiliate` SET `balance` = '" . (float)$amount . "' WHERE `customer_id` = '" . (int)$customer_id . "'");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $customer_id
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function deleteAffiliate(int $customer_id): void {
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "customer_affiliate` WHERE `customer_id` = '" . (int)$customer_id . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "customer_affiliate_report` WHERE `customer_id` = '" . (int)$customer_id . "'");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $customer_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getAffiliate(int $customer_id): array {
|
||||
$query = $this->db->query("SELECT DISTINCT *, CONCAT(c.`firstname`, ' ', c.`lastname`) AS `customer`, ca.`custom_field` FROM `" . DB_PREFIX . "customer_affiliate` ca LEFT JOIN `" . DB_PREFIX . "customer` c ON (ca.`customer_id` = c.`customer_id`) WHERE ca.`customer_id` = '" . (int)$customer_id . "'");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $tracking
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getAffiliateByTracking(string $tracking): array {
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "customer_affiliate` WHERE `tracking` = '" . $this->db->escape($tracking) . "'");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getAffiliates(array $data = []): array {
|
||||
$sql = "SELECT *, CONCAT(`c`.`firstname`, ' ', `c`.`lastname`) AS `name`, `ca`.`status` FROM `" . DB_PREFIX . "customer_affiliate` `ca` LEFT JOIN `" . DB_PREFIX . "customer` `c` ON (`ca`.`customer_id` = `c`.`customer_id`)";
|
||||
|
||||
$implode = [];
|
||||
|
||||
if (!empty($data['filter_name'])) {
|
||||
$implode[] = "CONCAT(c.`firstname`, ' ', c.`lastname`) LIKE '" . $this->db->escape((string)$data['filter_name'] . '%') . "'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_tracking'])) {
|
||||
$implode[] = "`ca`.`tracking` = '" . $this->db->escape((string)$data['filter_tracking']) . "'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_payment_method'])) {
|
||||
$implode[] = "`ca`.`payment_method` = '" . $this->db->escape($data['filter_payment_method']) . "'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_commission'])) {
|
||||
$implode[] = "`ca`.`commission` = '" . (float)$data['filter_commission'] . "'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_date_from'])) {
|
||||
$implode[] = "DATE(`ca`.`date_added`) >= DATE('" . $this->db->escape((string)$data['filter_date_from']) . "')";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_date_to'])) {
|
||||
$implode[] = "DATE(`ca.``date_added`) <= DATE('" . $this->db->escape((string)$data['filter_date_to']) . "')";
|
||||
}
|
||||
|
||||
if (isset($data['filter_status']) && $data['filter_status'] !== '') {
|
||||
$implode[] = "`ca`.`status` = '" . (int)$data['filter_status'] . "'";
|
||||
}
|
||||
|
||||
if ($implode) {
|
||||
$sql .= " WHERE " . implode(" AND ", $implode);
|
||||
}
|
||||
|
||||
$sort_data = [
|
||||
'name',
|
||||
'ca.tracking',
|
||||
'ca.commission',
|
||||
'ca.status',
|
||||
'ca.date_added'
|
||||
];
|
||||
|
||||
if (isset($data['sort']) && in_array($data['sort'], $sort_data)) {
|
||||
$sql .= " ORDER BY " . $data['sort'];
|
||||
} else {
|
||||
$sql .= " ORDER BY `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'];
|
||||
}
|
||||
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
return $query->rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalAffiliates(array $data = []): int {
|
||||
$sql = "SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "customer_affiliate` ca LEFT JOIN `" . DB_PREFIX . "customer` c ON (ca.`customer_id` = c.`customer_id`)";
|
||||
|
||||
$implode = [];
|
||||
|
||||
if (!empty($data['filter_name'])) {
|
||||
$implode[] = "CONCAT(`c`.`firstname`, ' ', `c`.`lastname`) LIKE '" . $this->db->escape((string)$data['filter_name'] . '%') . "'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_tracking'])) {
|
||||
$implode[] = "`ca`.`tracking` = '" . $this->db->escape((string)$data['filter_tracking']) . "'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_payment_method'])) {
|
||||
$implode[] = "`ca`.`payment_method` = '" . $this->db->escape($data['filter_payment_method']) . "'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_commission'])) {
|
||||
$implode[] = "`ca`.`commission` = '" . (float)$data['filter_commission'] . "'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_date_from'])) {
|
||||
$implode[] = "DATE(`ca`.`date_added`) >= DATE('" . $this->db->escape((string)$data['filter_date_from']) . "')";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_date_to'])) {
|
||||
$implode[] = "DATE(`ca`.`date_added`) <= DATE('" . $this->db->escape((string)$data['filter_date_to']) . "')";
|
||||
}
|
||||
|
||||
if (isset($data['filter_status']) && $data['filter_status'] !== '') {
|
||||
$implode[] = "`ca`.`status` = '" . (int)$data['filter_status'] . "'";
|
||||
}
|
||||
|
||||
if ($implode) {
|
||||
$sql .= " WHERE " . implode(" AND ", $implode);
|
||||
}
|
||||
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $customer_id
|
||||
* @param int $start
|
||||
* @param int $limit
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getReports(int $customer_id, int $start = 0, int $limit = 10): array {
|
||||
if ($start < 0) {
|
||||
$start = 0;
|
||||
}
|
||||
|
||||
if ($limit < 1) {
|
||||
$limit = 10;
|
||||
}
|
||||
|
||||
$query = $this->db->query("SELECT `ip`, `store_id`, `country`, `date_added` FROM `" . DB_PREFIX . "customer_affiliate_report` WHERE `customer_id` = '" . (int)$customer_id . "' ORDER BY `date_added` ASC LIMIT " . (int)$start . "," . (int)$limit);
|
||||
|
||||
return $query->rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $customer_id
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalReports(int $customer_id): int {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "customer_affiliate_report` WHERE `customer_id` = '" . (int)$customer_id . "'");
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
}
|
214
admininistrator/model/marketing/coupon.php
Normal file
214
admininistrator/model/marketing/coupon.php
Normal file
@ -0,0 +1,214 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Model\Marketing;
|
||||
/**
|
||||
* Class Coupon
|
||||
*
|
||||
* @package Opencart\Admin\Model\Marketing
|
||||
*/
|
||||
class Coupon extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function addCoupon(array $data): int {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "coupon` SET `name` = '" . $this->db->escape((string)$data['name']) . "', `code` = '" . $this->db->escape((string)$data['code']) . "', `discount` = '" . (float)$data['discount'] . "', `type` = '" . $this->db->escape((string)$data['type']) . "', `total` = '" . (float)$data['total'] . "', `logged` = '" . (isset($data['logged']) ? (bool)$data['logged'] : 0) . "', `shipping` = '" . (isset($data['shipping']) ? (bool)$data['shipping'] : 0) . "', `date_start` = '" . $this->db->escape((string)$data['date_start']) . "', `date_end` = '" . $this->db->escape((string)$data['date_end']) . "', `uses_total` = '" . (int)$data['uses_total'] . "', `uses_customer` = '" . (int)$data['uses_customer'] . "', `status` = '" . (bool)(isset($data['status']) ? $data['status'] : 0) . "', `date_added` = NOW()");
|
||||
|
||||
$coupon_id = $this->db->getLastId();
|
||||
|
||||
if (isset($data['coupon_product'])) {
|
||||
foreach ($data['coupon_product'] as $product_id) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "coupon_product` SET `coupon_id` = '" . (int)$coupon_id . "', `product_id` = '" . (int)$product_id . "'");
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($data['coupon_category'])) {
|
||||
foreach ($data['coupon_category'] as $category_id) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "coupon_category` SET `coupon_id` = '" . (int)$coupon_id . "', `category_id` = '" . (int)$category_id . "'");
|
||||
}
|
||||
}
|
||||
|
||||
return $coupon_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $coupon_id
|
||||
* @param array $data
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function editCoupon(int $coupon_id, array $data): void {
|
||||
$this->db->query("UPDATE `" . DB_PREFIX . "coupon` SET `name` = '" . $this->db->escape((string)$data['name']) . "', `code` = '" . $this->db->escape((string)$data['code']) . "', `discount` = '" . (float)$data['discount'] . "', `type` = '" . $this->db->escape((string)$data['type']) . "', `total` = '" . (float)$data['total'] . "', `logged` = '" . (isset($data['logged']) ? (bool)$data['logged'] : 0) . "', `shipping` = '" . (isset($data['shipping']) ? (bool)$data['shipping'] : 0) . "', `date_start` = '" . $this->db->escape((string)$data['date_start']) . "', `date_end` = '" . $this->db->escape((string)$data['date_end']) . "', `uses_total` = '" . (int)$data['uses_total'] . "', `uses_customer` = '" . (int)$data['uses_customer'] . "', `status` = '" . (bool)(isset($data['status']) ? $data['status'] : 0) . "' WHERE `coupon_id` = '" . (int)$coupon_id . "'");
|
||||
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "coupon_product` WHERE `coupon_id` = '" . (int)$coupon_id . "'");
|
||||
|
||||
if (isset($data['coupon_product'])) {
|
||||
foreach ($data['coupon_product'] as $product_id) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "coupon_product` SET `coupon_id` = '" . (int)$coupon_id . "', `product_id` = '" . (int)$product_id . "'");
|
||||
}
|
||||
}
|
||||
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "coupon_category` WHERE `coupon_id` = '" . (int)$coupon_id . "'");
|
||||
|
||||
if (isset($data['coupon_category'])) {
|
||||
foreach ($data['coupon_category'] as $category_id) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "coupon_category` SET `coupon_id` = '" . (int)$coupon_id . "', `category_id` = '" . (int)$category_id . "'");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $coupon_id
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function deleteCoupon(int $coupon_id): void {
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "coupon` WHERE `coupon_id` = '" . (int)$coupon_id . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "coupon_product` WHERE `coupon_id` = '" . (int)$coupon_id . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "coupon_category` WHERE `coupon_id` = '" . (int)$coupon_id . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "coupon_history` WHERE `coupon_id` = '" . (int)$coupon_id . "'");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $coupon_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getCoupon(int $coupon_id): array {
|
||||
$query = $this->db->query("SELECT DISTINCT * FROM `" . DB_PREFIX . "coupon` WHERE `coupon_id` = '" . (int)$coupon_id . "'");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $code
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getCouponByCode(string $code): array {
|
||||
$query = $this->db->query("SELECT DISTINCT * FROM `" . DB_PREFIX . "coupon` WHERE `code` = '" . $this->db->escape($code) . "'");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getCoupons(array $data = []): array {
|
||||
$sql = "SELECT `coupon_id`, `name`, `code`, `discount`, `date_start`, `date_end`, `status` FROM `" . DB_PREFIX . "coupon`";
|
||||
|
||||
$sort_data = [
|
||||
'name',
|
||||
'code',
|
||||
'discount',
|
||||
'date_start',
|
||||
'date_end',
|
||||
'status'
|
||||
];
|
||||
|
||||
if (isset($data['sort']) && in_array($data['sort'], $sort_data)) {
|
||||
$sql .= " ORDER BY " . $data['sort'];
|
||||
} else {
|
||||
$sql .= " ORDER BY `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'];
|
||||
}
|
||||
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
return $query->rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $coupon_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getProducts(int $coupon_id): array {
|
||||
$coupon_product_data = [];
|
||||
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "coupon_product` WHERE `coupon_id` = '" . (int)$coupon_id . "'");
|
||||
|
||||
foreach ($query->rows as $result) {
|
||||
$coupon_product_data[] = $result['product_id'];
|
||||
}
|
||||
|
||||
return $coupon_product_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $coupon_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getCategories(int $coupon_id): array {
|
||||
$coupon_category_data = [];
|
||||
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "coupon_category` WHERE `coupon_id` = '" . (int)$coupon_id . "'");
|
||||
|
||||
foreach ($query->rows as $result) {
|
||||
$coupon_category_data[] = $result['category_id'];
|
||||
}
|
||||
|
||||
return $coupon_category_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalCoupons(): int {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "coupon`");
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $coupon_id
|
||||
* @param int $start
|
||||
* @param int $limit
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getHistories(int $coupon_id, int $start = 0, int $limit = 10): array {
|
||||
if ($start < 0) {
|
||||
$start = 0;
|
||||
}
|
||||
|
||||
if ($limit < 1) {
|
||||
$limit = 10;
|
||||
}
|
||||
|
||||
$query = $this->db->query("SELECT ch.`order_id`, CONCAT(c.`firstname`, ' ', c.`lastname`) AS customer, ch.`amount`, ch.`date_added` FROM `" . DB_PREFIX . "coupon_history` ch LEFT JOIN `" . DB_PREFIX . "customer` c ON (ch.`customer_id` = c.`customer_id`) WHERE ch.`coupon_id` = '" . (int)$coupon_id . "' ORDER BY ch.`date_added` ASC LIMIT " . (int)$start . "," . (int)$limit);
|
||||
|
||||
return $query->rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $coupon_id
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalHistories(int $coupon_id): int {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "coupon_history` WHERE `coupon_id` = '" . (int)$coupon_id . "'");
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
}
|
200
admininistrator/model/marketing/marketing.php
Normal file
200
admininistrator/model/marketing/marketing.php
Normal file
@ -0,0 +1,200 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Model\Marketing;
|
||||
/**
|
||||
* Class Marketing
|
||||
*
|
||||
* @package Opencart\Admin\Model\Marketing
|
||||
*/
|
||||
class Marketing extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function addMarketing(array $data): int {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "marketing` SET `name` = '" . $this->db->escape((string)$data['name']) . "', `description` = '" . $this->db->escape((string)$data['description']) . "', `code` = '" . $this->db->escape((string)$data['code']) . "', `date_added` = NOW()");
|
||||
|
||||
return $this->db->getLastId();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $marketing_id
|
||||
* @param array $data
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function editMarketing(int $marketing_id, array $data): void {
|
||||
$this->db->query("UPDATE `" . DB_PREFIX . "marketing` SET `name` = '" . $this->db->escape((string)$data['name']) . "', `description` = '" . $this->db->escape((string)$data['description']) . "', `code` = '" . $this->db->escape((string)$data['code']) . "' WHERE `marketing_id` = '" . (int)$marketing_id . "'");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $marketing_id
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function deleteMarketing(int $marketing_id): void {
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "marketing` WHERE `marketing_id` = '" . (int)$marketing_id . "'");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $marketing_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getMarketing(int $marketing_id): array {
|
||||
$query = $this->db->query("SELECT DISTINCT * FROM `" . DB_PREFIX . "marketing` WHERE `marketing_id` = '" . (int)$marketing_id . "'");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $code
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getMarketingByCode(string $code): array {
|
||||
$query = $this->db->query("SELECT DISTINCT * FROM `" . DB_PREFIX . "marketing` WHERE `code` = '" . $this->db->escape($code) . "'");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getMarketings(array $data = []): array {
|
||||
$implode = [];
|
||||
|
||||
$order_statuses = $this->config->get('config_complete_status');
|
||||
|
||||
foreach ($order_statuses as $order_status_id) {
|
||||
$implode[] = "o.`order_status_id` = '" . (int)$order_status_id . "'";
|
||||
}
|
||||
|
||||
$sql = "SELECT *, (SELECT COUNT(*) FROM `" . DB_PREFIX . "order` o WHERE (" . implode(" OR ", $implode) . ") AND o.`marketing_id` = m.`marketing_id`) AS `orders` FROM `" . DB_PREFIX . "marketing` m";
|
||||
|
||||
$implode = [];
|
||||
|
||||
if (!empty($data['filter_name'])) {
|
||||
$implode[] = "m.`name` LIKE '" . $this->db->escape((string)$data['filter_name'] . '%') . "'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_code'])) {
|
||||
$implode[] = "m.`code` = '" . $this->db->escape((string)$data['filter_code']) . "'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_date_from'])) {
|
||||
$implode[] = "DATE(m.`date_added`) >= DATE('" . $this->db->escape((string)$data['filter_date_from']) . "')";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_date_to'])) {
|
||||
$implode[] = "DATE(m.`date_added`) <= DATE('" . $this->db->escape((string)$data['filter_date_to']) . "')";
|
||||
}
|
||||
|
||||
if ($implode) {
|
||||
$sql .= " WHERE " . implode(" AND ", $implode);
|
||||
}
|
||||
|
||||
$sort_data = [
|
||||
'm.name',
|
||||
'm.code',
|
||||
'm.date_added'
|
||||
];
|
||||
|
||||
if (isset($data['sort']) && in_array($data['sort'], $sort_data)) {
|
||||
$sql .= " ORDER BY " . $data['sort'];
|
||||
} else {
|
||||
$sql .= " ORDER BY m.`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'];
|
||||
}
|
||||
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
return $query->rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalMarketings(array $data = []): int {
|
||||
$sql = "SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "marketing`";
|
||||
|
||||
$implode = [];
|
||||
|
||||
if (!empty($data['filter_name'])) {
|
||||
$implode[] = "`name` LIKE '" . $this->db->escape((string)$data['filter_name']) . "'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_code'])) {
|
||||
$implode[] = "`code` = '" . $this->db->escape((string)$data['filter_code']) . "'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_date_from'])) {
|
||||
$implode[] = "DATE(`date_added`) >= DATE('" . $this->db->escape((string)$data['filter_date_from']) . "')";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_date_to'])) {
|
||||
$implode[] = "DATE(`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 $marketing_id
|
||||
* @param int $start
|
||||
* @param int $limit
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getReports(int $marketing_id, int $start = 0, int $limit = 10): array {
|
||||
if ($start < 0) {
|
||||
$start = 0;
|
||||
}
|
||||
|
||||
if ($limit < 1) {
|
||||
$limit = 10;
|
||||
}
|
||||
|
||||
$query = $this->db->query("SELECT `ip`, `store_id`, `country`, `date_added` FROM `" . DB_PREFIX . "marketing_report` WHERE `marketing_id` = '" . (int)$marketing_id . "' ORDER BY `date_added` ASC LIMIT " . (int)$start . "," . (int)$limit);
|
||||
|
||||
return $query->rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $marketing_id
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalReports(int $marketing_id): int {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "marketing_report` WHERE `marketing_id` = '" . (int)$marketing_id . "'");
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
}
|
76
admininistrator/model/report/online.php
Normal file
76
admininistrator/model/report/online.php
Normal file
@ -0,0 +1,76 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Model\Report;
|
||||
/**
|
||||
* Class Online
|
||||
*
|
||||
* @package Opencart\Admin\Model\Report
|
||||
*/
|
||||
class Online extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getOnline(array $data = []): array {
|
||||
$sql = "SELECT `co`.`ip`, `co`.`customer_id`, `co`.`url`, `co`.`referer`, `co`.`date_added` FROM `" . DB_PREFIX . "customer_online` `co` LEFT JOIN `" . DB_PREFIX . "customer` `c` ON (`co`.`customer_id` = `c`.`customer_id`)";
|
||||
|
||||
$implode = [];
|
||||
|
||||
if (!empty($data['filter_ip'])) {
|
||||
$implode[] = "`co`.`ip` LIKE '" . $this->db->escape((string)$data['filter_ip']) . "'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_customer'])) {
|
||||
$implode[] = "`co`.`customer_id` > '0' AND CONCAT(`c`.`firstname`, ' ', `c`.`lastname`) LIKE '" . $this->db->escape((string)$data['filter_customer']) . "'";
|
||||
}
|
||||
|
||||
if ($implode) {
|
||||
$sql .= " WHERE " . implode(" AND ", $implode);
|
||||
}
|
||||
|
||||
$sql .= " ORDER BY `co`.`date_added` DESC";
|
||||
|
||||
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 getTotalOnline(array $data = []): int {
|
||||
$sql = "SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "customer_online` `co` LEFT JOIN `" . DB_PREFIX . "customer` `c` ON (`co`.`customer_id` = `c`.`customer_id`)";
|
||||
|
||||
$implode = [];
|
||||
|
||||
if (!empty($data['filter_ip'])) {
|
||||
$implode[] = "`co`.`ip` LIKE '" . $this->db->escape((string)$data['filter_ip']) . "'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_customer'])) {
|
||||
$implode[] = "`co`.`customer_id` > '0' AND CONCAT(`c`.`firstname`, ' ', `c`.`lastname`) LIKE '" . $this->db->escape((string)$data['filter_customer']) . "'";
|
||||
}
|
||||
|
||||
if ($implode) {
|
||||
$sql .= " WHERE " . implode(" AND ", $implode);
|
||||
}
|
||||
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
}
|
62
admininistrator/model/report/statistics.php
Normal file
62
admininistrator/model/report/statistics.php
Normal file
@ -0,0 +1,62 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Model\Report;
|
||||
/**
|
||||
* Class Statistics
|
||||
*
|
||||
* @package Opencart\Admin\Model\Report
|
||||
*/
|
||||
class Statistics extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getStatistics(): array {
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "statistics`");
|
||||
|
||||
return $query->rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $code
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public function getValue(string $code): float {
|
||||
$query = $this->db->query("SELECT `value` FROM `" . DB_PREFIX . "statistics` WHERE `code` = '" . $this->db->escape($code) . "'");
|
||||
|
||||
if ($query->num_rows) {
|
||||
return $query->row['value'];
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $code
|
||||
* @param float $value
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function addValue(string $code, float $value): void {
|
||||
$this->db->query("UPDATE `" . DB_PREFIX . "statistics` SET `value` = (`value` + '" . (float)$value . "') WHERE `code` = '" . $this->db->escape($code) . "'");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $code
|
||||
* @param float $value
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function removeValue(string $code, float $value): void {
|
||||
$this->db->query("UPDATE `" . DB_PREFIX . "statistics` SET `value` = (`value` - '" . (float)$value . "') WHERE `code` = '" . $this->db->escape($code) . "'");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $code
|
||||
* @param float $value
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function editValue(string $code, float $value): void {
|
||||
$this->db->query("UPDATE `" . DB_PREFIX . "statistics` SET `value` = '" . (float)$value . "' WHERE `code` = '" . $this->db->escape($code) . "'");
|
||||
}
|
||||
}
|
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'];
|
||||
}
|
||||
}
|
137
admininistrator/model/setting/cron.php
Normal file
137
admininistrator/model/setting/cron.php
Normal file
@ -0,0 +1,137 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Model\Setting;
|
||||
/**
|
||||
* Class Cron
|
||||
*
|
||||
* @package Opencart\Admin\Model\Setting
|
||||
*/
|
||||
class Cron extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @param string $code
|
||||
* @param string $description
|
||||
* @param string $cycle
|
||||
* @param string $action
|
||||
* @param bool $status
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function addCron(string $code, string $description, string $cycle, string $action, bool $status): int {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "cron` SET `code` = '" . $this->db->escape($code) . "', `description` = '" . $this->db->escape($description) . "', `cycle` = '" . $this->db->escape($cycle) . "', `action` = '" . $this->db->escape($action) . "', `status` = '" . (int)$status . "', `date_added` = NOW(), `date_modified` = NOW()");
|
||||
|
||||
return $this->db->getLastId();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $cron_id
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function deleteCron(int $cron_id): void {
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "cron` WHERE `cron_id` = '" . (int)$cron_id . "'");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $code
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function deleteCronByCode(string $code): void {
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "cron` WHERE `code` = '" . $this->db->escape($code) . "'");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $cron_id
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function editCron(int $cron_id): void {
|
||||
$this->db->query("UPDATE `" . DB_PREFIX . "cron` SET `date_modified` = NOW() WHERE `cron_id` = '" . (int)$cron_id . "'");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $cron_id
|
||||
* @param bool $status
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function editStatus(int $cron_id, bool $status): void {
|
||||
$this->db->query("UPDATE `" . DB_PREFIX . "cron` SET `status` = '" . (bool)$status . "' WHERE `cron_id` = '" . (int)$cron_id . "'");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $cron_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getCron(int $cron_id): array {
|
||||
$query = $this->db->query("SELECT DISTINCT * FROM `" . DB_PREFIX . "cron` WHERE `cron_id` = '" . (int)$cron_id . "'");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $code
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getCronByCode(string $code): array {
|
||||
$query = $this->db->query("SELECT DISTINCT * FROM `" . DB_PREFIX . "cron` WHERE `code` = '" . $this->db->escape($code) . "' LIMIT 1");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getCrons(array $data = []): array {
|
||||
$sql = "SELECT * FROM `" . DB_PREFIX . "cron`";
|
||||
|
||||
$sort_data = [
|
||||
'code',
|
||||
'cycle',
|
||||
'action',
|
||||
'status',
|
||||
'date_added',
|
||||
'date_modified'
|
||||
];
|
||||
|
||||
if (isset($data['sort']) && in_array($data['sort'], $sort_data)) {
|
||||
$sql .= " ORDER BY " . $data['sort'];
|
||||
} else {
|
||||
$sql .= " ORDER BY `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 getTotalCrons(): int {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "cron`");
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
}
|
124
admininistrator/model/setting/event.php
Normal file
124
admininistrator/model/setting/event.php
Normal file
@ -0,0 +1,124 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Model\Setting;
|
||||
/**
|
||||
* Class Event
|
||||
*
|
||||
* @package Opencart\Admin\Model\Setting
|
||||
*/
|
||||
class Event extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function addEvent(array $data): int {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "event` SET `code` = '" . $this->db->escape($data['code']) . "', `description` = '" . $this->db->escape($data['description']) . "', `trigger` = '" . $this->db->escape($data['trigger']) . "', `action` = '" . $this->db->escape($data['action']) . "', `status` = '" . (bool)$data['status'] . "', `sort_order` = '" . (int)$data['sort_order'] . "'");
|
||||
|
||||
return $this->db->getLastId();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $event_id
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function deleteEvent(int $event_id): void {
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "event` WHERE `event_id` = '" . (int)$event_id . "'");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $code
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function deleteEventByCode(string $code): void {
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "event` WHERE `code` = '" . $this->db->escape($code) . "'");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $event_id
|
||||
* @param bool $status
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function editStatus(int $event_id, bool $status): void {
|
||||
$this->db->query("UPDATE `" . DB_PREFIX . "event` SET `status` = '" . (bool)$status . "' WHERE `event_id` = '" . (int)$event_id . "'");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $event_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getEvent(int $event_id): array {
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "event` WHERE `event_id` = '" . (int)$event_id . "'");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $code
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getEventByCode(string $code): array {
|
||||
$query = $this->db->query("SELECT DISTINCT * FROM `" . DB_PREFIX . "event` WHERE `code` = '" . $this->db->escape($code) . "' LIMIT 1");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getEvents(array $data = []): array {
|
||||
$sql = "SELECT * FROM `" . DB_PREFIX . "event`";
|
||||
|
||||
$sort_data = [
|
||||
'code',
|
||||
'trigger',
|
||||
'action',
|
||||
'sort_order',
|
||||
'status',
|
||||
'date_added'
|
||||
];
|
||||
|
||||
if (isset($data['sort']) && in_array($data['sort'], $sort_data)) {
|
||||
$sql .= " ORDER BY " . $data['sort'];
|
||||
} else {
|
||||
$sql .= " ORDER BY `sort_order`";
|
||||
}
|
||||
|
||||
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 getTotalEvents(): int {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "event`");
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
}
|
258
admininistrator/model/setting/extension.php
Normal file
258
admininistrator/model/setting/extension.php
Normal file
@ -0,0 +1,258 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Model\Setting;
|
||||
/**
|
||||
* Class Extension
|
||||
*
|
||||
* @package Opencart\Admin\Model\Setting
|
||||
*/
|
||||
class Extension extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getExtensions(): array {
|
||||
$query = $this->db->query("SELECT DISTINCT `extension` FROM `" . DB_PREFIX . "extension`");
|
||||
|
||||
return $query->rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $type
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getExtensionsByType(string $type): array {
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "extension` WHERE `type` = '" . $this->db->escape($type) . "' ORDER BY `code` ASC");
|
||||
|
||||
return $query->rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $type
|
||||
* @param string $code
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getExtensionByCode(string $type, string $code): array {
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "extension` WHERE `type` = '" . $this->db->escape($type) . "' AND `code` = '" . $this->db->escape($code) . "'");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $extension
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalExtensionsByExtension(string $extension): int {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "extension` WHERE `extension` = '" . $this->db->escape($extension) . "'");
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $type
|
||||
* @param string $extension
|
||||
* @param string $code
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function install(string $type, string $extension, string $code): void {
|
||||
$extensions = $this->getExtensionsByType($type);
|
||||
|
||||
$codes = array_column($extensions, 'code');
|
||||
|
||||
if (!in_array($code, $codes)) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "extension` SET `extension` = '" . $this->db->escape($extension) . "', `type` = '" . $this->db->escape($type) . "', `code` = '" . $this->db->escape($code) . "'");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $type
|
||||
* @param string $code
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function uninstall(string $type, string $code): void {
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "extension` WHERE `type` = '" . $this->db->escape($type) . "' AND `code` = '" . $this->db->escape($code) . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "setting` WHERE `code` = '" . $this->db->escape($type . '_' . $code) . "'");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function addInstall(array $data): int {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "extension_install` SET `extension_id` = '" . (int)$data['extension_id'] . "', `extension_download_id` = '" . (int)$data['extension_download_id'] . "', `name` = '" . $this->db->escape($data['name']) . "', `code` = '" . $this->db->escape($data['code']) . "', `version` = '" . $this->db->escape($data['version']) . "', `author` = '" . $this->db->escape($data['author']) . "', `link` = '" . $this->db->escape($data['link']) . "', `status` = '0', `date_added` = NOW()");
|
||||
|
||||
return $this->db->getLastId();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $extension_install_id
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function deleteInstall(int $extension_install_id): void {
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "extension_install` WHERE `extension_install_id` = '" . (int)$extension_install_id . "'");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $extension_install_id
|
||||
* @param bool $status
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function editStatus(int $extension_install_id, bool $status): void {
|
||||
$this->db->query("UPDATE `" . DB_PREFIX . "extension_install` SET `status` = '" . (bool)$status . "' WHERE `extension_install_id` = '" . (int)$extension_install_id . "'");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $extension_install_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getInstall(int $extension_install_id): array {
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "extension_install` WHERE `extension_install_id` = '" . (int)$extension_install_id . "'");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $extension_download_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getInstallByExtensionDownloadId(int $extension_download_id): array {
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "extension_install` WHERE `extension_download_id` = '" . (int)$extension_download_id . "'");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $code
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getInstallByCode(string $code): array {
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "extension_install` WHERE `code` = '" . $this->db->escape($code) . "'");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getInstalls(array $data = []): array {
|
||||
$sql = "SELECT * FROM `" . DB_PREFIX . "extension_install`";
|
||||
|
||||
if (!empty($data['filter_extension_download_id'])) {
|
||||
$sql .= " WHERE `extension_download_id` = '" . (int)$data['filter_extension_download_id'] . "'";
|
||||
}
|
||||
|
||||
$sort_data = [
|
||||
'name',
|
||||
'version',
|
||||
'date_added'
|
||||
];
|
||||
|
||||
if (isset($data['sort']) && in_array($data['sort'], $sort_data)) {
|
||||
$sql .= " ORDER BY " . $data['sort'];
|
||||
} else {
|
||||
$sql .= " ORDER BY `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;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalInstalls(array $data = []): int {
|
||||
$sql = "SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "extension_install`";
|
||||
|
||||
if (!empty($data['filter_extension_download_id'])) {
|
||||
$sql .= " WHERE `extension_download_id` = '" . (int)$data['filter_extension_download_id'] . "'";
|
||||
}
|
||||
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $extension_install_id
|
||||
* @param string $path
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function addPath(int $extension_install_id, string $path): void {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "extension_path` SET `extension_install_id` = '" . (int)$extension_install_id . "', `path` = '" . $this->db->escape($path) . "'");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $extension_path_id
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function deletePath(int $extension_path_id): void {
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "extension_path` WHERE `extension_path_id` = '" . (int)$extension_path_id . "'");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $extension_install_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getPathsByExtensionInstallId(int $extension_install_id): array {
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "extension_path` WHERE `extension_install_id` = '" . (int)$extension_install_id . "' ORDER BY `extension_path_id` ASC");
|
||||
|
||||
return $query->rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $path
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getPaths(string $path): array {
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "extension_path` WHERE `path` LIKE '" . $this->db->escape($path) . "' ORDER BY `path` ASC");
|
||||
|
||||
return $query->rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $path
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalPaths(string $path): int {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "extension_path` WHERE `path` LIKE '" . $this->db->escape($path) . "'");
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
}
|
86
admininistrator/model/setting/module.php
Normal file
86
admininistrator/model/setting/module.php
Normal file
@ -0,0 +1,86 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Model\Setting;
|
||||
/**
|
||||
* Class Module
|
||||
*
|
||||
* @package Opencart\Admin\Model\Setting
|
||||
*/
|
||||
class Module extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @param string $code
|
||||
* @param array $data
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function addModule(string $code, array $data): int {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "module` SET `name` = '" . $this->db->escape((string)$data['name']) . "', `code` = '" . $this->db->escape($code) . "', `setting` = '" . $this->db->escape(json_encode($data)) . "'");
|
||||
|
||||
$module_id = $this->db->getLastId();
|
||||
|
||||
return (int)$module_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $module_id
|
||||
* @param array $data
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function editModule(int $module_id, array $data): void {
|
||||
$this->db->query("UPDATE `" . DB_PREFIX . "module` SET `name` = '" . $this->db->escape((string)$data['name']) . "', `setting` = '" . $this->db->escape(json_encode($data)) . "' WHERE `module_id` = '" . (int)$module_id . "'");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $module_id
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function deleteModule(int $module_id): void {
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "module` WHERE `module_id` = '" . (int)$module_id . "'");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $module_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getModule(int $module_id): array {
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "module` WHERE `module_id` = '" . (int)$module_id . "'");
|
||||
|
||||
if ($query->row) {
|
||||
return json_decode($query->row['setting'], true);
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getModules(): array {
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "module` ORDER BY `code`");
|
||||
|
||||
return $query->rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $code
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getModulesByCode(string $code): array {
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "module` WHERE `code` = '" . $this->db->escape($code) . "' ORDER BY `name`");
|
||||
|
||||
return $query->rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $code
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function deleteModulesByCode(string $code): void {
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "module` WHERE `code` = '" . $this->db->escape($code) . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "layout_module` WHERE `code` = '" . $this->db->escape($code) . "' OR `code` LIKE '" . $this->db->escape($code . '.%') . "'");
|
||||
}
|
||||
}
|
104
admininistrator/model/setting/setting.php
Normal file
104
admininistrator/model/setting/setting.php
Normal file
@ -0,0 +1,104 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Model\Setting;
|
||||
/**
|
||||
* Class Setting
|
||||
*
|
||||
* @package Opencart\Admin\Model\Setting
|
||||
*/
|
||||
class Setting extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @param int $store_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getSettings(int $store_id = 0): array {
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "setting` WHERE `store_id` = '" . (int)$store_id . "' OR `store_id` = '0' ORDER BY `store_id` ASC");
|
||||
|
||||
return $query->rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $code
|
||||
* @param int $store_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getSetting(string $code, int $store_id = 0): array {
|
||||
$setting_data = [];
|
||||
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "setting` WHERE `store_id` = '" . (int)$store_id . "' AND `code` = '" . $this->db->escape($code) . "'");
|
||||
|
||||
foreach ($query->rows as $result) {
|
||||
if (!$result['serialized']) {
|
||||
$setting_data[$result['key']] = $result['value'];
|
||||
} else {
|
||||
$setting_data[$result['key']] = json_decode($result['value'], true);
|
||||
}
|
||||
}
|
||||
|
||||
return $setting_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $code
|
||||
* @param array $data
|
||||
* @param int $store_id
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function editSetting(string $code, array $data, int $store_id = 0): void {
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "setting` WHERE `store_id` = '" . (int)$store_id . "' AND `code` = '" . $this->db->escape($code) . "'");
|
||||
|
||||
foreach ($data as $key => $value) {
|
||||
if (substr($key, 0, strlen($code)) == $code) {
|
||||
if (!is_array($value)) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "setting` SET `store_id` = '" . (int)$store_id . "', `code` = '" . $this->db->escape($code) . "', `key` = '" . $this->db->escape($key) . "', `value` = '" . $this->db->escape($value) . "'");
|
||||
} else {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "setting` SET `store_id` = '" . (int)$store_id . "', `code` = '" . $this->db->escape($code) . "', `key` = '" . $this->db->escape($key) . "', `value` = '" . $this->db->escape(json_encode($value)) . "', `serialized` = '1'");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $code
|
||||
* @param int $store_id
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function deleteSetting(string $code, int $store_id = 0): void {
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "setting` WHERE `store_id` = '" . (int)$store_id . "' AND `code` = '" . $this->db->escape($code) . "'");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $key
|
||||
* @param int $store_id
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getValue(string $key, int $store_id = 0): string {
|
||||
$query = $this->db->query("SELECT `value` FROM `" . DB_PREFIX . "setting` WHERE `store_id` = '" . (int)$store_id . "' AND `key` = '" . $this->db->escape($key) . "'");
|
||||
|
||||
if ($query->num_rows) {
|
||||
return $query->row['value'];
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $code
|
||||
* @param string $key
|
||||
* @param string|array $value
|
||||
* @param int $store_id
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function editValue(string $code = '', string $key = '', string|array $value = '', int $store_id = 0): void {
|
||||
if (!is_array($value)) {
|
||||
$this->db->query("UPDATE `" . DB_PREFIX . "setting` SET `value` = '" . $this->db->escape($value) . "', `serialized` = '0' WHERE `code` = '" . $this->db->escape($code) . "' AND `key` = '" . $this->db->escape($key) . "' AND `store_id` = '" . (int)$store_id . "'");
|
||||
} else {
|
||||
$this->db->query("UPDATE `" . DB_PREFIX . "setting` SET `value` = '" . $this->db->escape(json_encode($value)) . "', `serialized` = '1' WHERE `code` = '" . $this->db->escape($code) . "' AND `key` = '" . $this->db->escape($key) . "' AND `store_id` = '" . (int)$store_id . "'");
|
||||
}
|
||||
}
|
||||
}
|
123
admininistrator/model/setting/startup.php
Normal file
123
admininistrator/model/setting/startup.php
Normal file
@ -0,0 +1,123 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Model\Setting;
|
||||
/**
|
||||
* Class Startup
|
||||
*
|
||||
* @package Opencart\Admin\Model\Setting
|
||||
*/
|
||||
class Startup extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function addStartup(array $data): int {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "startup` SET `code` = '" . $this->db->escape($data['code']) . "', `action` = '" . $this->db->escape($data['action']) . "', `status` = '" . (bool)$data['status'] . "', `sort_order` = '" . (int)$data['sort_order'] . "'");
|
||||
|
||||
return $this->db->getLastId();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $startup_id
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function deleteStartup(int $startup_id): void {
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "startup` WHERE `startup_id` = '" . (int)$startup_id . "'");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $code
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function deleteStartupByCode(string $code): void {
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "startup` WHERE `code` = '" . $this->db->escape($code) . "'");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $startup_id
|
||||
* @param bool $status
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function editStatus(int $startup_id, bool $status): void {
|
||||
$this->db->query("UPDATE `" . DB_PREFIX . "startup` SET `status` = '" . (bool)$status . "' WHERE `startup_id` = '" . (int)$startup_id . "'");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $startup_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getStartup(int $startup_id): array {
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "startup` WHERE `startup_id` = '" . (int)$startup_id . "'");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $code
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getStartupByCode(string $code): array {
|
||||
$query = $this->db->query("SELECT DISTINCT * FROM `" . DB_PREFIX . "startup` WHERE `code` = '" . $this->db->escape($code) . "' LIMIT 1");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getStartups(array $data = []): array {
|
||||
$sql = "SELECT * FROM `" . DB_PREFIX . "startup`";
|
||||
|
||||
$sort_data = [
|
||||
'code',
|
||||
'action',
|
||||
'status',
|
||||
'sort_order',
|
||||
'date_added'
|
||||
];
|
||||
|
||||
if (isset($data['sort']) && in_array($data['sort'], $sort_data)) {
|
||||
$sql .= " ORDER BY " . $data['sort'];
|
||||
} else {
|
||||
$sql .= " ORDER BY `sort_order`";
|
||||
}
|
||||
|
||||
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 getTotalStartups(): int {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "startup`");
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
}
|
325
admininistrator/model/setting/store.php
Normal file
325
admininistrator/model/setting/store.php
Normal file
@ -0,0 +1,325 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Model\Setting;
|
||||
/**
|
||||
* Class Store
|
||||
*
|
||||
* @package Opencart\Admin\Model\Setting
|
||||
*/
|
||||
class Store extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function addStore(array $data): int {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "store` SET `name` = '" . $this->db->escape((string)$data['config_name']) . "', `url` = '" . $this->db->escape((string)$data['config_url']) . "'");
|
||||
|
||||
$store_id = $this->db->getLastId();
|
||||
|
||||
// Layout Route
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "layout_route` WHERE `store_id` = '0'");
|
||||
|
||||
foreach ($query->rows as $layout_route) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "layout_route` SET `layout_id` = '" . (int)$layout_route['layout_id'] . "', `route` = '" . $this->db->escape($layout_route['route']) . "', `store_id` = '" . (int)$store_id . "'");
|
||||
}
|
||||
|
||||
$this->cache->delete('store');
|
||||
|
||||
return $store_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $store_id
|
||||
* @param array $data
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function editStore(int $store_id, array $data): void {
|
||||
$this->db->query("UPDATE `" . DB_PREFIX . "store` SET `name` = '" . $this->db->escape((string)$data['config_name']) . "', `url` = '" . $this->db->escape((string)$data['config_url']) . "' WHERE `store_id` = '" . (int)$store_id . "'");
|
||||
|
||||
$this->cache->delete('store');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $store_id
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function deleteStore(int $store_id): void {
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "store` WHERE `store_id` = '" . (int)$store_id . "'");
|
||||
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "category_to_layout` WHERE `store_id` = '" . (int)$store_id . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "category_to_store` WHERE `store_id` = '" . (int)$store_id . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "customer` WHERE `store_id` = '" . (int)$store_id . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "customer_affiliate_report` WHERE `store_id` = '" . (int)$store_id . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "customer_ip` WHERE `store_id` = '" . (int)$store_id . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "customer_search` WHERE `store_id` = '" . (int)$store_id . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "download_report` WHERE `store_id` = '" . (int)$store_id . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "gdpr` WHERE `store_id` = '" . (int)$store_id . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "information_to_layout` WHERE `store_id` = '" . (int)$store_id . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "information_to_store` WHERE `store_id` = '" . (int)$store_id . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "layout_route` WHERE `store_id` = '" . (int)$store_id . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "manufacturer_to_layout` WHERE `store_id` = '" . (int)$store_id . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "manufacturer_to_store` WHERE `store_id` = '" . (int)$store_id . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "marketing_report` WHERE `store_id` = '" . (int)$store_id . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "order` WHERE `store_id` = '" . (int)$store_id . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "product_report` WHERE `store_id` = '" . (int)$store_id . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "product_to_layout` WHERE `store_id` = '" . (int)$store_id . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "product_to_store` WHERE `store_id` = '" . (int)$store_id . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "setting` WHERE `store_id` = '" . (int)$store_id . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "subscription` WHERE `store_id` = '" . (int)$store_id . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "theme` WHERE `store_id` = '" . (int)$store_id . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "translation` WHERE `store_id` = '" . (int)$store_id . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "seo_url` WHERE `store_id` = '" . (int)$store_id . "'");
|
||||
|
||||
$this->cache->delete('store');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $store_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getStore(int $store_id): array {
|
||||
$query = $this->db->query("SELECT DISTINCT * FROM `" . DB_PREFIX . "store` WHERE `store_id` = '" . (int)$store_id . "'");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getStores(array $data = []): array {
|
||||
$sql = "SELECT * FROM `" . DB_PREFIX . "store` ORDER BY `url`";
|
||||
|
||||
$store_data = $this->cache->get('store.' . md5($sql));
|
||||
|
||||
if (!$store_data) {
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
$store_data = $query->rows;
|
||||
|
||||
$this->cache->set('store.' . md5($sql), $store_data);
|
||||
}
|
||||
|
||||
return $store_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $store_id
|
||||
* @param string $language
|
||||
* @param string $session_id
|
||||
*
|
||||
* @return \Opencart\System\Engine\Registry
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function createStoreInstance(int $store_id = 0, string $language = '', string $session_id = ''): object {
|
||||
// Autoloader
|
||||
$this->autoloader->register('Opencart\Catalog', DIR_CATALOG);
|
||||
|
||||
// Registry
|
||||
$registry = new \Opencart\System\Engine\Registry();
|
||||
$registry->set('autoloader', $this->autoloader);
|
||||
|
||||
// Config
|
||||
$config = new \Opencart\System\Engine\Config();
|
||||
$registry->set('config', $config);
|
||||
|
||||
// Load the default config
|
||||
$config->addPath(DIR_CONFIG);
|
||||
$config->load('default');
|
||||
$config->load('catalog');
|
||||
$config->set('application', 'Catalog');
|
||||
|
||||
// Store
|
||||
$config->set('config_store_id', $store_id);
|
||||
|
||||
// Logging
|
||||
$registry->set('log', $this->log);
|
||||
|
||||
// Event
|
||||
$event = new \Opencart\System\Engine\Event($registry);
|
||||
$registry->set('event', $event);
|
||||
|
||||
// Event Register
|
||||
if ($config->has('action_event')) {
|
||||
foreach ($config->get('action_event') as $key => $value) {
|
||||
foreach ($value as $priority => $action) {
|
||||
$event->register($key, new \Opencart\System\Engine\Action($action), $priority);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Loader
|
||||
$loader = new \Opencart\System\Engine\Loader($registry);
|
||||
$registry->set('load', $loader);
|
||||
|
||||
// Create a dummy request class, so we can feed the data to the order editor
|
||||
$request = new \stdClass();
|
||||
$request->get = [];
|
||||
$request->post = [];
|
||||
$request->server = $this->request->server;
|
||||
$request->cookie = [];
|
||||
|
||||
// Request
|
||||
$registry->set('request', $request);
|
||||
|
||||
// Response
|
||||
$response = new \Opencart\System\Library\Response();
|
||||
$registry->set('response', $response);
|
||||
|
||||
// Database
|
||||
$registry->set('db', $this->db);
|
||||
|
||||
// Cache
|
||||
$registry->set('cache', $this->cache);
|
||||
|
||||
// Session
|
||||
$session = new \Opencart\System\Library\Session($config->get('session_engine'), $registry);
|
||||
$registry->set('session', $session);
|
||||
|
||||
// Start session
|
||||
$session->start($session_id);
|
||||
|
||||
// Template
|
||||
$template = new \Opencart\System\Library\Template($config->get('template_engine'));
|
||||
$template->addPath(DIR_CATALOG . 'view/template/');
|
||||
$registry->set('template', $template);
|
||||
|
||||
// Adding language var to the GET variable so there is a default language
|
||||
$registry->request->get['language'] = $language;
|
||||
|
||||
// Language
|
||||
$language = new \Opencart\System\Library\Language($config->get('language_code'));
|
||||
$language->addPath(DIR_CATALOG . 'language/');
|
||||
$language->load('default');
|
||||
$registry->set('language', $language);
|
||||
|
||||
// Url
|
||||
$registry->set('url', new \Opencart\System\Library\Url($config->get('site_url')));
|
||||
|
||||
// Document
|
||||
$registry->set('document', new \Opencart\System\Library\Document());
|
||||
|
||||
// Run pre actions to load key settings and classes.
|
||||
$pre_actions = [
|
||||
'startup/setting',
|
||||
'startup/language',
|
||||
'startup/extension',
|
||||
'startup/customer',
|
||||
'startup/tax',
|
||||
'startup/currency',
|
||||
'startup/application',
|
||||
'startup/startup',
|
||||
'startup/event'
|
||||
];
|
||||
|
||||
// Pre Actions
|
||||
foreach ($pre_actions as $pre_action) {
|
||||
$loader->controller($pre_action);
|
||||
}
|
||||
|
||||
return $registry;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalStores(): int {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "store`");
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $layout_id
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalStoresByLayoutId(int $layout_id): int {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "setting` WHERE `key` = 'config_layout_id' AND `value` = '" . (int)$layout_id . "' AND `store_id` != '0'");
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $language
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalStoresByLanguage(string $language): int {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "setting` WHERE `key` = 'config_language' AND `value` = '" . $this->db->escape($language) . "' AND `store_id` != '0'");
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $currency
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalStoresByCurrency(string $currency): int {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "setting` WHERE `key` = 'config_currency' AND `value` = '" . $this->db->escape($currency) . "' AND `store_id` != '0'");
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $country_id
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalStoresByCountryId(int $country_id): int {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "setting` WHERE `key` = 'config_country_id' AND `value` = '" . (int)$country_id . "' AND `store_id` != '0'");
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $zone_id
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalStoresByZoneId(int $zone_id): int {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "setting` WHERE `key` = 'config_zone_id' AND `value` = '" . (int)$zone_id . "' AND `store_id` != '0'");
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $customer_group_id
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalStoresByCustomerGroupId(int $customer_group_id): int {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "setting` WHERE `key` = 'config_customer_group_id' AND `value` = '" . (int)$customer_group_id . "' AND `store_id` != '0'");
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $information_id
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalStoresByInformationId(int $information_id): int {
|
||||
$account_query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "setting` WHERE `key` = 'config_account_id' AND `value` = '" . (int)$information_id . "' AND `store_id` != '0'");
|
||||
|
||||
$checkout_query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "setting` WHERE `key` = 'config_checkout_id' AND `value` = '" . (int)$information_id . "' AND `store_id` != '0'");
|
||||
|
||||
return ($account_query->row['total'] + $checkout_query->row['total']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $order_status_id
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalStoresByOrderStatusId(int $order_status_id): int {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "setting` WHERE `key` = 'config_order_status_id' AND `value` = '" . (int)$order_status_id . "' AND `store_id` != '0'");
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
}
|
65
admininistrator/model/tool/backup.php
Normal file
65
admininistrator/model/tool/backup.php
Normal file
@ -0,0 +1,65 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Model\Tool;
|
||||
/**
|
||||
* Class Backup
|
||||
*
|
||||
* @package Opencart\Admin\Model\Tool
|
||||
*/
|
||||
class Backup extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getTables(): array {
|
||||
$table_data = [];
|
||||
|
||||
$query = $this->db->query("SHOW TABLES FROM `" . DB_DATABASE . "`");
|
||||
|
||||
foreach ($query->rows as $result) {
|
||||
if (isset($result['Tables_in_' . DB_DATABASE]) && substr($result['Tables_in_' . DB_DATABASE], 0, strlen(DB_PREFIX)) == DB_PREFIX) {
|
||||
$table_data[] = $result['Tables_in_' . DB_DATABASE];
|
||||
}
|
||||
}
|
||||
|
||||
return $table_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $table
|
||||
* @param int $start
|
||||
* @param int $limit
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getRecords(string $table, int $start = 0, int $limit = 100): array {
|
||||
if ($start < 0) {
|
||||
$start = 0;
|
||||
}
|
||||
|
||||
if ($limit < 1) {
|
||||
$limit = 10;
|
||||
}
|
||||
|
||||
$query = $this->db->query("SELECT * FROM `" . $table . "` LIMIT " . (int)$start . "," . (int)$limit);
|
||||
|
||||
if ($query->num_rows) {
|
||||
return $query->rows;
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $table
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalRecords(string $table): int {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . $table . "`");
|
||||
|
||||
if ($query->num_rows) {
|
||||
return (int)$query->row['total'];
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
61
admininistrator/model/tool/image.php
Normal file
61
admininistrator/model/tool/image.php
Normal file
@ -0,0 +1,61 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Model\Tool;
|
||||
/**
|
||||
* Class Image
|
||||
*
|
||||
* @package Opencart\Admin\Model\Tool
|
||||
*/
|
||||
class Image extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @param string $filename
|
||||
* @param int $width
|
||||
* @param int $height
|
||||
*
|
||||
* @return string
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function resize(string $filename, int $width, int $height): string {
|
||||
if (!is_file(DIR_IMAGE . $filename) || substr(str_replace('\\', '/', realpath(DIR_IMAGE . $filename)), 0, strlen(DIR_IMAGE)) != DIR_IMAGE) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$extension = pathinfo($filename, PATHINFO_EXTENSION);
|
||||
|
||||
$image_old = $filename;
|
||||
$image_new = 'cache/' . oc_substr($filename, 0, oc_strrpos($filename, '.')) . '-' . $width . 'x' . $height . '.' . $extension;
|
||||
|
||||
if (!is_file(DIR_IMAGE . $image_new) || (filemtime(DIR_IMAGE . $image_old) > filemtime(DIR_IMAGE . $image_new))) {
|
||||
list($width_orig, $height_orig, $image_type) = getimagesize(DIR_IMAGE . $image_old);
|
||||
|
||||
if (!in_array($image_type, [IMAGETYPE_PNG, IMAGETYPE_JPEG, IMAGETYPE_GIF, IMAGETYPE_WEBP])) {
|
||||
return HTTP_CATALOG . 'image/' . $image_old;
|
||||
}
|
||||
|
||||
$path = '';
|
||||
|
||||
$directories = explode('/', dirname($image_new));
|
||||
|
||||
foreach ($directories as $directory) {
|
||||
if (!$path) {
|
||||
$path = $directory;
|
||||
} else {
|
||||
$path = $path . '/' . $directory;
|
||||
}
|
||||
|
||||
if (!is_dir(DIR_IMAGE . $path)) {
|
||||
@mkdir(DIR_IMAGE . $path, 0777);
|
||||
}
|
||||
}
|
||||
|
||||
if ($width_orig != $width || $height_orig != $height) {
|
||||
$image = new \Opencart\System\Library\Image(DIR_IMAGE . $image_old);
|
||||
$image->resize($width, $height);
|
||||
$image->save(DIR_IMAGE . $image_new);
|
||||
} else {
|
||||
copy(DIR_IMAGE . $image_old, DIR_IMAGE . $image_new);
|
||||
}
|
||||
}
|
||||
|
||||
return HTTP_CATALOG . 'image/' . $image_new;
|
||||
}
|
||||
}
|
97
admininistrator/model/tool/notification.php
Normal file
97
admininistrator/model/tool/notification.php
Normal file
@ -0,0 +1,97 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Model\Tool;
|
||||
/**
|
||||
* Class Notification
|
||||
*
|
||||
* @package Opencart\Admin\Model\Tool
|
||||
*/
|
||||
class Notification extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function addNotification(array $data): int {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "notification` SET `title` = '" . $this->db->escape((string)$data['title']) . "', `text` = '" . $this->db->escape((string)$data['text']) . "', `status` = '" . (bool)$data['status'] . "', `date_added` = NOW()");
|
||||
|
||||
return $this->db->getLastId();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $notification_id
|
||||
* @param bool $status
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function editStatus(int $notification_id, bool $status): void {
|
||||
$this->db->query("UPDATE `" . DB_PREFIX . "notification` SET `status` = '" . (bool)$status . "' WHERE `notification_id` = '" . (int)$notification_id . "'");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $notification_id
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function deleteNotification(int $notification_id): void {
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "notification` WHERE `notification_id` = '" . (int)$notification_id . "'");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $notification_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getNotification(int $notification_id): array {
|
||||
$query = $this->db->query("SELECT DISTINCT * FROM `" . DB_PREFIX . "notification` WHERE `notification_id` = '" . (int)$notification_id . "'");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getNotifications(array $data = []): array {
|
||||
$sql = "SELECT * FROM `" . DB_PREFIX . "notification`";
|
||||
|
||||
if (isset($data['filter_status']) && $data['filter_status'] !== '') {
|
||||
$sql .= " WHERE `status` = '" . (bool)$data['filter_status'] . "'";
|
||||
}
|
||||
|
||||
$sql .= " ORDER BY `date_added` DESC";
|
||||
|
||||
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 getTotalNotifications(array $data = []): int {
|
||||
$sql = "SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "notification`";
|
||||
|
||||
if (isset($data['filter_status']) && $data['filter_status'] !== '') {
|
||||
$sql .= " WHERE `status` = '" . (bool)$data['filter_status'] . "'";
|
||||
}
|
||||
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
}
|
153
admininistrator/model/tool/upload.php
Normal file
153
admininistrator/model/tool/upload.php
Normal file
@ -0,0 +1,153 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Model\Tool;
|
||||
/**
|
||||
* Class Upload
|
||||
*
|
||||
* @package Opencart\Admin\Model\Tool
|
||||
*/
|
||||
class Upload extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @param string $name
|
||||
* @param string $filename
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function addUpload(string $name, string $filename): string {
|
||||
$code = oc_token(32);
|
||||
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "upload` SET `name` = '" . $this->db->escape($name) . "', `filename` = '" . $this->db->escape($filename) . "', `code` = '" . $this->db->escape($code) . "', `date_added` = NOW()");
|
||||
|
||||
return $code;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $upload_id
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function deleteUpload(int $upload_id): void {
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "upload` WHERE `upload_id` = '" . (int)$upload_id . "'");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $upload_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getUpload(int $upload_id): array {
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "upload` WHERE `upload_id` = '" . (int)$upload_id . "'");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $code
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getUploadByCode(string $code): array {
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "upload` WHERE `code` = '" . $this->db->escape($code) . "'");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getUploads(array $data = []): array {
|
||||
$sql = "SELECT * FROM `" . DB_PREFIX . "upload`";
|
||||
|
||||
$implode = [];
|
||||
|
||||
if (!empty($data['filter_name'])) {
|
||||
$implode[] = "`name` LIKE '" . $this->db->escape((string)$data['filter_name'] . '%') . "'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_code'])) {
|
||||
$implode[] = "`code` LIKE '" . $this->db->escape((string)$data['filter_code'] . '%') . "'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_date_from'])) {
|
||||
$implode[] = "DATE(`date_added`) >= DATE('" . $this->db->escape((string)$data['filter_date_from']) . "')";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_date_to'])) {
|
||||
$implode[] = "DATE(`date_added`) <= DATE('" . $this->db->escape((string)$data['filter_date_to']) . "')";
|
||||
}
|
||||
|
||||
if ($implode) {
|
||||
$sql .= " WHERE " . implode(" AND ", $implode);
|
||||
}
|
||||
|
||||
$sort_data = [
|
||||
'name',
|
||||
'code',
|
||||
'date_added'
|
||||
];
|
||||
|
||||
if (isset($data['sort']) && in_array($data['sort'], $sort_data)) {
|
||||
$sql .= " ORDER BY " . $data['sort'];
|
||||
} else {
|
||||
$sql .= " ORDER BY `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;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalUploads(array $data = []): int {
|
||||
$sql = "SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "upload`";
|
||||
|
||||
$implode = [];
|
||||
|
||||
if (!empty($data['filter_name'])) {
|
||||
$implode[] = "`name` LIKE '" . $this->db->escape((string)$data['filter_name'] . '%') . "'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_code'])) {
|
||||
$implode[] = "`code` LIKE '" . $this->db->escape((string)$data['filter_code'] . '%') . "'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_date_from'])) {
|
||||
$implode[] = "DATE(`date_added`) >= DATE('" . $this->db->escape((string)$data['filter_date_from']) . "')";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_date_to'])) {
|
||||
$implode[] = "DATE(`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'];
|
||||
}
|
||||
}
|
197
admininistrator/model/user/api.php
Normal file
197
admininistrator/model/user/api.php
Normal file
@ -0,0 +1,197 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Model\User;
|
||||
/**
|
||||
* Class Api
|
||||
*
|
||||
* @package Opencart\Admin\Model\User
|
||||
*/
|
||||
class Api extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function addApi(array $data): int {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "api` SET `username` = '" . $this->db->escape((string)$data['username']) . "', `key` = '" . $this->db->escape((string)$data['key']) . "', `status` = '" . (bool)(isset($data['status']) ? $data['status'] : 0) . "', `date_added` = NOW(), `date_modified` = NOW()");
|
||||
|
||||
$api_id = $this->db->getLastId();
|
||||
|
||||
if (isset($data['api_ip'])) {
|
||||
foreach ($data['api_ip'] as $ip) {
|
||||
if ($ip) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "api_ip` SET `api_id` = '" . (int)$api_id . "', `ip` = '" . $this->db->escape($ip) . "'");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $api_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $api_id
|
||||
* @param array $data
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function editApi(int $api_id, array $data): void {
|
||||
$this->db->query("UPDATE `" . DB_PREFIX . "api` SET `username` = '" . $this->db->escape((string)$data['username']) . "', `key` = '" . $this->db->escape((string)$data['key']) . "', `status` = '" . (bool)(isset($data['status']) ? $data['status'] : 0) . "', `date_modified` = NOW() WHERE `api_id` = '" . (int)$api_id . "'");
|
||||
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "api_ip` WHERE `api_id` = '" . (int)$api_id . "'");
|
||||
|
||||
if (isset($data['api_ip'])) {
|
||||
foreach ($data['api_ip'] as $ip) {
|
||||
if ($ip) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "api_ip` SET `api_id` = '" . (int)$api_id . "', `ip` = '" . $this->db->escape($ip) . "'");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $api_id
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function deleteApi(int $api_id): void {
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "api` WHERE `api_id` = '" . (int)$api_id . "'");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $api_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getApi(int $api_id): array {
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "api` WHERE `api_id` = '" . (int)$api_id . "'");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getApis(array $data = []): array {
|
||||
$sql = "SELECT * FROM `" . DB_PREFIX . "api`";
|
||||
|
||||
$sort_data = [
|
||||
'username',
|
||||
'status',
|
||||
'date_added',
|
||||
'date_modified'
|
||||
];
|
||||
|
||||
if (isset($data['sort']) && in_array($data['sort'], $sort_data)) {
|
||||
$sql .= " ORDER BY " . $data['sort'];
|
||||
} else {
|
||||
$sql .= " ORDER BY `username`";
|
||||
}
|
||||
|
||||
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 getTotalApis(): int {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "api`");
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $api_id
|
||||
* @param string $ip
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function addIp(int $api_id, string $ip): void {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "api_ip` SET `api_id` = '" . (int)$api_id . "', `ip` = '" . $this->db->escape($ip) . "'");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $api_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getIps(int $api_id): array {
|
||||
$ip_data = [];
|
||||
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "api_ip` WHERE `api_id` = '" . (int)$api_id . "'");
|
||||
|
||||
foreach ($query->rows as $result) {
|
||||
$ip_data[] = $result['ip'];
|
||||
}
|
||||
|
||||
return $ip_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $api_id
|
||||
* @param string $session_id
|
||||
* @param string $ip
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function addSession(int $api_id, string $session_id, string $ip): int {
|
||||
$api_ip_query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "api_ip` WHERE `ip` = '" . $this->db->escape($ip) . "'");
|
||||
|
||||
if (!$api_ip_query->num_rows) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "api_ip` SET `api_id` = '" . (int)$api_id . "', `ip` = '" . $this->db->escape($ip) . "'");
|
||||
}
|
||||
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "api_session` SET `api_id` = '" . (int)$api_id . "', `session_id` = '" . $this->db->escape($session_id) . "', `ip` = '" . $this->db->escape($ip) . "', `date_added` = NOW(), `date_modified` = NOW()");
|
||||
|
||||
return $this->db->getLastId();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $api_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getSessions(int $api_id): array {
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "api_session` WHERE `api_id` = '" . (int)$api_id . "'");
|
||||
|
||||
return $query->rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $api_session_id
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function deleteSession(int $api_session_id): void {
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "api_session` WHERE `api_session_id` = '" . (int)$api_session_id . "'");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $session_id
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function deleteSessionBySessionId(string $session_id): void {
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "api_session` WHERE `session_id` = '" . $this->db->escape($session_id) . "'");
|
||||
}
|
||||
}
|
332
admininistrator/model/user/user.php
Normal file
332
admininistrator/model/user/user.php
Normal file
@ -0,0 +1,332 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Model\User;
|
||||
/**
|
||||
* Class User
|
||||
*
|
||||
* @package Opencart\Admin\Model\User
|
||||
*/
|
||||
class User extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function addUser(array $data): int {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "user` SET `username` = '" . $this->db->escape((string)$data['username']) . "', `user_group_id` = '" . (int)$data['user_group_id'] . "', `password` = '" . $this->db->escape(password_hash(html_entity_decode($data['password'], ENT_QUOTES, 'UTF-8'), PASSWORD_DEFAULT)) . "', `firstname` = '" . $this->db->escape((string)$data['firstname']) . "', `lastname` = '" . $this->db->escape((string)$data['lastname']) . "', `email` = '" . $this->db->escape((string)$data['email']) . "', `image` = '" . $this->db->escape((string)$data['image']) . "', `status` = '" . (bool)(isset($data['status']) ? $data['status'] : 0) . "', `date_added` = NOW()");
|
||||
|
||||
return $this->db->getLastId();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $user_id
|
||||
* @param array $data
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function editUser(int $user_id, array $data): void {
|
||||
$this->db->query("UPDATE `" . DB_PREFIX . "user` SET `username` = '" . $this->db->escape((string)$data['username']) . "', `user_group_id` = '" . (int)$data['user_group_id'] . "', `firstname` = '" . $this->db->escape((string)$data['firstname']) . "', `lastname` = '" . $this->db->escape((string)$data['lastname']) . "', `email` = '" . $this->db->escape((string)$data['email']) . "', `image` = '" . $this->db->escape((string)$data['image']) . "', `status` = '" . (bool)(isset($data['status']) ? $data['status'] : 0) . "' WHERE `user_id` = '" . (int)$user_id . "'");
|
||||
|
||||
if ($data['password']) {
|
||||
$this->db->query("UPDATE `" . DB_PREFIX . "user` SET `password` = '" . $this->db->escape(password_hash(html_entity_decode($data['password'], ENT_QUOTES, 'UTF-8'), PASSWORD_DEFAULT)) . "' WHERE `user_id` = '" . (int)$user_id . "'");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $user_id
|
||||
* @param $password
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function editPassword(int $user_id, $password): void {
|
||||
$this->db->query("UPDATE `" . DB_PREFIX . "user` SET `password` = '" . $this->db->escape(password_hash(html_entity_decode($password, ENT_QUOTES, 'UTF-8'), PASSWORD_DEFAULT)) . "', `code` = '' WHERE `user_id` = '" . (int)$user_id . "'");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $email
|
||||
* @param string $code
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function editCode(string $email, string $code): void {
|
||||
$this->db->query("UPDATE `" . DB_PREFIX . "user` SET `code` = '" . $this->db->escape($code) . "' WHERE LCASE(`email`) = '" . $this->db->escape(oc_strtolower($email)) . "'");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $user_id
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function deleteUser(int $user_id): void {
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "user` WHERE `user_id` = '" . (int)$user_id . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "user_history` WHERE `user_id` = '" . (int)$user_id . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "user_history` WHERE `user_id` = '" . (int)$user_id . "'");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $user_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getUser(int $user_id): array {
|
||||
$query = $this->db->query("SELECT *, (SELECT ug.`name` FROM `" . DB_PREFIX . "user_group` ug WHERE ug.`user_group_id` = u.`user_group_id`) AS user_group FROM `" . DB_PREFIX . "user` u WHERE u.`user_id` = '" . (int)$user_id . "'");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $username
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getUserByUsername(string $username): array {
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "user` WHERE `username` = '" . $this->db->escape($username) . "'");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $email
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getUserByEmail(string $email): array {
|
||||
$query = $this->db->query("SELECT DISTINCT * FROM `" . DB_PREFIX . "user` WHERE LCASE(`email`) = '" . $this->db->escape(oc_strtolower($email)) . "'");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $code
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getUserByCode(string $code): array {
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "user` WHERE `code` = '" . $this->db->escape($code) . "' AND `code` != ''");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getUsers(array $data = []): array {
|
||||
$sql = "SELECT * FROM `" . DB_PREFIX . "user`";
|
||||
|
||||
$sort_data = [
|
||||
'username',
|
||||
'status',
|
||||
'date_added'
|
||||
];
|
||||
|
||||
if (isset($data['sort']) && in_array($data['sort'], $sort_data)) {
|
||||
$sql .= " ORDER BY " . $data['sort'];
|
||||
} else {
|
||||
$sql .= " ORDER BY `username`";
|
||||
}
|
||||
|
||||
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 getTotalUsers(): int {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "user`");
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $user_group_id
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalUsersByGroupId(int $user_group_id): int {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "user` WHERE `user_group_id` = '" . (int)$user_group_id . "'");
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $email
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalUsersByEmail(string $email): int {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "user` WHERE LCASE(`email`) = '" . $this->db->escape(oc_strtolower($email)) . "'");
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $user_id
|
||||
* @param array $data
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function addLogin(int $user_id, array $data): void {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "user_login` SET `user_id` = '" . (int)$user_id . "', `ip` = '" . $this->db->escape($data['ip']) . "', `user_agent` = '" . $this->db->escape($data['user_agent']) . "', `date_added` = NOW()");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $user_id
|
||||
* @param int $start
|
||||
* @param int $limit
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getLogins(int $user_id, int $start = 0, int $limit = 10): array {
|
||||
if ($start < 0) {
|
||||
$start = 0;
|
||||
}
|
||||
|
||||
if ($limit < 1) {
|
||||
$limit = 10;
|
||||
}
|
||||
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "user_login` WHERE `user_id` = '" . (int)$user_id . "' LIMIT " . (int)$start . "," . (int)$limit);
|
||||
|
||||
if ($query->num_rows) {
|
||||
return $query->rows;
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $user_id
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalLogins(int $user_id): int {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "user_login` WHERE `user_id` = '" . (int)$user_id . "'");
|
||||
|
||||
if ($query->num_rows) {
|
||||
return (int)$query->row['total'];
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $user_id
|
||||
* @param array $data
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function addAuthorize(int $user_id, array $data): void {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "user_authorize` SET `user_id` = '" . (int)$user_id . "', `token` = '" . $this->db->escape($data['token']) . "', `ip` = '" . $this->db->escape($data['ip']) . "', `user_agent` = '" . $this->db->escape($data['user_agent']) . "', `date_added` = NOW()");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $user_authorize_id
|
||||
* @param bool $status
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function editAuthorizeStatus(int $user_authorize_id, bool $status): void {
|
||||
$this->db->query("UPDATE `" . DB_PREFIX . "user_authorize` SET `status` = '" . (bool)$status . "' WHERE `user_authorize_id` = '" . (int)$user_authorize_id . "'");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $user_authorize_id
|
||||
* @param int $total
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function editAuthorizeTotal(int $user_authorize_id, int $total): void {
|
||||
$this->db->query("UPDATE `" . DB_PREFIX . "user_authorize` SET `total` = '" . (int)$total . "' WHERE `user_authorize_id` = '" . (int)$user_authorize_id . "'");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $user_authorize_id
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function deleteAuthorize(int $user_authorize_id): void {
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "user_authorize` WHERE `user_authorize_id` = '" . (int)$user_authorize_id . "'");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $user_id
|
||||
* @param string $token
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getAuthorizeByToken(int $user_id, string $token): array {
|
||||
$query = $this->db->query("SELECT *, (SELECT SUM(total) FROM `" . DB_PREFIX . "user_authorize` WHERE `user_id` = '" . (int)$user_id . "') AS `attempts` FROM `" . DB_PREFIX . "user_authorize` WHERE `user_id` = '" . (int)$user_id . "' AND `token` = '" . $this->db->escape($token) . "'");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $user_id
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function resetAuthorizes(int $user_id): void {
|
||||
$this->db->query("UPDATE `" . DB_PREFIX . "user_authorize` SET `total` = '0' WHERE `user_id` = '" . (int)$user_id . "'");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $user_id
|
||||
* @param int $start
|
||||
* @param int $limit
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getAuthorizes(int $user_id, int $start = 0, int $limit = 10): array {
|
||||
if ($start < 0) {
|
||||
$start = 0;
|
||||
}
|
||||
|
||||
if ($limit < 1) {
|
||||
$limit = 10;
|
||||
}
|
||||
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "user_authorize` WHERE `user_id` = '" . (int)$user_id . "' LIMIT " . (int)$start . "," . (int)$limit);
|
||||
|
||||
if ($query->num_rows) {
|
||||
return $query->rows;
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $user_id
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalAuthorizes(int $user_id): int {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS total FROM `" . DB_PREFIX . "user_authorize` WHERE `user_id` = '" . (int)$user_id . "'");
|
||||
|
||||
if ($query->num_rows) {
|
||||
return (int)$query->row['total'];
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
134
admininistrator/model/user/user_group.php
Normal file
134
admininistrator/model/user/user_group.php
Normal file
@ -0,0 +1,134 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Model\User;
|
||||
/**
|
||||
* Class User Group
|
||||
*
|
||||
* @package Opencart\Admin\Model\User
|
||||
*/
|
||||
class UserGroup extends \Opencart\System\Engine\Model {
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function addUserGroup(array $data): int {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "user_group` SET `name` = '" . $this->db->escape((string)$data['name']) . "', `permission` = '" . (isset($data['permission']) ? $this->db->escape(json_encode($data['permission'])) : '') . "'");
|
||||
|
||||
return $this->db->getLastId();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $user_group_id
|
||||
* @param array $data
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function editUserGroup(int $user_group_id, array $data): void {
|
||||
$this->db->query("UPDATE `" . DB_PREFIX . "user_group` SET `name` = '" . $this->db->escape((string)$data['name']) . "', `permission` = '" . (isset($data['permission']) ? $this->db->escape(json_encode($data['permission'])) : '') . "' WHERE `user_group_id` = '" . (int)$user_group_id . "'");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $user_group_id
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function deleteUserGroup(int $user_group_id): void {
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "user_group` WHERE `user_group_id` = '" . (int)$user_group_id . "'");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $user_group_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getUserGroup(int $user_group_id): array {
|
||||
$query = $this->db->query("SELECT DISTINCT * FROM `" . DB_PREFIX . "user_group` WHERE `user_group_id` = '" . (int)$user_group_id . "'");
|
||||
|
||||
$user_group = [
|
||||
'name' => $query->row['name'],
|
||||
'permission' => json_decode($query->row['permission'], true)
|
||||
];
|
||||
|
||||
return $user_group;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getUserGroups(array $data = []): array {
|
||||
$sql = "SELECT * FROM `" . DB_PREFIX . "user_group` ORDER BY `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'];
|
||||
}
|
||||
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
return $query->rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getTotalUserGroups(): int {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "user_group`");
|
||||
|
||||
return (int)$query->row['total'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $user_group_id
|
||||
* @param string $type
|
||||
* @param string $route
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function addPermission(int $user_group_id, string $type, string $route): void {
|
||||
$user_group_query = $this->db->query("SELECT DISTINCT * FROM `" . DB_PREFIX . "user_group` WHERE `user_group_id` = '" . (int)$user_group_id . "'");
|
||||
|
||||
if ($user_group_query->num_rows) {
|
||||
$data = json_decode($user_group_query->row['permission'], true);
|
||||
|
||||
$data[$type][] = $route;
|
||||
|
||||
$this->db->query("UPDATE `" . DB_PREFIX . "user_group` SET `permission` = '" . $this->db->escape(json_encode($data)) . "' WHERE `user_group_id` = '" . (int)$user_group_id . "'");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $user_group_id
|
||||
* @param string $type
|
||||
* @param string $route
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function removePermission(int $user_group_id, string $type, string $route): void {
|
||||
$user_group_query = $this->db->query("SELECT DISTINCT * FROM `" . DB_PREFIX . "user_group` WHERE `user_group_id` = '" . (int)$user_group_id . "'");
|
||||
|
||||
if ($user_group_query->num_rows) {
|
||||
$data = json_decode($user_group_query->row['permission'], true);
|
||||
|
||||
if (isset($data[$type])) {
|
||||
$data[$type] = array_diff($data[$type], [$route]);
|
||||
}
|
||||
|
||||
$this->db->query("UPDATE `" . DB_PREFIX . "user_group` SET `permission` = '" . $this->db->escape(json_encode($data)) . "' WHERE `user_group_id` = '" . (int)$user_group_id . "'");
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user