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'];
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user