first commit
This commit is contained in:
@@ -0,0 +1,105 @@
|
||||
<?php
|
||||
class ModelCatalogAttribute extends Model {
|
||||
public function addAttribute($data) {
|
||||
$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;
|
||||
}
|
||||
|
||||
public function editAttribute($attribute_id, $data) {
|
||||
$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']) . "'");
|
||||
}
|
||||
}
|
||||
|
||||
public function deleteAttribute($attribute_id) {
|
||||
$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 . "'");
|
||||
}
|
||||
|
||||
public function getAttribute($attribute_id) {
|
||||
$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;
|
||||
}
|
||||
|
||||
public function getAttributes($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($data['filter_name']) . "%'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_attribute_group_id'])) {
|
||||
$sql .= " AND a.attribute_group_id = '" . $this->db->escape($data['filter_attribute_group_id']) . "'";
|
||||
}
|
||||
|
||||
$sort_data = array(
|
||||
'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;
|
||||
}
|
||||
|
||||
public function getAttributeDescriptions($attribute_id) {
|
||||
$attribute_data = array();
|
||||
|
||||
$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']] = array('name' => $result['name']);
|
||||
}
|
||||
|
||||
return $attribute_data;
|
||||
}
|
||||
|
||||
public function getTotalAttributes() {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "attribute");
|
||||
|
||||
return $query->row['total'];
|
||||
}
|
||||
|
||||
public function getTotalAttributesByAttributeGroupId($attribute_group_id) {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "attribute WHERE attribute_group_id = '" . (int)$attribute_group_id . "'");
|
||||
|
||||
return $query->row['total'];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
class ModelCatalogAttributeGroup extends Model {
|
||||
public function addAttributeGroup($data) {
|
||||
$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;
|
||||
}
|
||||
|
||||
public function editAttributeGroup($attribute_group_id, $data) {
|
||||
$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']) . "'");
|
||||
}
|
||||
}
|
||||
|
||||
public function deleteAttributeGroup($attribute_group_id) {
|
||||
$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 . "'");
|
||||
}
|
||||
|
||||
public function getAttributeGroup($attribute_group_id) {
|
||||
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "attribute_group WHERE attribute_group_id = '" . (int)$attribute_group_id . "'");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
public function getAttributeGroups($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 = array(
|
||||
'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;
|
||||
}
|
||||
|
||||
public function getAttributeGroupDescriptions($attribute_group_id) {
|
||||
$attribute_group_data = array();
|
||||
|
||||
$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']] = array('name' => $result['name']);
|
||||
}
|
||||
|
||||
return $attribute_group_data;
|
||||
}
|
||||
|
||||
public function getTotalAttributeGroups() {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "attribute_group");
|
||||
|
||||
return $query->row['total'];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,486 @@
|
||||
<?php
|
||||
// * @source See SOURCE.txt for source and other copyright.
|
||||
// * @license GNU General Public License version 3; see LICENSE.txt
|
||||
|
||||
class ModelCatalogCategory extends Model {
|
||||
public function addCategory($data) {
|
||||
$this->db->query("INSERT INTO " . DB_PREFIX . "category SET 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 = '" . (int)$data['status'] . "', noindex = '" . (int)$data['noindex'] . "', date_modified = NOW(), date_added = NOW()");
|
||||
|
||||
$category_id = $this->db->getLastId();
|
||||
|
||||
if (isset($data['image'])) {
|
||||
$this->db->query("UPDATE " . DB_PREFIX . "category SET image = '" . $this->db->escape($data['image']) . "' 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_h1 = '" . $this->db->escape($value['meta_h1']) . "', 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 . "'");
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($data['category_seo_url'])) {
|
||||
foreach ($data['category_seo_url'] as $store_id => $language) {
|
||||
foreach ($language as $language_id => $keyword) {
|
||||
if (!empty($keyword)) {
|
||||
$this->db->query("INSERT INTO " . DB_PREFIX . "seo_url SET store_id = '" . (int)$store_id . "', language_id = '" . (int)$language_id . "', query = 'category_id=" . (int)$category_id . "', keyword = '" . $this->db->escape(trim($keyword)) . "'");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($data['product_related'])) {
|
||||
foreach ($data['product_related'] as $related_id) {
|
||||
$this->db->query("INSERT INTO " . DB_PREFIX . "product_related_wb SET category_id = '" . (int)$category_id . "', product_id = '" . (int)$related_id . "'");
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($data['article_related'])) {
|
||||
foreach ($data['article_related'] as $related_id) {
|
||||
$this->db->query("INSERT INTO " . DB_PREFIX . "article_related_wb SET category_id = '" . (int)$category_id . "', article_id = '" . (int)$related_id . "'");
|
||||
}
|
||||
}
|
||||
|
||||
// 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 . "'");
|
||||
}
|
||||
}
|
||||
|
||||
$this->cache->delete('category');
|
||||
|
||||
if($this->config->get('config_seo_pro')){
|
||||
$this->cache->delete('seopro');
|
||||
}
|
||||
|
||||
return $category_id;
|
||||
}
|
||||
|
||||
public function editCategory($category_id, $data) {
|
||||
$this->db->query("UPDATE " . DB_PREFIX . "category SET 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 = '" . (int)$data['status'] . "', noindex = '" . (int)$data['noindex'] . "', date_modified = NOW() WHERE category_id = '" . (int)$category_id . "'");
|
||||
|
||||
if (isset($data['image'])) {
|
||||
$this->db->query("UPDATE " . DB_PREFIX . "category SET image = '" . $this->db->escape($data['image']) . "' 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_h1 = '" . $this->db->escape($value['meta_h1']) . "', meta_description = '" . $this->db->escape($value['meta_description']) . "', meta_keyword = '" . $this->db->escape($value['meta_keyword']) . "'");
|
||||
}
|
||||
|
||||
// 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'] . "'");
|
||||
|
||||
$path = array();
|
||||
|
||||
// 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) {
|
||||
$path[] = $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) {
|
||||
$path[] = $result['path_id'];
|
||||
}
|
||||
|
||||
// Combine the paths with a new level
|
||||
$level = 0;
|
||||
|
||||
foreach ($path 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 URL
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "seo_url` WHERE query = 'category_id=" . (int)$category_id . "'");
|
||||
|
||||
if (isset($data['category_seo_url'])) {
|
||||
foreach ($data['category_seo_url'] as $store_id => $language) {
|
||||
foreach ($language as $language_id => $keyword) {
|
||||
if (!empty($keyword)) {
|
||||
$this->db->query("INSERT INTO " . DB_PREFIX . "seo_url SET store_id = '" . (int)$store_id . "', language_id = '" . (int)$language_id . "', query = 'category_id=" . (int)$category_id . "', keyword = '" . $this->db->escape(trim($keyword)) . "'");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->db->query("DELETE FROM " . DB_PREFIX . "product_related_wb WHERE category_id = '" . (int)$category_id . "'");
|
||||
|
||||
if (isset($data['product_related'])) {
|
||||
foreach ($data['product_related'] as $related_id) {
|
||||
$this->db->query("DELETE FROM " . DB_PREFIX . "product_related_wb WHERE category_id = '" . (int)$category_id . "' AND product_id = '" . (int)$related_id . "'");
|
||||
$this->db->query("INSERT INTO " . DB_PREFIX . "product_related_wb SET category_id = '" . (int)$category_id . "', product_id = '" . (int)$related_id . "'");
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
$this->db->query("DELETE FROM " . DB_PREFIX . "article_related_wb WHERE category_id = '" . (int)$category_id . "'");
|
||||
|
||||
if (isset($data['article_related'])) {
|
||||
foreach ($data['article_related'] as $related_id) {
|
||||
$this->db->query("DELETE FROM " . DB_PREFIX . "article_related_wb WHERE category_id = '" . (int)$category_id . "' AND article_id = '" . (int)$related_id . "'");
|
||||
$this->db->query("INSERT INTO " . DB_PREFIX . "article_related_wb SET category_id = '" . (int)$category_id . "', article_id = '" . (int)$related_id . "'");
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
$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 . "'");
|
||||
}
|
||||
}
|
||||
|
||||
$this->cache->delete('category');
|
||||
|
||||
if($this->config->get('config_seo_pro')){
|
||||
$this->cache->delete('seopro');
|
||||
}
|
||||
}
|
||||
|
||||
public function editCategoryStatus($category_id, $status) {
|
||||
$this->db->query("UPDATE " . DB_PREFIX . "category SET status = '" . (int)$status . "', date_modified = NOW() WHERE category_id = '" . (int)$category_id . "'");
|
||||
|
||||
$this->cache->delete('category');
|
||||
|
||||
if($this->config->get('config_seo_pro')){
|
||||
$this->cache->delete('seopro');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function deleteCategory($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']);
|
||||
}
|
||||
|
||||
$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 . "seo_url WHERE query = 'category_id=" . (int)$category_id . "'");
|
||||
$this->db->query("DELETE FROM " . DB_PREFIX . "product_related_wb WHERE category_id = '" . (int)$category_id . "'");
|
||||
$this->db->query("DELETE FROM " . DB_PREFIX . "article_related_wb WHERE category_id = '" . (int)$category_id . "'");
|
||||
$this->db->query("DELETE FROM " . DB_PREFIX . "coupon_category WHERE category_id = '" . (int)$category_id . "'");
|
||||
|
||||
$this->cache->delete('category');
|
||||
|
||||
if($this->config->get('config_seo_pro')){
|
||||
$this->cache->delete('seopro');
|
||||
}
|
||||
}
|
||||
|
||||
public function repairCategories($parent_id = 0) {
|
||||
$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']);
|
||||
}
|
||||
}
|
||||
|
||||
public function getCategory($category_id) {
|
||||
$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;
|
||||
}
|
||||
|
||||
public function getAllCategories() {
|
||||
$result = $this->cache->get('category.all.' . $this->config->get('config_language_id') . '.' . (int)$this->config->get('config_store_id'));
|
||||
|
||||
if (!$result || !is_array($result)) {
|
||||
$query = $this->db->query("SELECT c.category_id, c.parent_id, name FROM " . DB_PREFIX . "category c LEFT JOIN " . DB_PREFIX . "category_description cd ON (c.category_id = cd.category_id) LEFT JOIN " . DB_PREFIX . "category_to_store c2s ON (c.category_id = c2s.category_id) WHERE cd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND c2s.store_id = '" . (int)$this->config->get('config_store_id') . "' ORDER BY c.parent_id, c.sort_order, cd.name");
|
||||
|
||||
$categories = array();
|
||||
|
||||
foreach ($query->rows as $row) {
|
||||
$categories[$row['parent_id']][$row['category_id']] = $row;
|
||||
}
|
||||
|
||||
$result = $this->getCategories($categories);
|
||||
|
||||
$this->cache->set('category.all.' . $this->config->get('config_language_id') . '.' . (int)$this->config->get('config_store_id'), $result);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function getCategories($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.noindex 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($data['filter_name']) . "%'";
|
||||
}
|
||||
|
||||
$sql .= " GROUP BY cp.category_id";
|
||||
|
||||
$sort_data = array(
|
||||
'name',
|
||||
'sort_order',
|
||||
'noindex'
|
||||
);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
public function getCategoryDescriptions($category_id) {
|
||||
$category_description_data = array();
|
||||
|
||||
$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']] = array(
|
||||
'name' => $result['name'],
|
||||
'meta_title' => $result['meta_title'],
|
||||
'meta_h1' => $result['meta_h1'],
|
||||
'meta_description' => $result['meta_description'],
|
||||
'meta_keyword' => $result['meta_keyword'],
|
||||
'description' => $result['description']
|
||||
);
|
||||
}
|
||||
|
||||
return $category_description_data;
|
||||
}
|
||||
|
||||
public function getCategoryPath($category_id) {
|
||||
$query = $this->db->query("SELECT category_id, path_id, level FROM " . DB_PREFIX . "category_path WHERE category_id = '" . (int)$category_id . "'");
|
||||
|
||||
return $query->rows;
|
||||
}
|
||||
|
||||
public function getCategoryFilters($category_id) {
|
||||
$category_filter_data = array();
|
||||
|
||||
$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;
|
||||
}
|
||||
|
||||
public function getCategoryStores($category_id) {
|
||||
$category_store_data = array();
|
||||
|
||||
$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;
|
||||
}
|
||||
|
||||
public function getCategorySeoUrls($category_id) {
|
||||
$category_seo_url_data = array();
|
||||
|
||||
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "seo_url WHERE query = 'category_id=" . (int)$category_id . "'");
|
||||
|
||||
foreach ($query->rows as $result) {
|
||||
$category_seo_url_data[$result['store_id']][$result['language_id']] = $result['keyword'];
|
||||
}
|
||||
|
||||
return $category_seo_url_data;
|
||||
}
|
||||
|
||||
public function getCategoryRelated($category_id) {
|
||||
$category_related_data = array();
|
||||
|
||||
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_related_wb WHERE product_id = '" . (int)$product_id . "'");
|
||||
|
||||
foreach ($query->rows as $result) {
|
||||
$product_related_data[] = $result['related_id'];
|
||||
}
|
||||
|
||||
return $product_related_data;
|
||||
}
|
||||
|
||||
public function getCategoryRelated_article($category_id) {
|
||||
$category_related_data = array();
|
||||
|
||||
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "article_related_wb WHERE article_id = '" . (int)$article_id . "'");
|
||||
|
||||
foreach ($query->rows as $result) {
|
||||
$article_related_data[] = $result['related_id'];
|
||||
}
|
||||
|
||||
return $article_related_data;
|
||||
}
|
||||
|
||||
public function getCategoryLayouts($category_id) {
|
||||
$category_layout_data = array();
|
||||
|
||||
$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;
|
||||
}
|
||||
|
||||
public function getTotalCategories() {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "category");
|
||||
|
||||
return $query->row['total'];
|
||||
}
|
||||
|
||||
public function getTotalCategoriesByLayoutId($layout_id) {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "category_to_layout WHERE layout_id = '" . (int)$layout_id . "'");
|
||||
|
||||
return $query->row['total'];
|
||||
}
|
||||
|
||||
public function getCategoriesByParentId($parent_id = 0) {
|
||||
$query = $this->db->query("SELECT *, (SELECT COUNT(parent_id) FROM " . DB_PREFIX . "category WHERE parent_id = c.category_id) AS children FROM " . DB_PREFIX . "category c LEFT JOIN " . DB_PREFIX . "category_description cd ON (c.category_id = cd.category_id) WHERE c.parent_id = '" . (int)$parent_id . "' AND cd.language_id = '" . (int)$this->config->get('config_language_id') . "' ORDER BY c.sort_order, cd.name");
|
||||
return $query->rows;
|
||||
}
|
||||
|
||||
public function getCategoriesChildren($parent_id = 0) {
|
||||
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "category_path WHERE path_id = '" . (int)$parent_id . "'");
|
||||
return $query->rows;
|
||||
}
|
||||
|
||||
public function getProductRelated($category_id) {
|
||||
$product_related_data = array();
|
||||
|
||||
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_related_wb WHERE category_id = '" . (int)$category_id . "'");
|
||||
|
||||
foreach ($query->rows as $result) {
|
||||
$product_related_data[] = $result['product_id'];
|
||||
}
|
||||
|
||||
return $product_related_data;
|
||||
}
|
||||
|
||||
public function getArticleRelated($category_id) {
|
||||
$article_related_data = array();
|
||||
|
||||
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "article_related_wb WHERE category_id = '" . (int)$category_id . "'");
|
||||
|
||||
foreach ($query->rows as $result) {
|
||||
$article_related_data[] = $result['article_id'];
|
||||
}
|
||||
|
||||
return $article_related_data;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
<?php
|
||||
class ModelCatalogDownload extends Model {
|
||||
public function addDownload($data) {
|
||||
$this->db->query("INSERT INTO " . DB_PREFIX . "download SET filename = '" . $this->db->escape($data['filename']) . "', mask = '" . $this->db->escape($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;
|
||||
}
|
||||
|
||||
public function editDownload($download_id, $data) {
|
||||
$this->db->query("UPDATE " . DB_PREFIX . "download SET filename = '" . $this->db->escape($data['filename']) . "', mask = '" . $this->db->escape($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']) . "'");
|
||||
}
|
||||
}
|
||||
|
||||
public function deleteDownload($download_id) {
|
||||
$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 . "'");
|
||||
}
|
||||
|
||||
public function getDownload($download_id) {
|
||||
$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;
|
||||
}
|
||||
|
||||
public function getDownloads($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($data['filter_name']) . "%'";
|
||||
}
|
||||
|
||||
$sort_data = array(
|
||||
'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;
|
||||
}
|
||||
|
||||
public function getDownloadDescriptions($download_id) {
|
||||
$download_description_data = array();
|
||||
|
||||
$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']] = array('name' => $result['name']);
|
||||
}
|
||||
|
||||
return $download_description_data;
|
||||
}
|
||||
|
||||
public function getTotalDownloads() {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "download");
|
||||
|
||||
return $query->row['total'];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,179 @@
|
||||
<?php
|
||||
class ModelCatalogFilter extends Model {
|
||||
public function addFilter($data) {
|
||||
$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;
|
||||
}
|
||||
|
||||
public function editFilter($filter_group_id, $data) {
|
||||
$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']) . "'");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function deleteFilter($filter_group_id) {
|
||||
$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 . "'");
|
||||
}
|
||||
|
||||
public function getFilterGroup($filter_group_id) {
|
||||
$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;
|
||||
}
|
||||
|
||||
public function getFilterGroups($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 = array(
|
||||
'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;
|
||||
}
|
||||
|
||||
public function getFilterGroupDescriptions($filter_group_id) {
|
||||
$filter_group_data = array();
|
||||
|
||||
$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']] = array('name' => $result['name']);
|
||||
}
|
||||
|
||||
return $filter_group_data;
|
||||
}
|
||||
|
||||
public function getFilter($filter_id) {
|
||||
$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;
|
||||
}
|
||||
|
||||
public function getFilters($data) {
|
||||
$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($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;
|
||||
}
|
||||
|
||||
public function getFilterDescriptions($filter_group_id) {
|
||||
$filter_data = array();
|
||||
|
||||
$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 = array();
|
||||
|
||||
$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']] = array('name' => $filter_description['name']);
|
||||
}
|
||||
|
||||
$filter_data[] = array(
|
||||
'filter_id' => $filter['filter_id'],
|
||||
'filter_description' => $filter_description_data,
|
||||
'sort_order' => $filter['sort_order']
|
||||
);
|
||||
}
|
||||
|
||||
return $filter_data;
|
||||
}
|
||||
|
||||
public function getTotalFilterGroups() {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS total FROM `" . DB_PREFIX . "filter_group`");
|
||||
|
||||
return $query->row['total'];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,223 @@
|
||||
<?php
|
||||
// * @source See SOURCE.txt for source and other copyright.
|
||||
// * @license GNU General Public License version 3; see LICENSE.txt
|
||||
|
||||
class ModelCatalogInformation extends Model {
|
||||
public function addInformation($data) {
|
||||
$this->db->query("INSERT INTO " . DB_PREFIX . "information SET sort_order = '" . (int)$data['sort_order'] . "', bottom = '" . (isset($data['bottom']) ? (int)$data['bottom'] : 0) . "', status = '" . (int)$data['status'] . "', noindex = '" . (int)$data['noindex'] . "'");
|
||||
|
||||
$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_h1 = '" . $this->db->escape($value['meta_h1']) . "', 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) {
|
||||
if (!empty($keyword)) {
|
||||
$this->db->query("INSERT INTO " . DB_PREFIX . "seo_url SET store_id = '" . (int)$store_id . "', language_id = '" . (int)$language_id . "', query = 'information_id=" . (int)$information_id . "', keyword = '" . $this->db->escape(trim($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;
|
||||
}
|
||||
|
||||
public function editInformation($information_id, $data) {
|
||||
$this->db->query("UPDATE " . DB_PREFIX . "information SET sort_order = '" . (int)$data['sort_order'] . "', bottom = '" . (isset($data['bottom']) ? (int)$data['bottom'] : 0) . "', status = '" . (int)$data['status'] . "', noindex = '" . (int)$data['noindex'] . "' 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_h1 = '" . $this->db->escape($value['meta_h1']) . "', 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 query = 'information_id=" . (int)$information_id . "'");
|
||||
|
||||
if (isset($data['information_seo_url'])) {
|
||||
foreach ($data['information_seo_url'] as $store_id => $language) {
|
||||
foreach ($language as $language_id => $keyword) {
|
||||
if (trim($keyword)) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "seo_url` SET store_id = '" . (int)$store_id . "', language_id = '" . (int)$language_id . "', query = 'information_id=" . (int)$information_id . "', keyword = '" . $this->db->escape(trim($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');
|
||||
}
|
||||
|
||||
public function editInformationStatus($information_id, $status) {
|
||||
$this->db->query("UPDATE " . DB_PREFIX . "information SET status = '" . (int)$status . "'WHERE information_id = '" . (int)$information_id . "'");
|
||||
|
||||
$this->cache->delete('information');
|
||||
|
||||
}
|
||||
|
||||
public function deleteInformation($information_id) {
|
||||
$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 query = 'information_id=" . (int)$information_id . "'");
|
||||
|
||||
$this->cache->delete('information');
|
||||
}
|
||||
|
||||
public function getInformation($information_id) {
|
||||
$query = $this->db->query("SELECT DISTINCT * FROM " . DB_PREFIX . "information WHERE information_id = '" . (int)$information_id . "'");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
public function getInformations($data = array()) {
|
||||
if ($data) {
|
||||
$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 = array(
|
||||
'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'];
|
||||
}
|
||||
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
return $query->rows;
|
||||
} else {
|
||||
$information_data = $this->cache->get('information.' . (int)$this->config->get('config_language_id'));
|
||||
|
||||
if (!$information_data) {
|
||||
$query = $this->db->query("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') . "' ORDER BY id.title");
|
||||
|
||||
$information_data = $query->rows;
|
||||
|
||||
$this->cache->set('information.' . (int)$this->config->get('config_language_id'), $information_data);
|
||||
}
|
||||
|
||||
return $information_data;
|
||||
}
|
||||
}
|
||||
|
||||
public function getInformationDescriptions($information_id) {
|
||||
$information_description_data = array();
|
||||
|
||||
$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']] = array(
|
||||
'title' => $result['title'],
|
||||
'description' => $result['description'],
|
||||
'meta_title' => $result['meta_title'],
|
||||
'meta_h1' => $result['meta_h1'],
|
||||
'meta_description' => $result['meta_description'],
|
||||
'meta_keyword' => $result['meta_keyword']
|
||||
);
|
||||
}
|
||||
|
||||
return $information_description_data;
|
||||
}
|
||||
|
||||
public function getInformationStores($information_id) {
|
||||
$information_store_data = array();
|
||||
|
||||
$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;
|
||||
}
|
||||
|
||||
public function getInformationSeoUrls($information_id) {
|
||||
$information_seo_url_data = array();
|
||||
|
||||
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "seo_url WHERE query = 'information_id=" . (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;
|
||||
}
|
||||
|
||||
public function getInformationLayouts($information_id) {
|
||||
$information_layout_data = array();
|
||||
|
||||
$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;
|
||||
}
|
||||
|
||||
public function getTotalInformations() {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "information");
|
||||
|
||||
return $query->row['total'];
|
||||
}
|
||||
|
||||
public function getTotalInformationsByLayoutId($layout_id) {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "information_to_layout WHERE layout_id = '" . (int)$layout_id . "'");
|
||||
|
||||
return $query->row['total'];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,267 @@
|
||||
<?php
|
||||
// * @source See SOURCE.txt for source and other copyright.
|
||||
// * @license GNU General Public License version 3; see LICENSE.txt
|
||||
|
||||
class ModelCatalogManufacturer extends Model {
|
||||
public function addManufacturer($data) {
|
||||
$this->db->query("INSERT INTO " . DB_PREFIX . "manufacturer SET name = '" . $this->db->escape($data['name']) . "', sort_order = '" . (int)$data['sort_order'] . "', noindex = '" . (int)$data['noindex'] . "'");
|
||||
|
||||
$manufacturer_id = $this->db->getLastId();
|
||||
|
||||
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 . "'");
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($data['image'])) {
|
||||
$this->db->query("UPDATE " . DB_PREFIX . "manufacturer SET image = '" . $this->db->escape($data['image']) . "' WHERE manufacturer_id = '" . (int)$manufacturer_id . "'");
|
||||
}
|
||||
|
||||
foreach ($data['manufacturer_description'] as $language_id => $value) {
|
||||
$this->db->query("INSERT INTO " . DB_PREFIX . "manufacturer_description SET manufacturer_id = '" . (int)$manufacturer_id . "', language_id = '" . (int)$language_id . "', description = '" . $this->db->escape($value['description']) . "', meta_title = '" . $this->db->escape($value['meta_title']) . "', meta_h1 = '" . $this->db->escape($value['meta_h1']) . "', meta_description = '" . $this->db->escape($value['meta_description']) . "', meta_keyword = '" . $this->db->escape($value['meta_keyword']) . "'");
|
||||
}
|
||||
|
||||
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 . "'");
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($data['product_related'])) {
|
||||
foreach ($data['product_related'] as $related_id) {
|
||||
$this->db->query("INSERT INTO " . DB_PREFIX . "product_related_mn SET manufacturer_id = '" . (int)$manufacturer_id . "', product_id = '" . (int)$related_id . "'");
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($data['article_related'])) {
|
||||
foreach ($data['article_related'] as $related_id) {
|
||||
$this->db->query("INSERT INTO " . DB_PREFIX . "article_related_mn SET manufacturer_id = '" . (int)$manufacturer_id . "', article_id = '" . (int)$related_id . "'");
|
||||
}
|
||||
}
|
||||
|
||||
// SEO URL
|
||||
if (isset($data['manufacturer_seo_url'])) {
|
||||
foreach ($data['manufacturer_seo_url'] as $store_id => $language) {
|
||||
foreach ($language as $language_id => $keyword) {
|
||||
if (!empty($keyword)) {
|
||||
$this->db->query("INSERT INTO " . DB_PREFIX . "seo_url SET store_id = '" . (int)$store_id . "', language_id = '" . (int)$language_id . "', query = 'manufacturer_id=" . (int)$manufacturer_id . "', keyword = '" . $this->db->escape(trim($keyword)) . "'");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->cache->delete('manufacturer');
|
||||
|
||||
return $manufacturer_id;
|
||||
}
|
||||
|
||||
public function editManufacturer($manufacturer_id, $data) {
|
||||
|
||||
$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->db->query("UPDATE " . DB_PREFIX . "manufacturer SET name = '" . $this->db->escape($data['name']) . "', sort_order = '" . (int)$data['sort_order'] . "', noindex = '" . (int)$data['noindex'] . "' WHERE manufacturer_id = '" . (int)$manufacturer_id . "'");
|
||||
|
||||
if (isset($data['image'])) {
|
||||
$this->db->query("UPDATE " . DB_PREFIX . "manufacturer SET image = '" . $this->db->escape($data['image']) . "' WHERE manufacturer_id = '" . (int)$manufacturer_id . "'");
|
||||
}
|
||||
|
||||
$this->db->query("DELETE FROM " . DB_PREFIX . "manufacturer_description WHERE manufacturer_id = '" . (int)$manufacturer_id . "'");
|
||||
|
||||
foreach ($data['manufacturer_description'] as $language_id => $value) {
|
||||
$this->db->query("INSERT INTO " . DB_PREFIX . "manufacturer_description SET manufacturer_id = '" . (int)$manufacturer_id . "', language_id = '" . (int)$language_id . "', description = '" . $this->db->escape($value['description']) . "', meta_title = '" . $this->db->escape($value['meta_title']) . "', meta_h1 = '" . $this->db->escape($value['meta_h1']) . "', meta_description = '" . $this->db->escape($value['meta_description']) . "', meta_keyword = '" . $this->db->escape($value['meta_keyword']) . "'");
|
||||
}
|
||||
|
||||
$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 . "product_related_mn WHERE manufacturer_id = '" . (int)$manufacturer_id . "'");
|
||||
|
||||
if (isset($data['product_related'])) {
|
||||
foreach ($data['product_related'] as $related_id) {
|
||||
$this->db->query("DELETE FROM " . DB_PREFIX . "product_related_mn WHERE manufacturer_id = '" . (int)$manufacturer_id . "' AND product_id = '" . (int)$related_id . "'");
|
||||
$this->db->query("INSERT INTO " . DB_PREFIX . "product_related_mn SET manufacturer_id = '" . (int)$manufacturer_id . "', product_id = '" . (int)$related_id . "'");
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
$this->db->query("DELETE FROM " . DB_PREFIX . "article_related_mn WHERE manufacturer_id = '" . (int)$manufacturer_id . "'");
|
||||
|
||||
if (isset($data['article_related'])) {
|
||||
foreach ($data['article_related'] as $related_id) {
|
||||
$this->db->query("DELETE FROM " . DB_PREFIX . "article_related_mn WHERE manufacturer_id = '" . (int)$manufacturer_id . "' AND article_id = '" . (int)$related_id . "'");
|
||||
$this->db->query("INSERT INTO " . DB_PREFIX . "article_related_mn SET manufacturer_id = '" . (int)$manufacturer_id . "', article_id = '" . (int)$related_id . "'");
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "seo_url` WHERE query = 'manufacturer_id=" . (int)$manufacturer_id . "'");
|
||||
|
||||
if (isset($data['manufacturer_seo_url'])) {
|
||||
foreach ($data['manufacturer_seo_url'] as $store_id => $language) {
|
||||
foreach ($language as $language_id => $keyword) {
|
||||
if (!empty($keyword)) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "seo_url` SET store_id = '" . (int)$store_id . "', language_id = '" . (int)$language_id . "', query = 'manufacturer_id=" . (int)$manufacturer_id . "', keyword = '" . $this->db->escape(trim($keyword)) . "'");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->cache->delete('manufacturer');
|
||||
}
|
||||
|
||||
public function deleteManufacturer($manufacturer_id) {
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "manufacturer` 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 . "manufacturer_description` 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 . "seo_url` WHERE query = 'manufacturer_id=" . (int)$manufacturer_id . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "product_related_mn` WHERE manufacturer_id = '" . (int)$manufacturer_id . "'");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "article_related_mn` WHERE manufacturer_id = '" . (int)$manufacturer_id . "'");
|
||||
|
||||
$this->cache->delete('manufacturer');
|
||||
}
|
||||
|
||||
public function getManufacturer($manufacturer_id) {
|
||||
$query = $this->db->query("SELECT DISTINCT * FROM " . DB_PREFIX . "manufacturer WHERE manufacturer_id = '" . (int)$manufacturer_id . "'");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
public function getManufacturers($data = array()) {
|
||||
$sql = "SELECT * FROM " . DB_PREFIX . "manufacturer";
|
||||
|
||||
if (!empty($data['filter_name'])) {
|
||||
$sql .= " WHERE name LIKE '" . $this->db->escape($data['filter_name']) . "%'";
|
||||
}
|
||||
|
||||
$sort_data = array(
|
||||
'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;
|
||||
}
|
||||
|
||||
public function getManufacturerStores($manufacturer_id) {
|
||||
$manufacturer_store_data = array();
|
||||
|
||||
$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;
|
||||
}
|
||||
|
||||
public function getManufacturerSeoUrls($manufacturer_id) {
|
||||
$manufacturer_seo_url_data = array();
|
||||
|
||||
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "seo_url WHERE query = 'manufacturer_id=" . (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;
|
||||
}
|
||||
|
||||
public function getManufacturerLayouts($manufacturer_id) {
|
||||
$manufacturer_layout_data = array();
|
||||
$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;
|
||||
}
|
||||
|
||||
public function getTotalManufacturerByLayoutId($layout_id) {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "manufacturer_to_layout WHERE layout_id = '" . (int)$layout_id . "'");
|
||||
return $query->row['total'];
|
||||
}
|
||||
|
||||
public function getTotalManufacturers() {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "manufacturer");
|
||||
|
||||
return $query->row['total'];
|
||||
}
|
||||
|
||||
public function getManufacturerDescriptions($manufacturer_id) {
|
||||
$manufacturer_description_data = array();
|
||||
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "manufacturer_description WHERE manufacturer_id = '" . (int)$manufacturer_id . "'");
|
||||
foreach ($query->rows as $result) {
|
||||
$manufacturer_description_data[$result['language_id']] = array(
|
||||
'meta_title' => $result['meta_title'],
|
||||
'meta_h1' => $result['meta_h1'],
|
||||
'meta_description' => $result['meta_description'],
|
||||
'meta_keyword' => $result['meta_keyword'],
|
||||
'description' => $result['description']
|
||||
);
|
||||
}
|
||||
return $manufacturer_description_data;
|
||||
}
|
||||
|
||||
public function getProductRelated($manufacturer_id) {
|
||||
$product_related_data = array();
|
||||
|
||||
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_related_mn WHERE manufacturer_id = '" . (int)$manufacturer_id . "'");
|
||||
|
||||
foreach ($query->rows as $result) {
|
||||
$product_related_data[] = $result['product_id'];
|
||||
}
|
||||
|
||||
return $product_related_data;
|
||||
}
|
||||
|
||||
public function getArticleRelated($manufacturer_id) {
|
||||
$article_related_data = array();
|
||||
|
||||
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "article_related_mn WHERE manufacturer_id = '" . (int)$manufacturer_id . "'");
|
||||
|
||||
foreach ($query->rows as $result) {
|
||||
$article_related_data[] = $result['article_id'];
|
||||
}
|
||||
|
||||
return $article_related_data;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,177 @@
|
||||
<?php
|
||||
class ModelCatalogOption extends Model {
|
||||
public function addOption($data) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "option` SET type = '" . $this->db->escape($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;
|
||||
}
|
||||
|
||||
public function editOption($option_id, $data) {
|
||||
$this->db->query("UPDATE `" . DB_PREFIX . "option` SET type = '" . $this->db->escape($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']) . "'");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public function deleteOption($option_id) {
|
||||
$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 . "'");
|
||||
}
|
||||
|
||||
public function getOption($option_id) {
|
||||
$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;
|
||||
}
|
||||
|
||||
public function getOptions($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($data['filter_name']) . "%'";
|
||||
}
|
||||
|
||||
$sort_data = array(
|
||||
'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;
|
||||
}
|
||||
|
||||
public function getOptionDescriptions($option_id) {
|
||||
$option_data = array();
|
||||
|
||||
$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']] = array('name' => $result['name']);
|
||||
}
|
||||
|
||||
return $option_data;
|
||||
}
|
||||
|
||||
public function getOptionValue($option_value_id) {
|
||||
$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;
|
||||
}
|
||||
|
||||
public function getOptionValues($option_id) {
|
||||
$option_value_data = array();
|
||||
|
||||
$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[] = array(
|
||||
'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;
|
||||
}
|
||||
|
||||
public function getOptionValueDescriptions($option_id) {
|
||||
$option_value_data = array();
|
||||
|
||||
$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 = array();
|
||||
|
||||
$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']] = array('name' => $option_value_description['name']);
|
||||
}
|
||||
|
||||
$option_value_data[] = array(
|
||||
'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;
|
||||
}
|
||||
|
||||
public function getTotalOptions() {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS total FROM `" . DB_PREFIX . "option`");
|
||||
|
||||
return $query->row['total'];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,917 @@
|
||||
<?php
|
||||
// * @source See SOURCE.txt for source and other copyright.
|
||||
// * @license GNU General Public License version 3; see LICENSE.txt
|
||||
|
||||
class ModelCatalogProduct extends Model {
|
||||
public function addProduct($data) {
|
||||
$this->db->query("INSERT INTO " . DB_PREFIX . "product SET model = '" . $this->db->escape($data['model']) . "', sku = '" . $this->db->escape($data['sku']) . "', upc = '" . $this->db->escape($data['upc']) . "', ean = '" . $this->db->escape($data['ean']) . "', jan = '" . $this->db->escape($data['jan']) . "', isbn = '" . $this->db->escape($data['isbn']) . "', mpn = '" . $this->db->escape($data['mpn']) . "', location = '" . $this->db->escape($data['location']) . "', quantity = '" . (int)$data['quantity'] . "', minimum = '" . (int)$data['minimum'] . "', subtract = '" . (int)$data['subtract'] . "', stock_status_id = '" . (int)$data['stock_status_id'] . "', date_available = '" . $this->db->escape($data['date_available']) . "', manufacturer_id = '" . (int)$data['manufacturer_id'] . "', shipping = '" . (int)$data['shipping'] . "', price = '" . (float)$data['price'] . "',price_2 = '" . (float)$data['price_2'] . "',price_3 = '" . (float)$data['price_3'] . "', points = '" . (int)$data['points'] . "', weight = '" . (float)$data['weight'] . "', weight_class_id = '" . (int)$data['weight_class_id'] . "', length = '" . (float)$data['length'] . "', width = '" . (float)$data['width'] . "', height = '" . (float)$data['height'] . "', length_class_id = '" . (int)$data['length_class_id'] . "', status = '" . (int)$data['status'] . "', noindex = '" . (int)$data['noindex'] . "', tax_class_id = '" . (int)$data['tax_class_id'] . "', sort_order = '" . (int)$data['sort_order'] . "', date_added = NOW(), date_modified = NOW()");
|
||||
|
||||
$product_id = $this->db->getLastId();
|
||||
|
||||
if (isset($data['image'])) {
|
||||
$this->db->query("UPDATE " . DB_PREFIX . "product SET image = '" . $this->db->escape($data['image']) . "' WHERE product_id = '" . (int)$product_id . "'");
|
||||
}
|
||||
|
||||
foreach ($data['product_description'] as $language_id => $value) {
|
||||
$this->db->query("INSERT INTO " . DB_PREFIX . "product_description SET product_id = '" . (int)$product_id . "', language_id = '" . (int)$language_id . "', name = '" . $this->db->escape($value['name']) . "', description = '" . $this->db->escape($value['description']) . "', tag = '" . $this->db->escape($value['tag']) . "', meta_title = '" . $this->db->escape($value['meta_title']) . "', meta_h1 = '" . $this->db->escape($value['meta_h1']) . "', meta_description = '" . $this->db->escape($value['meta_description']) . "', meta_keyword = '" . $this->db->escape($value['meta_keyword']) . "'");
|
||||
}
|
||||
|
||||
if (isset($data['product_store'])) {
|
||||
foreach ($data['product_store'] as $store_id) {
|
||||
$this->db->query("INSERT INTO " . DB_PREFIX . "product_to_store SET product_id = '" . (int)$product_id . "', store_id = '" . (int)$store_id . "'");
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($data['product_attribute'])) {
|
||||
foreach ($data['product_attribute'] as $product_attribute) {
|
||||
if ($product_attribute['attribute_id']) {
|
||||
// Removes duplicates
|
||||
$this->db->query("DELETE FROM " . DB_PREFIX . "product_attribute WHERE product_id = '" . (int)$product_id . "' AND attribute_id = '" . (int)$product_attribute['attribute_id'] . "'");
|
||||
|
||||
foreach ($product_attribute['product_attribute_description'] as $language_id => $product_attribute_description) {
|
||||
$this->db->query("DELETE FROM " . DB_PREFIX . "product_attribute WHERE product_id = '" . (int)$product_id . "' AND attribute_id = '" . (int)$product_attribute['attribute_id'] . "' AND language_id = '" . (int)$language_id . "'");
|
||||
|
||||
$this->db->query("INSERT INTO " . DB_PREFIX . "product_attribute SET product_id = '" . (int)$product_id . "', attribute_id = '" . (int)$product_attribute['attribute_id'] . "', language_id = '" . (int)$language_id . "', text = '" . $this->db->escape($product_attribute_description['text']) . "'");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($data['product_option'])) {
|
||||
foreach ($data['product_option'] as $product_option) {
|
||||
if ($product_option['type'] == 'select' || $product_option['type'] == 'radio' || $product_option['type'] == 'checkbox' || $product_option['type'] == 'image') {
|
||||
if (isset($product_option['product_option_value'])) {
|
||||
$this->db->query("INSERT INTO " . DB_PREFIX . "product_option SET product_id = '" . (int)$product_id . "', option_id = '" . (int)$product_option['option_id'] . "', required = '" . (int)$product_option['required'] . "'");
|
||||
|
||||
$product_option_id = $this->db->getLastId();
|
||||
|
||||
foreach ($product_option['product_option_value'] as $product_option_value) {
|
||||
$this->db->query("INSERT INTO " . DB_PREFIX . "product_option_value SET product_option_id = '" . (int)$product_option_id . "', product_id = '" . (int)$product_id . "', option_id = '" . (int)$product_option['option_id'] . "', option_value_id = '" . (int)$product_option_value['option_value_id'] . "', quantity = '" . (int)$product_option_value['quantity'] . "', subtract = '" . (int)$product_option_value['subtract'] . "', price = '" . (float)$product_option_value['price'] . "', price_prefix = '" . $this->db->escape($product_option_value['price_prefix']) . "', points = '" . (int)$product_option_value['points'] . "', points_prefix = '" . $this->db->escape($product_option_value['points_prefix']) . "', weight = '" . (float)$product_option_value['weight'] . "', weight_prefix = '" . $this->db->escape($product_option_value['weight_prefix']) . "'");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$this->db->query("INSERT INTO " . DB_PREFIX . "product_option SET product_id = '" . (int)$product_id . "', option_id = '" . (int)$product_option['option_id'] . "', value = '" . $this->db->escape($product_option['value']) . "', required = '" . (int)$product_option['required'] . "'");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($data['product_recurring'])) {
|
||||
foreach ($data['product_recurring'] as $recurring) {
|
||||
|
||||
$query = $this->db->query("SELECT `product_id` FROM `" . DB_PREFIX . "product_recurring` WHERE `product_id` = '" . (int)$product_id . "' AND `customer_group_id = '" . (int)$recurring['customer_group_id'] . "' AND `recurring_id` = '" . (int)$recurring['recurring_id'] . "'");
|
||||
|
||||
if (!$query->num_rows) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "product_recurring` SET `product_id` = '" . (int)$product_id . "', customer_group_id = '" . (int)$recurring['customer_group_id'] . "', `recurring_id` = '" . (int)$recurring['recurring_id'] . "'");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($data['product_discount'])) {
|
||||
foreach ($data['product_discount'] as $product_discount) {
|
||||
$this->db->query("INSERT INTO " . DB_PREFIX . "product_discount SET product_id = '" . (int)$product_id . "', customer_group_id = '" . (int)$product_discount['customer_group_id'] . "', quantity = '" . (int)$product_discount['quantity'] . "', priority = '" . (int)$product_discount['priority'] . "', price = '" . (float)$product_discount['price'] . "', date_start = '" . $this->db->escape($product_discount['date_start']) . "', date_end = '" . $this->db->escape($product_discount['date_end']) . "'");
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($data['product_special'])) {
|
||||
foreach ($data['product_special'] as $product_special) {
|
||||
$this->db->query("INSERT INTO " . DB_PREFIX . "product_special SET product_id = '" . (int)$product_id . "', customer_group_id = '" . (int)$product_special['customer_group_id'] . "', priority = '" . (int)$product_special['priority'] . "', price = '" . (float)$product_special['price'] . "', date_start = '" . $this->db->escape($product_special['date_start']) . "', date_end = '" . $this->db->escape($product_special['date_end']) . "'");
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($data['product_image'])) {
|
||||
foreach ($data['product_image'] as $product_image) {
|
||||
$this->db->query("INSERT INTO " . DB_PREFIX . "product_image SET product_id = '" . (int)$product_id . "', image = '" . $this->db->escape($product_image['image']) . "', sort_order = '" . (int)$product_image['sort_order'] . "'");
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($data['product_download'])) {
|
||||
foreach ($data['product_download'] as $download_id) {
|
||||
$this->db->query("INSERT INTO " . DB_PREFIX . "product_to_download SET product_id = '" . (int)$product_id . "', download_id = '" . (int)$download_id . "'");
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($data['product_category'])) {
|
||||
foreach ($data['product_category'] as $category_id) {
|
||||
$this->db->query("INSERT INTO " . DB_PREFIX . "product_to_category SET product_id = '" . (int)$product_id . "', category_id = '" . (int)$category_id . "'");
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($data['main_category_id']) && $data['main_category_id'] > 0) {
|
||||
$this->db->query("DELETE FROM " . DB_PREFIX . "product_to_category WHERE product_id = '" . (int)$product_id . "' AND category_id = '" . (int)$data['main_category_id'] . "'");
|
||||
$this->db->query("INSERT INTO " . DB_PREFIX . "product_to_category SET product_id = '" . (int)$product_id . "', category_id = '" . (int)$data['main_category_id'] . "', main_category = 1");
|
||||
} elseif (isset($data['product_category'][0])) {
|
||||
$this->db->query("UPDATE " . DB_PREFIX . "product_to_category SET main_category = 1 WHERE product_id = '" . (int)$product_id . "' AND category_id = '" . (int)$data['product_category'][0] . "'");
|
||||
}
|
||||
|
||||
if (isset($data['product_filter'])) {
|
||||
foreach ($data['product_filter'] as $filter_id) {
|
||||
$this->db->query("INSERT INTO " . DB_PREFIX . "product_filter SET product_id = '" . (int)$product_id . "', filter_id = '" . (int)$filter_id . "'");
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($data['product_related'])) {
|
||||
foreach ($data['product_related'] as $related_id) {
|
||||
$this->db->query("DELETE FROM " . DB_PREFIX . "product_related WHERE product_id = '" . (int)$product_id . "' AND related_id = '" . (int)$related_id . "'");
|
||||
$this->db->query("INSERT INTO " . DB_PREFIX . "product_related SET product_id = '" . (int)$product_id . "', related_id = '" . (int)$related_id . "'");
|
||||
$this->db->query("DELETE FROM " . DB_PREFIX . "product_related WHERE product_id = '" . (int)$related_id . "' AND related_id = '" . (int)$product_id . "'");
|
||||
$this->db->query("INSERT INTO " . DB_PREFIX . "product_related SET product_id = '" . (int)$related_id . "', related_id = '" . (int)$product_id . "'");
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($data['product_related_article'])) {
|
||||
foreach ($data['product_related_article'] as $article_id) {
|
||||
$this->db->query("DELETE FROM " . DB_PREFIX . "product_related_article WHERE product_id = '" . (int)$product_id . "' AND article_id = '" . (int)$article_id . "'");
|
||||
$this->db->query("INSERT INTO " . DB_PREFIX . "product_related_article SET product_id = '" . (int)$product_id . "', article_id = '" . (int)$article_id . "'");
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($data['product_reward'])) {
|
||||
foreach ($data['product_reward'] as $customer_group_id => $product_reward) {
|
||||
if ((int)$product_reward['points'] > 0) {
|
||||
$this->db->query("INSERT INTO " . DB_PREFIX . "product_reward SET product_id = '" . (int)$product_id . "', customer_group_id = '" . (int)$customer_group_id . "', points = '" . (int)$product_reward['points'] . "'");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// SEO URL
|
||||
if (isset($data['product_seo_url'])) {
|
||||
foreach ($data['product_seo_url'] as $store_id => $language) {
|
||||
foreach ($language as $language_id => $keyword) {
|
||||
if (!empty($keyword)) {
|
||||
$this->db->query("INSERT INTO " . DB_PREFIX . "seo_url SET store_id = '" . (int)$store_id . "', language_id = '" . (int)$language_id . "', query = 'product_id=" . (int)$product_id . "', keyword = '" . $this->db->escape(trim($keyword)) . "'");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($data['product_layout'])) {
|
||||
foreach ($data['product_layout'] as $store_id => $layout_id) {
|
||||
$this->db->query("INSERT INTO " . DB_PREFIX . "product_to_layout SET product_id = '" . (int)$product_id . "', store_id = '" . (int)$store_id . "', layout_id = '" . (int)$layout_id . "'");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$this->cache->delete('product');
|
||||
|
||||
if($this->config->get('config_seo_pro')){
|
||||
$this->cache->delete('seopro');
|
||||
}
|
||||
|
||||
return $product_id;
|
||||
}
|
||||
|
||||
public function editProduct($product_id, $data) {
|
||||
$this->db->query("UPDATE " . DB_PREFIX . "product SET model = '" . $this->db->escape($data['model']) . "', sku = '" . $this->db->escape($data['sku']) . "', upc = '" . $this->db->escape($data['upc']) . "', ean = '" . $this->db->escape($data['ean']) . "', jan = '" . $this->db->escape($data['jan']) . "', isbn = '" . $this->db->escape($data['isbn']) . "', mpn = '" . $this->db->escape($data['mpn']) . "', location = '" . $this->db->escape($data['location']) . "', quantity = '" . (int)$data['quantity'] . "', minimum = '" . (int)$data['minimum'] . "', subtract = '" . (int)$data['subtract'] . "', stock_status_id = '" . (int)$data['stock_status_id'] . "', date_available = '" . $this->db->escape($data['date_available']) . "', manufacturer_id = '" . (int)$data['manufacturer_id'] . "', shipping = '" . (int)$data['shipping'] . "', price = '" . (float)$data['price'] . "',price_2 = '" . (float)$data['price_2'] . "',price_3 = '" . (float)$data['price_3'] . "', points = '" . (int)$data['points'] . "', weight = '" . (float)$data['weight'] . "', weight_class_id = '" . (int)$data['weight_class_id'] . "', length = '" . (float)$data['length'] . "', width = '" . (float)$data['width'] . "', height = '" . (float)$data['height'] . "', length_class_id = '" . (int)$data['length_class_id'] . "', status = '" . (int)$data['status'] . "', noindex = '" . (int)$data['noindex'] . "', tax_class_id = '" . (int)$data['tax_class_id'] . "', sort_order = '" . (int)$data['sort_order'] . "', date_modified = NOW() WHERE product_id = '" . (int)$product_id . "'");
|
||||
|
||||
if (isset($data['image'])) {
|
||||
$this->db->query("UPDATE " . DB_PREFIX . "product SET image = '" . $this->db->escape($data['image']) . "' WHERE product_id = '" . (int)$product_id . "'");
|
||||
}
|
||||
|
||||
$this->db->query("DELETE FROM " . DB_PREFIX . "product_description WHERE product_id = '" . (int)$product_id . "'");
|
||||
|
||||
foreach ($data['product_description'] as $language_id => $value) {
|
||||
$this->db->query("INSERT INTO " . DB_PREFIX . "product_description SET product_id = '" . (int)$product_id . "', language_id = '" . (int)$language_id . "', name = '" . $this->db->escape($value['name']) . "', description = '" . $this->db->escape($value['description']) . "', tag = '" . $this->db->escape($value['tag']) . "', meta_title = '" . $this->db->escape($value['meta_title']) . "', meta_h1 = '" . $this->db->escape($value['meta_h1']) . "', meta_description = '" . $this->db->escape($value['meta_description']) . "', meta_keyword = '" . $this->db->escape($value['meta_keyword']) . "'");
|
||||
}
|
||||
|
||||
$this->db->query("DELETE FROM " . DB_PREFIX . "product_to_store WHERE product_id = '" . (int)$product_id . "'");
|
||||
|
||||
if (isset($data['product_store'])) {
|
||||
foreach ($data['product_store'] as $store_id) {
|
||||
$this->db->query("INSERT INTO " . DB_PREFIX . "product_to_store SET product_id = '" . (int)$product_id . "', store_id = '" . (int)$store_id . "'");
|
||||
}
|
||||
}
|
||||
|
||||
$this->db->query("DELETE FROM " . DB_PREFIX . "product_attribute WHERE product_id = '" . (int)$product_id . "'");
|
||||
|
||||
if (!empty($data['product_attribute'])) {
|
||||
foreach ($data['product_attribute'] as $product_attribute) {
|
||||
if ($product_attribute['attribute_id']) {
|
||||
// Removes duplicates
|
||||
$this->db->query("DELETE FROM " . DB_PREFIX . "product_attribute WHERE product_id = '" . (int)$product_id . "' AND attribute_id = '" . (int)$product_attribute['attribute_id'] . "'");
|
||||
|
||||
foreach ($product_attribute['product_attribute_description'] as $language_id => $product_attribute_description) {
|
||||
$this->db->query("INSERT INTO " . DB_PREFIX . "product_attribute SET product_id = '" . (int)$product_id . "', attribute_id = '" . (int)$product_attribute['attribute_id'] . "', language_id = '" . (int)$language_id . "', text = '" . $this->db->escape($product_attribute_description['text']) . "'");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->db->query("DELETE FROM " . DB_PREFIX . "product_option WHERE product_id = '" . (int)$product_id . "'");
|
||||
$this->db->query("DELETE FROM " . DB_PREFIX . "product_option_value WHERE product_id = '" . (int)$product_id . "'");
|
||||
|
||||
if (isset($data['product_option'])) {
|
||||
foreach ($data['product_option'] as $product_option) {
|
||||
if ($product_option['type'] == 'select' || $product_option['type'] == 'radio' || $product_option['type'] == 'checkbox' || $product_option['type'] == 'image') {
|
||||
if (isset($product_option['product_option_value'])) {
|
||||
$this->db->query("INSERT INTO " . DB_PREFIX . "product_option SET product_option_id = '" . (int)$product_option['product_option_id'] . "', product_id = '" . (int)$product_id . "', option_id = '" . (int)$product_option['option_id'] . "', required = '" . (int)$product_option['required'] . "'");
|
||||
|
||||
$product_option_id = $this->db->getLastId();
|
||||
|
||||
foreach ($product_option['product_option_value'] as $product_option_value) {
|
||||
$this->db->query("INSERT INTO " . DB_PREFIX . "product_option_value SET product_option_value_id = '" . (int)$product_option_value['product_option_value_id'] . "', product_option_id = '" . (int)$product_option_id . "', product_id = '" . (int)$product_id . "', option_id = '" . (int)$product_option['option_id'] . "', option_value_id = '" . (int)$product_option_value['option_value_id'] . "', quantity = '" . (int)$product_option_value['quantity'] . "', subtract = '" . (int)$product_option_value['subtract'] . "', price = '" . (float)$product_option_value['price'] . "', price_prefix = '" . $this->db->escape($product_option_value['price_prefix']) . "', points = '" . (int)$product_option_value['points'] . "', points_prefix = '" . $this->db->escape($product_option_value['points_prefix']) . "', weight = '" . (float)$product_option_value['weight'] . "', weight_prefix = '" . $this->db->escape($product_option_value['weight_prefix']) . "'");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$this->db->query("INSERT INTO " . DB_PREFIX . "product_option SET product_option_id = '" . (int)$product_option['product_option_id'] . "', product_id = '" . (int)$product_id . "', option_id = '" . (int)$product_option['option_id'] . "', value = '" . $this->db->escape($product_option['value']) . "', required = '" . (int)$product_option['required'] . "'");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "product_recurring` WHERE product_id = " . (int)$product_id);
|
||||
|
||||
if (isset($data['product_recurring'])) {
|
||||
foreach ($data['product_recurring'] as $product_recurring) {
|
||||
$query = $this->db->query("SELECT `product_id` FROM `" . DB_PREFIX . "product_recurring` WHERE `product_id` = '" . (int)$product_id . "' AND `customer_group_id` = '" . (int)$product_recurring['customer_group_id'] . "' AND `recurring_id` = '" . (int)$product_recurring['recurring_id'] . "'");
|
||||
|
||||
if (!$query->num_rows) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "product_recurring` SET `product_id` = '" . (int)$product_id . "', `customer_group_id` = '" . (int)$product_recurring['customer_group_id'] . "', `recurring_id` = '" . (int)$product_recurring['recurring_id'] . "'");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->db->query("DELETE FROM " . DB_PREFIX . "product_discount WHERE product_id = '" . (int)$product_id . "'");
|
||||
|
||||
if (isset($data['product_discount'])) {
|
||||
foreach ($data['product_discount'] as $product_discount) {
|
||||
$this->db->query("INSERT INTO " . DB_PREFIX . "product_discount SET product_id = '" . (int)$product_id . "', customer_group_id = '" . (int)$product_discount['customer_group_id'] . "', quantity = '" . (int)$product_discount['quantity'] . "', priority = '" . (int)$product_discount['priority'] . "', price = '" . (float)$product_discount['price'] . "', date_start = '" . $this->db->escape($product_discount['date_start']) . "', date_end = '" . $this->db->escape($product_discount['date_end']) . "'");
|
||||
}
|
||||
}
|
||||
|
||||
$this->db->query("DELETE FROM " . DB_PREFIX . "product_special WHERE product_id = '" . (int)$product_id . "'");
|
||||
|
||||
if (isset($data['product_special'])) {
|
||||
foreach ($data['product_special'] as $product_special) {
|
||||
$this->db->query("INSERT INTO " . DB_PREFIX . "product_special SET product_id = '" . (int)$product_id . "', customer_group_id = '" . (int)$product_special['customer_group_id'] . "', priority = '" . (int)$product_special['priority'] . "', price = '" . (float)$product_special['price'] . "', date_start = '" . $this->db->escape($product_special['date_start']) . "', date_end = '" . $this->db->escape($product_special['date_end']) . "'");
|
||||
}
|
||||
}
|
||||
|
||||
$this->db->query("DELETE FROM " . DB_PREFIX . "product_image WHERE product_id = '" . (int)$product_id . "'");
|
||||
|
||||
if (isset($data['product_image'])) {
|
||||
foreach ($data['product_image'] as $product_image) {
|
||||
$this->db->query("INSERT INTO " . DB_PREFIX . "product_image SET product_id = '" . (int)$product_id . "', image = '" . $this->db->escape($product_image['image']) . "', sort_order = '" . (int)$product_image['sort_order'] . "'");
|
||||
}
|
||||
}
|
||||
|
||||
$this->db->query("DELETE FROM " . DB_PREFIX . "product_to_download WHERE product_id = '" . (int)$product_id . "'");
|
||||
|
||||
if (isset($data['product_download'])) {
|
||||
foreach ($data['product_download'] as $download_id) {
|
||||
$this->db->query("INSERT INTO " . DB_PREFIX . "product_to_download SET product_id = '" . (int)$product_id . "', download_id = '" . (int)$download_id . "'");
|
||||
}
|
||||
}
|
||||
|
||||
$this->db->query("DELETE FROM " . DB_PREFIX . "product_to_category WHERE product_id = '" . (int)$product_id . "'");
|
||||
|
||||
if (isset($data['product_category'])) {
|
||||
foreach ($data['product_category'] as $category_id) {
|
||||
$this->db->query("INSERT INTO " . DB_PREFIX . "product_to_category SET product_id = '" . (int)$product_id . "', category_id = '" . (int)$category_id . "'");
|
||||
}
|
||||
}
|
||||
|
||||
$this->db->query("DELETE FROM " . DB_PREFIX . "product_filter WHERE product_id = '" . (int)$product_id . "'");
|
||||
|
||||
if (isset($data['main_category_id']) && $data['main_category_id'] > 0) {
|
||||
$this->db->query("DELETE FROM " . DB_PREFIX . "product_to_category WHERE product_id = '" . (int)$product_id . "' AND category_id = '" . (int)$data['main_category_id'] . "'");
|
||||
$this->db->query("INSERT INTO " . DB_PREFIX . "product_to_category SET product_id = '" . (int)$product_id . "', category_id = '" . (int)$data['main_category_id'] . "', main_category = 1");
|
||||
} elseif (isset($data['product_category'][0])) {
|
||||
$this->db->query("UPDATE " . DB_PREFIX . "product_to_category SET main_category = 1 WHERE product_id = '" . (int)$product_id . "' AND category_id = '" . (int)$data['product_category'][0] . "'");
|
||||
}
|
||||
|
||||
if (isset($data['product_filter'])) {
|
||||
foreach ($data['product_filter'] as $filter_id) {
|
||||
$this->db->query("INSERT INTO " . DB_PREFIX . "product_filter SET product_id = '" . (int)$product_id . "', filter_id = '" . (int)$filter_id . "'");
|
||||
}
|
||||
}
|
||||
|
||||
$this->db->query("DELETE FROM " . DB_PREFIX . "product_related WHERE product_id = '" . (int)$product_id . "'");
|
||||
$this->db->query("DELETE FROM " . DB_PREFIX . "product_related WHERE related_id = '" . (int)$product_id . "'");
|
||||
|
||||
if (isset($data['product_related'])) {
|
||||
foreach ($data['product_related'] as $related_id) {
|
||||
$this->db->query("DELETE FROM " . DB_PREFIX . "product_related WHERE product_id = '" . (int)$product_id . "' AND related_id = '" . (int)$related_id . "'");
|
||||
$this->db->query("INSERT INTO " . DB_PREFIX . "product_related SET product_id = '" . (int)$product_id . "', related_id = '" . (int)$related_id . "'");
|
||||
$this->db->query("DELETE FROM " . DB_PREFIX . "product_related WHERE product_id = '" . (int)$related_id . "' AND related_id = '" . (int)$product_id . "'");
|
||||
$this->db->query("INSERT INTO " . DB_PREFIX . "product_related SET product_id = '" . (int)$related_id . "', related_id = '" . (int)$product_id . "'");
|
||||
}
|
||||
}
|
||||
|
||||
$this->db->query("DELETE FROM " . DB_PREFIX . "product_related_article WHERE product_id = '" . (int)$product_id . "'");
|
||||
|
||||
if (isset($data['product_related_article'])) {
|
||||
foreach ($data['product_related_article'] as $article_id) {
|
||||
$this->db->query("DELETE FROM " . DB_PREFIX . "product_related_article WHERE product_id = '" . (int)$product_id . "' AND article_id = '" . (int)$article_id . "'");
|
||||
$this->db->query("INSERT INTO " . DB_PREFIX . "product_related_article SET product_id = '" . (int)$product_id . "', article_id = '" . (int)$article_id . "'");
|
||||
}
|
||||
}
|
||||
|
||||
$this->db->query("DELETE FROM " . DB_PREFIX . "product_reward WHERE product_id = '" . (int)$product_id . "'");
|
||||
|
||||
if (isset($data['product_reward'])) {
|
||||
foreach ($data['product_reward'] as $customer_group_id => $value) {
|
||||
if ((int)$value['points'] > 0) {
|
||||
$this->db->query("INSERT INTO " . DB_PREFIX . "product_reward SET product_id = '" . (int)$product_id . "', customer_group_id = '" . (int)$customer_group_id . "', points = '" . (int)$value['points'] . "'");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// SEO URL
|
||||
$this->db->query("DELETE FROM " . DB_PREFIX . "seo_url WHERE query = 'product_id=" . (int)$product_id . "'");
|
||||
|
||||
if (isset($data['product_seo_url'])) {
|
||||
foreach ($data['product_seo_url']as $store_id => $language) {
|
||||
foreach ($language as $language_id => $keyword) {
|
||||
if (!empty($keyword)) {
|
||||
$this->db->query("INSERT INTO " . DB_PREFIX . "seo_url SET store_id = '" . (int)$store_id . "', language_id = '" . (int)$language_id . "', query = 'product_id=" . (int)$product_id . "', keyword = '" . $this->db->escape(trim($keyword)) . "'");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->db->query("DELETE FROM " . DB_PREFIX . "product_to_layout WHERE product_id = '" . (int)$product_id . "'");
|
||||
|
||||
if (isset($data['product_layout'])) {
|
||||
foreach ($data['product_layout'] as $store_id => $layout_id) {
|
||||
$this->db->query("INSERT INTO " . DB_PREFIX . "product_to_layout SET product_id = '" . (int)$product_id . "', store_id = '" . (int)$store_id . "', layout_id = '" . (int)$layout_id . "'");
|
||||
}
|
||||
}
|
||||
|
||||
$this->cache->delete('product');
|
||||
|
||||
if($this->config->get('config_seo_pro')){
|
||||
$this->cache->delete('seopro');
|
||||
}
|
||||
}
|
||||
|
||||
public function editProductStatus($product_id, $status) {
|
||||
$this->db->query("UPDATE " . DB_PREFIX . "product SET status = '" . (int)$status . "', date_modified = NOW() WHERE product_id = '" . (int)$product_id . "'");
|
||||
|
||||
$this->cache->delete('product');
|
||||
|
||||
if($this->config->get('config_seo_pro')){
|
||||
$this->cache->delete('seopro');
|
||||
}
|
||||
|
||||
return $product_id;
|
||||
}
|
||||
|
||||
public function copyProduct($product_id) {
|
||||
$query = $this->db->query("SELECT DISTINCT * FROM " . DB_PREFIX . "product p WHERE p.product_id = '" . (int)$product_id . "'");
|
||||
|
||||
if ($query->num_rows) {
|
||||
$data = $query->row;
|
||||
|
||||
$data['sku'] = '';
|
||||
$data['upc'] = '';
|
||||
$data['viewed'] = '0';
|
||||
$data['keyword'] = '';
|
||||
$data['status'] = '0';
|
||||
$data['noindex'] = '0';
|
||||
|
||||
$data['product_attribute'] = $this->getProductAttributes($product_id);
|
||||
$data['product_description'] = $this->getProductDescriptions($product_id);
|
||||
$data['product_discount'] = $this->getProductDiscounts($product_id);
|
||||
$data['product_filter'] = $this->getProductFilters($product_id);
|
||||
$data['product_image'] = $this->getProductImages($product_id);
|
||||
$data['product_option'] = $this->getProductOptions($product_id);
|
||||
$data['product_related'] = $this->getProductRelated($product_id);
|
||||
$data['product_related_article'] = $this->getArticleRelated($product_id);
|
||||
$data['product_reward'] = $this->getProductRewards($product_id);
|
||||
$data['product_special'] = $this->getProductSpecials($product_id);
|
||||
$data['product_category'] = $this->getProductCategories($product_id);
|
||||
$data['product_download'] = $this->getProductDownloads($product_id);
|
||||
$data['product_layout'] = $this->getProductLayouts($product_id);
|
||||
$data['product_store'] = $this->getProductStores($product_id);
|
||||
$data['product_recurrings'] = $this->getRecurrings($product_id);
|
||||
|
||||
$this->addProduct($data);
|
||||
}
|
||||
}
|
||||
|
||||
public function deleteProduct($product_id) {
|
||||
$this->db->query("DELETE FROM " . DB_PREFIX . "product WHERE product_id = '" . (int)$product_id . "'");
|
||||
$this->db->query("DELETE FROM " . DB_PREFIX . "product_attribute WHERE product_id = '" . (int)$product_id . "'");
|
||||
$this->db->query("DELETE FROM " . DB_PREFIX . "product_description WHERE product_id = '" . (int)$product_id . "'");
|
||||
$this->db->query("DELETE FROM " . DB_PREFIX . "product_discount WHERE product_id = '" . (int)$product_id . "'");
|
||||
$this->db->query("DELETE FROM " . DB_PREFIX . "product_filter WHERE product_id = '" . (int)$product_id . "'");
|
||||
$this->db->query("DELETE FROM " . DB_PREFIX . "product_image WHERE product_id = '" . (int)$product_id . "'");
|
||||
$this->db->query("DELETE FROM " . DB_PREFIX . "product_option WHERE product_id = '" . (int)$product_id . "'");
|
||||
$this->db->query("DELETE FROM " . DB_PREFIX . "product_option_value WHERE product_id = '" . (int)$product_id . "'");
|
||||
$this->db->query("DELETE FROM " . DB_PREFIX . "product_related WHERE product_id = '" . (int)$product_id . "'");
|
||||
$this->db->query("DELETE FROM " . DB_PREFIX . "product_related WHERE related_id = '" . (int)$product_id . "'");
|
||||
$this->db->query("DELETE FROM " . DB_PREFIX . "product_related_article WHERE product_id = '" . (int)$product_id . "'");
|
||||
$this->db->query("DELETE FROM " . DB_PREFIX . "product_reward WHERE product_id = '" . (int)$product_id . "'");
|
||||
$this->db->query("DELETE FROM " . DB_PREFIX . "product_special WHERE product_id = '" . (int)$product_id . "'");
|
||||
$this->db->query("DELETE FROM " . DB_PREFIX . "product_to_category WHERE product_id = '" . (int)$product_id . "'");
|
||||
$this->db->query("DELETE FROM " . DB_PREFIX . "product_to_download WHERE product_id = '" . (int)$product_id . "'");
|
||||
$this->db->query("DELETE FROM " . DB_PREFIX . "product_to_layout WHERE product_id = '" . (int)$product_id . "'");
|
||||
$this->db->query("DELETE FROM " . DB_PREFIX . "product_to_store WHERE product_id = '" . (int)$product_id . "'");
|
||||
$this->db->query("DELETE FROM " . DB_PREFIX . "product_recurring WHERE product_id = " . (int)$product_id);
|
||||
$this->db->query("DELETE FROM " . DB_PREFIX . "review WHERE product_id = '" . (int)$product_id . "'");
|
||||
$this->db->query("DELETE FROM " . DB_PREFIX . "seo_url WHERE query = 'product_id=" . (int)$product_id . "'");
|
||||
$this->db->query("DELETE FROM " . DB_PREFIX . "coupon_product WHERE product_id = '" . (int)$product_id . "'");
|
||||
|
||||
$this->cache->delete('product');
|
||||
|
||||
if($this->config->get('config_seo_pro')){
|
||||
$this->cache->delete('seopro');
|
||||
}
|
||||
}
|
||||
|
||||
public function getProduct($product_id) {
|
||||
$query = $this->db->query("SELECT DISTINCT * FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) WHERE p.product_id = '" . (int)$product_id . "' AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "'");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
public function getProducts($data = array()) {
|
||||
$sql = "SELECT * FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) WHERE pd.language_id = '" . (int)$this->config->get('config_language_id') . "'";
|
||||
|
||||
if (isset($data['filter_category']) && !is_null($data['filter_category'])) {
|
||||
preg_match('/(.*)(WHERE pd\.language_id.*)/', $sql, $sql_crutch_matches);
|
||||
if (isset($sql_crutch_matches[2])) {
|
||||
$sql = $sql_crutch_matches[1] . " LEFT JOIN " . DB_PREFIX . "product_to_category p2c ON (p.product_id = p2c.product_id)" . $sql_crutch_matches[2];
|
||||
} else {
|
||||
$data['filter_category'] = null;
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($data['filter_name'])) {
|
||||
$sql .= " AND pd.name LIKE '%" . $this->db->escape($data['filter_name']) . "%'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_model'])) {
|
||||
$sql .= " AND p.model LIKE '%" . $this->db->escape($data['filter_model']) . "%'";
|
||||
}
|
||||
|
||||
if (isset($data['filter_category']) && !is_null($data['filter_category'])) {
|
||||
if (!empty($data['filter_category']) && !empty($data['filter_sub_category'])) {
|
||||
$implode_data = array();
|
||||
|
||||
$this->load->model('catalog/category');
|
||||
|
||||
$categories = $this->model_catalog_category->getCategoriesChildren($data['filter_category']);
|
||||
|
||||
foreach ($categories as $category) {
|
||||
$implode_data[] = "p2c.category_id = '" . (int)$category['category_id'] . "'";
|
||||
}
|
||||
|
||||
$sql .= " AND (" . implode(' OR ', $implode_data) . ")";
|
||||
} else {
|
||||
if ((int)$data['filter_category'] > 0) {
|
||||
$sql .= " AND p2c.category_id = '" . (int)$data['filter_category'] . "'";
|
||||
} else {
|
||||
$sql .= " AND p2c.category_id IS NULL";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($data['filter_manufacturer_id']) && !is_null($data['filter_manufacturer_id'])) {
|
||||
$sql .= " AND p.manufacturer_id = '" . (int)$data['filter_manufacturer_id'] . "'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_price'])) {
|
||||
$sql .= " AND p.price LIKE '" . $this->db->escape($data['filter_price']) . "%'";
|
||||
}
|
||||
|
||||
if (isset($data['filter_price_min']) && !is_null($data['filter_price_min'])) {
|
||||
$sql .= " AND p.price >= '" . (float)$data['filter_price_min'] . "'";
|
||||
}
|
||||
|
||||
if (isset($data['filter_price_max']) && !is_null($data['filter_price_max'])) {
|
||||
$sql .= " AND p.price <= '" . (float)$data['filter_price_max'] . "'";
|
||||
}
|
||||
|
||||
if (isset($data['filter_quantity']) && $data['filter_quantity'] !== '') {
|
||||
$sql .= " AND p.quantity = '" . (int)$data['filter_quantity'] . "'";
|
||||
}
|
||||
|
||||
if (isset($data['filter_quantity_min']) && !is_null($data['filter_quantity_min'])) {
|
||||
$sql .= " AND p.quantity >= '" . (int)$data['filter_quantity_min'] . "'";
|
||||
}
|
||||
|
||||
if (isset($data['filter_quantity_max']) && !is_null($data['filter_quantity_max'])) {
|
||||
$sql .= " AND p.quantity <= '" . (int)$data['filter_quantity_max'] . "'";
|
||||
}
|
||||
|
||||
if (isset($data['filter_status']) && $data['filter_status'] !== '') {
|
||||
$sql .= " AND p.status = '" . (int)$data['filter_status'] . "'";
|
||||
}
|
||||
|
||||
if (isset($data['filter_noindex']) && $data['filter_noindex'] !== '') {
|
||||
$sql .= " AND p.noindex = '" . (int)$data['filter_noindex'] . "'";
|
||||
}
|
||||
|
||||
$sql .= " GROUP BY p.product_id";
|
||||
|
||||
$sort_data = array(
|
||||
'pd.name',
|
||||
'p.model',
|
||||
'p.price',
|
||||
'p.quantity',
|
||||
'p.status',
|
||||
'p.noindex',
|
||||
'p.sort_order'
|
||||
);
|
||||
|
||||
if (isset($data['sort']) && in_array($data['sort'], $sort_data)) {
|
||||
$sql .= " ORDER BY " . $data['sort'];
|
||||
} else {
|
||||
$sql .= " ORDER BY pd.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;
|
||||
}
|
||||
|
||||
public function getProductsByCategoryId($category_id) {
|
||||
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_category p2c ON (p.product_id = p2c.product_id) WHERE pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2c.category_id = '" . (int)$category_id . "' ORDER BY pd.name ASC");
|
||||
|
||||
return $query->rows;
|
||||
}
|
||||
|
||||
public function getProductDescriptions($product_id) {
|
||||
$product_description_data = array();
|
||||
|
||||
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_description WHERE product_id = '" . (int)$product_id . "'");
|
||||
|
||||
foreach ($query->rows as $result) {
|
||||
$product_description_data[$result['language_id']] = array(
|
||||
'name' => $result['name'],
|
||||
'description' => $result['description'],
|
||||
'meta_title' => $result['meta_title'],
|
||||
'meta_h1' => $result['meta_h1'],
|
||||
'meta_description' => $result['meta_description'],
|
||||
'meta_keyword' => $result['meta_keyword'],
|
||||
'tag' => $result['tag']
|
||||
);
|
||||
}
|
||||
|
||||
return $product_description_data;
|
||||
}
|
||||
|
||||
public function getProductCategories($product_id) {
|
||||
$product_category_data = array();
|
||||
|
||||
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_to_category WHERE product_id = '" . (int)$product_id . "'");
|
||||
|
||||
foreach ($query->rows as $result) {
|
||||
$product_category_data[] = $result['category_id'];
|
||||
}
|
||||
|
||||
return $product_category_data;
|
||||
}
|
||||
|
||||
public function getProductMainCategoryId($product_id) {
|
||||
$query = $this->db->query("SELECT category_id FROM " . DB_PREFIX . "product_to_category WHERE product_id = '" . (int)$product_id . "' AND main_category = '1' LIMIT 1");
|
||||
|
||||
return ($query->num_rows ? (int)$query->row['category_id'] : 0);
|
||||
}
|
||||
|
||||
public function getProductFilters($product_id) {
|
||||
$product_filter_data = array();
|
||||
|
||||
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_filter WHERE product_id = '" . (int)$product_id . "'");
|
||||
|
||||
foreach ($query->rows as $result) {
|
||||
$product_filter_data[] = $result['filter_id'];
|
||||
}
|
||||
|
||||
return $product_filter_data;
|
||||
}
|
||||
|
||||
public function getProductAttributes($product_id) {
|
||||
$product_attribute_data = array();
|
||||
|
||||
$product_attribute_query = $this->db->query("SELECT attribute_id FROM " . DB_PREFIX . "product_attribute WHERE product_id = '" . (int)$product_id . "' GROUP BY attribute_id");
|
||||
|
||||
foreach ($product_attribute_query->rows as $product_attribute) {
|
||||
$product_attribute_description_data = array();
|
||||
|
||||
$product_attribute_description_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_attribute WHERE product_id = '" . (int)$product_id . "' AND attribute_id = '" . (int)$product_attribute['attribute_id'] . "'");
|
||||
|
||||
foreach ($product_attribute_description_query->rows as $product_attribute_description) {
|
||||
$product_attribute_description_data[$product_attribute_description['language_id']] = array('text' => $product_attribute_description['text']);
|
||||
}
|
||||
|
||||
$product_attribute_data[] = array(
|
||||
'attribute_id' => $product_attribute['attribute_id'],
|
||||
'product_attribute_description' => $product_attribute_description_data
|
||||
);
|
||||
}
|
||||
|
||||
return $product_attribute_data;
|
||||
}
|
||||
|
||||
public function getProductOptions($product_id) {
|
||||
$product_option_data = array();
|
||||
|
||||
$product_option_query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "product_option` po LEFT JOIN `" . DB_PREFIX . "option` o ON (po.option_id = o.option_id) LEFT JOIN `" . DB_PREFIX . "option_description` od ON (o.option_id = od.option_id) WHERE po.product_id = '" . (int)$product_id . "' AND od.language_id = '" . (int)$this->config->get('config_language_id') . "' ORDER BY o.sort_order ASC");
|
||||
|
||||
foreach ($product_option_query->rows as $product_option) {
|
||||
$product_option_value_data = array();
|
||||
|
||||
$product_option_value_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_option_value pov LEFT JOIN " . DB_PREFIX . "option_value ov ON(pov.option_value_id = ov.option_value_id) WHERE pov.product_option_id = '" . (int)$product_option['product_option_id'] . "' ORDER BY ov.sort_order ASC");
|
||||
|
||||
foreach ($product_option_value_query->rows as $product_option_value) {
|
||||
$product_option_value_data[] = array(
|
||||
'product_option_value_id' => $product_option_value['product_option_value_id'],
|
||||
'option_value_id' => $product_option_value['option_value_id'],
|
||||
'quantity' => $product_option_value['quantity'],
|
||||
'subtract' => $product_option_value['subtract'],
|
||||
'price' => $product_option_value['price'],
|
||||
'price_prefix' => $product_option_value['price_prefix'],
|
||||
'points' => $product_option_value['points'],
|
||||
'points_prefix' => $product_option_value['points_prefix'],
|
||||
'weight' => $product_option_value['weight'],
|
||||
'weight_prefix' => $product_option_value['weight_prefix']
|
||||
);
|
||||
}
|
||||
|
||||
$product_option_data[] = array(
|
||||
'product_option_id' => $product_option['product_option_id'],
|
||||
'product_option_value' => $product_option_value_data,
|
||||
'option_id' => $product_option['option_id'],
|
||||
'name' => $product_option['name'],
|
||||
'type' => $product_option['type'],
|
||||
'value' => $product_option['value'],
|
||||
'required' => $product_option['required']
|
||||
);
|
||||
}
|
||||
|
||||
return $product_option_data;
|
||||
}
|
||||
|
||||
public function getProductOptionValue($product_id, $product_option_value_id) {
|
||||
$query = $this->db->query("SELECT pov.option_value_id, ovd.name, pov.quantity, pov.subtract, pov.price, pov.price_prefix, pov.points, pov.points_prefix, pov.weight, pov.weight_prefix FROM " . DB_PREFIX . "product_option_value pov LEFT JOIN " . DB_PREFIX . "option_value ov ON (pov.option_value_id = ov.option_value_id) LEFT JOIN " . DB_PREFIX . "option_value_description ovd ON (ov.option_value_id = ovd.option_value_id) WHERE pov.product_id = '" . (int)$product_id . "' AND pov.product_option_value_id = '" . (int)$product_option_value_id . "' AND ovd.language_id = '" . (int)$this->config->get('config_language_id') . "'");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
public function getProductImages($product_id) {
|
||||
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_image WHERE product_id = '" . (int)$product_id . "' ORDER BY sort_order ASC");
|
||||
|
||||
return $query->rows;
|
||||
}
|
||||
|
||||
public function getProductDiscounts($product_id) {
|
||||
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_discount WHERE product_id = '" . (int)$product_id . "' ORDER BY quantity, priority, price");
|
||||
|
||||
return $query->rows;
|
||||
}
|
||||
|
||||
public function getProductSpecials($product_id) {
|
||||
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_special WHERE product_id = '" . (int)$product_id . "' ORDER BY priority, price");
|
||||
|
||||
return $query->rows;
|
||||
}
|
||||
|
||||
public function getProductRewards($product_id) {
|
||||
$product_reward_data = array();
|
||||
|
||||
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_reward WHERE product_id = '" . (int)$product_id . "'");
|
||||
|
||||
foreach ($query->rows as $result) {
|
||||
$product_reward_data[$result['customer_group_id']] = array('points' => $result['points']);
|
||||
}
|
||||
|
||||
return $product_reward_data;
|
||||
}
|
||||
|
||||
public function getProductDownloads($product_id) {
|
||||
$product_download_data = array();
|
||||
|
||||
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_to_download WHERE product_id = '" . (int)$product_id . "'");
|
||||
|
||||
foreach ($query->rows as $result) {
|
||||
$product_download_data[] = $result['download_id'];
|
||||
}
|
||||
|
||||
return $product_download_data;
|
||||
}
|
||||
|
||||
public function getProductStores($product_id) {
|
||||
$product_store_data = array();
|
||||
|
||||
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_to_store WHERE product_id = '" . (int)$product_id . "'");
|
||||
|
||||
foreach ($query->rows as $result) {
|
||||
$product_store_data[] = $result['store_id'];
|
||||
}
|
||||
|
||||
return $product_store_data;
|
||||
}
|
||||
|
||||
public function getProductSeoUrls($product_id) {
|
||||
$product_seo_url_data = array();
|
||||
|
||||
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "seo_url WHERE query = 'product_id=" . (int)$product_id . "'");
|
||||
|
||||
foreach ($query->rows as $result) {
|
||||
$product_seo_url_data[$result['store_id']][$result['language_id']] = $result['keyword'];
|
||||
}
|
||||
|
||||
return $product_seo_url_data;
|
||||
}
|
||||
|
||||
public function getProductLayouts($product_id) {
|
||||
$product_layout_data = array();
|
||||
|
||||
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_to_layout WHERE product_id = '" . (int)$product_id . "'");
|
||||
|
||||
foreach ($query->rows as $result) {
|
||||
$product_layout_data[$result['store_id']] = $result['layout_id'];
|
||||
}
|
||||
|
||||
return $product_layout_data;
|
||||
}
|
||||
|
||||
public function getProductRelated($product_id) {
|
||||
$product_related_data = array();
|
||||
|
||||
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_related WHERE product_id = '" . (int)$product_id . "'");
|
||||
|
||||
foreach ($query->rows as $result) {
|
||||
$product_related_data[] = $result['related_id'];
|
||||
}
|
||||
|
||||
return $product_related_data;
|
||||
}
|
||||
|
||||
public function getArticleRelated($product_id) {
|
||||
$article_related_data = array();
|
||||
|
||||
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_related_article WHERE product_id = '" . (int)$product_id . "'");
|
||||
|
||||
foreach ($query->rows as $result) {
|
||||
$article_related_data[] = $result['article_id'];
|
||||
}
|
||||
|
||||
return $article_related_data;
|
||||
}
|
||||
|
||||
public function getRecurrings($product_id) {
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "product_recurring` WHERE product_id = '" . (int)$product_id . "'");
|
||||
|
||||
return $query->rows;
|
||||
}
|
||||
|
||||
public function getTotalProducts($data = array()) {
|
||||
$sql = "SELECT COUNT(DISTINCT p.product_id) AS total FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id)";
|
||||
|
||||
if (isset($data['filter_category']) && !is_null($data['filter_category'])) {
|
||||
$sql .= " LEFT JOIN " . DB_PREFIX . "product_to_category p2c ON (p.product_id = p2c.product_id)";
|
||||
}
|
||||
|
||||
$sql .= " WHERE pd.language_id = '" . (int)$this->config->get('config_language_id') . "'";
|
||||
|
||||
if (!empty($data['filter_name'])) {
|
||||
$sql .= " AND pd.name LIKE '%" . $this->db->escape($data['filter_name']) . "%'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_model'])) {
|
||||
$sql .= " AND p.model LIKE '%" . $this->db->escape($data['filter_model']) . "%'";
|
||||
}
|
||||
|
||||
if (isset($data['filter_category']) && !is_null($data['filter_category'])) {
|
||||
if (!empty($data['filter_category']) && !empty($data['filter_sub_category'])) {
|
||||
$implode_data = array();
|
||||
|
||||
$this->load->model('catalog/category');
|
||||
|
||||
$categories = $this->model_catalog_category->getCategoriesChildren($data['filter_category']);
|
||||
|
||||
foreach ($categories as $category) {
|
||||
$implode_data[] = "p2c.category_id = '" . (int)$category['category_id'] . "'";
|
||||
}
|
||||
|
||||
$sql .= " AND (" . implode(' OR ', $implode_data) . ")";
|
||||
} else {
|
||||
if ((int)$data['filter_category'] > 0) {
|
||||
$sql .= " AND p2c.category_id = '" . (int)$data['filter_category'] . "'";
|
||||
} else {
|
||||
$sql .= " AND p2c.category_id IS NULL";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($data['filter_manufacturer_id']) && !is_null($data['filter_manufacturer_id'])) {
|
||||
$sql .= " AND p.manufacturer_id = '" . (int)$data['filter_manufacturer_id'] . "'";
|
||||
}
|
||||
|
||||
if (isset($data['filter_price']) && !is_null($data['filter_price'])) {
|
||||
$sql .= " AND p.price LIKE '" . $this->db->escape($data['filter_price']) . "%'";
|
||||
}
|
||||
|
||||
if (isset($data['filter_price_min']) && !is_null($data['filter_price_min'])) {
|
||||
$sql .= " AND p.price >= '" . (float)$data['filter_price_min'] . "'";
|
||||
}
|
||||
|
||||
if (isset($data['filter_price_max']) && !is_null($data['filter_price_max'])) {
|
||||
$sql .= " AND p.price <= '" . (float)$data['filter_price_max'] . "'";
|
||||
}
|
||||
|
||||
if (isset($data['filter_quantity']) && $data['filter_quantity'] !== '') {
|
||||
$sql .= " AND p.quantity = '" . (int)$data['filter_quantity'] . "'";
|
||||
}
|
||||
|
||||
if (isset($data['filter_quantity_min']) && !is_null($data['filter_quantity_min'])) {
|
||||
$sql .= " AND p.quantity >= '" . (int)$data['filter_quantity_min'] . "'";
|
||||
}
|
||||
|
||||
if (isset($data['filter_quantity_max']) && !is_null($data['filter_quantity_max'])) {
|
||||
$sql .= " AND p.quantity <= '" . (int)$data['filter_quantity_max'] . "'";
|
||||
}
|
||||
|
||||
if (isset($data['filter_status']) && $data['filter_status'] !== '') {
|
||||
$sql .= " AND p.status = '" . (int)$data['filter_status'] . "'";
|
||||
}
|
||||
|
||||
if (isset($data['filter_noindex']) && $data['filter_noindex'] !== '') {
|
||||
$sql .= " AND p.noindex = '" . (int)$data['filter_noindex'] . "'";
|
||||
}
|
||||
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
return $query->row['total'];
|
||||
}
|
||||
|
||||
public function getTotalProductsByTaxClassId($tax_class_id) {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "product WHERE tax_class_id = '" . (int)$tax_class_id . "'");
|
||||
|
||||
return $query->row['total'];
|
||||
}
|
||||
|
||||
public function getTotalProductsByStockStatusId($stock_status_id) {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "product WHERE stock_status_id = '" . (int)$stock_status_id . "'");
|
||||
|
||||
return $query->row['total'];
|
||||
}
|
||||
|
||||
public function getTotalProductsByWeightClassId($weight_class_id) {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "product WHERE weight_class_id = '" . (int)$weight_class_id . "'");
|
||||
|
||||
return $query->row['total'];
|
||||
}
|
||||
|
||||
public function getTotalProductsByLengthClassId($length_class_id) {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "product WHERE length_class_id = '" . (int)$length_class_id . "'");
|
||||
|
||||
return $query->row['total'];
|
||||
}
|
||||
|
||||
public function getTotalProductsByDownloadId($download_id) {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "product_to_download WHERE download_id = '" . (int)$download_id . "'");
|
||||
|
||||
return $query->row['total'];
|
||||
}
|
||||
|
||||
public function getTotalProductsByManufacturerId($manufacturer_id) {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "product WHERE manufacturer_id = '" . (int)$manufacturer_id . "'");
|
||||
|
||||
return $query->row['total'];
|
||||
}
|
||||
|
||||
public function getTotalProductsByAttributeId($attribute_id) {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "product_attribute WHERE attribute_id = '" . (int)$attribute_id . "'");
|
||||
|
||||
return $query->row['total'];
|
||||
}
|
||||
|
||||
public function getTotalProductsByOptionId($option_id) {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "product_option WHERE option_id = '" . (int)$option_id . "'");
|
||||
|
||||
return $query->row['total'];
|
||||
}
|
||||
|
||||
public function getTotalProductsByProfileId($recurring_id) {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "product_recurring WHERE recurring_id = '" . (int)$recurring_id . "'");
|
||||
|
||||
return $query->row['total'];
|
||||
}
|
||||
|
||||
public function getTotalProductsByLayoutId($layout_id) {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "product_to_layout WHERE layout_id = '" . (int)$layout_id . "'");
|
||||
|
||||
return $query->row['total'];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
<?php
|
||||
class ModelCatalogRecurring extends Model {
|
||||
public function addRecurring($data) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "recurring` SET `sort_order` = " . (int)$data['sort_order'] . ", `status` = " . (int)$data['status'] . ", `price` = " . (float)$data['price'] . ", `frequency` = '" . $this->db->escape($data['frequency']) . "', `duration` = " . (int)$data['duration'] . ", `cycle` = " . (int)$data['cycle'] . ", `trial_status` = " . (int)$data['trial_status'] . ", `trial_price` = " . (float)$data['trial_price'] . ", `trial_frequency` = '" . $this->db->escape($data['trial_frequency']) . "', `trial_duration` = " . (int)$data['trial_duration'] . ", `trial_cycle` = '" . (int)$data['trial_cycle'] . "'");
|
||||
|
||||
$recurring_id = $this->db->getLastId();
|
||||
|
||||
foreach ($data['recurring_description'] as $language_id => $recurring_description) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "recurring_description` (`recurring_id`, `language_id`, `name`) VALUES (" . (int)$recurring_id . ", " . (int)$language_id . ", '" . $this->db->escape($recurring_description['name']) . "')");
|
||||
}
|
||||
|
||||
return $recurring_id;
|
||||
}
|
||||
|
||||
public function editRecurring($recurring_id, $data) {
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "recurring_description` WHERE recurring_id = '" . (int)$recurring_id . "'");
|
||||
|
||||
$this->db->query("UPDATE `" . DB_PREFIX . "recurring` SET `price` = '" . (float)$data['price'] . "', `frequency` = '" . $this->db->escape($data['frequency']) . "', `duration` = '" . (int)$data['duration'] . "', `cycle` = '" . (int)$data['cycle'] . "', `sort_order` = '" . (int)$data['sort_order'] . "', `status` = '" . (int)$data['status'] . "', `trial_price` = '" . (float)$data['trial_price'] . "', `trial_frequency` = '" . $this->db->escape($data['trial_frequency']) . "', `trial_duration` = '" . (int)$data['trial_duration'] . "', `trial_cycle` = '" . (int)$data['trial_cycle'] . "', `trial_status` = '" . (int)$data['trial_status'] . "' WHERE recurring_id = '" . (int)$recurring_id . "'");
|
||||
|
||||
foreach ($data['recurring_description'] as $language_id => $recurring_description) {
|
||||
$this->db->query("INSERT INTO `" . DB_PREFIX . "recurring_description` (`recurring_id`, `language_id`, `name`) VALUES (" . (int)$recurring_id . ", " . (int)$language_id . ", '" . $this->db->escape($recurring_description['name']) . "')");
|
||||
}
|
||||
}
|
||||
|
||||
public function copyRecurring($recurring_id) {
|
||||
$data = $this->getRecurring($recurring_id);
|
||||
|
||||
$data['recurring_description'] = $this->getRecurringDescription($recurring_id);
|
||||
|
||||
foreach ($data['recurring_description'] as &$recurring_description) {
|
||||
$recurring_description['name'] .= ' - 2';
|
||||
}
|
||||
|
||||
$this->addRecurring($data);
|
||||
}
|
||||
|
||||
public function deleteRecurring($recurring_id) {
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "recurring` WHERE recurring_id = " . (int)$recurring_id . "");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "recurring_description` WHERE recurring_id = " . (int)$recurring_id . "");
|
||||
$this->db->query("DELETE FROM `" . DB_PREFIX . "product_recurring` WHERE recurring_id = " . (int)$recurring_id . "");
|
||||
$this->db->query("UPDATE `" . DB_PREFIX . "order_recurring` SET `recurring_id` = 0 WHERE `recurring_id` = " . (int)$recurring_id . "");
|
||||
}
|
||||
|
||||
public function getRecurring($recurring_id) {
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "recurring` WHERE recurring_id = '" . (int)$recurring_id . "'");
|
||||
|
||||
return $query->row;
|
||||
}
|
||||
|
||||
public function getRecurringDescription($recurring_id) {
|
||||
$recurring_description_data = array();
|
||||
|
||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "recurring_description` WHERE `recurring_id` = '" . (int)$recurring_id . "'");
|
||||
|
||||
foreach ($query->rows as $result) {
|
||||
$recurring_description_data[$result['language_id']] = array('name' => $result['name']);
|
||||
}
|
||||
|
||||
return $recurring_description_data;
|
||||
}
|
||||
|
||||
public function getRecurrings($data = array()) {
|
||||
$sql = "SELECT * FROM `" . DB_PREFIX . "recurring` r LEFT JOIN " . DB_PREFIX . "recurring_description rd ON (r.recurring_id = rd.recurring_id) WHERE rd.language_id = '" . (int)$this->config->get('config_language_id') . "'";
|
||||
|
||||
if (!empty($data['filter_name'])) {
|
||||
$sql .= " AND rd.name LIKE '" . $this->db->escape($data['filter_name']) . "%'";
|
||||
}
|
||||
|
||||
$sort_data = array(
|
||||
'rd.name',
|
||||
'r.sort_order'
|
||||
);
|
||||
|
||||
if (isset($data['sort']) && in_array($data['sort'], $sort_data)) {
|
||||
$sql .= " ORDER BY " . $data['sort'];
|
||||
} else {
|
||||
$sql .= " ORDER BY rd.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;
|
||||
}
|
||||
|
||||
public function getTotalRecurrings() {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS total FROM `" . DB_PREFIX . "recurring`");
|
||||
|
||||
return $query->row['total'];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,119 @@
|
||||
<?php
|
||||
// * @source See SOURCE.txt for source and other copyright.
|
||||
// * @license GNU General Public License version 3; see LICENSE.txt
|
||||
|
||||
class ModelCatalogReview extends Model {
|
||||
public function addReview($data) {
|
||||
$this->db->query("INSERT INTO " . DB_PREFIX . "review SET author = '" . $this->db->escape($data['author']) . "', product_id = '" . (int)$data['product_id'] . "', text = '" . $this->db->escape(strip_tags($data['text'])) . "', rating = '" . (int)$data['rating'] . "', status = '" . (int)$data['status'] . "', date_added = '" . $this->db->escape($data['date_added']) . "'");
|
||||
|
||||
$review_id = $this->db->getLastId();
|
||||
|
||||
$this->cache->delete('product');
|
||||
|
||||
return $review_id;
|
||||
}
|
||||
|
||||
public function editReview($review_id, $data) {
|
||||
$this->db->query("UPDATE " . DB_PREFIX . "review SET author = '" . $this->db->escape($data['author']) . "', product_id = '" . (int)$data['product_id'] . "', text = '" . $this->db->escape(strip_tags($data['text'])) . "', rating = '" . (int)$data['rating'] . "', status = '" . (int)$data['status'] . "', date_added = '" . $this->db->escape($data['date_added']) . "', date_modified = NOW() WHERE review_id = '" . (int)$review_id . "'");
|
||||
|
||||
$this->cache->delete('product');
|
||||
}
|
||||
|
||||
public function deleteReview($review_id) {
|
||||
$this->db->query("DELETE FROM " . DB_PREFIX . "review WHERE review_id = '" . (int)$review_id . "'");
|
||||
|
||||
$this->cache->delete('product');
|
||||
}
|
||||
|
||||
public function getReview($review_id) {
|
||||
$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;
|
||||
}
|
||||
|
||||
public function getReviews($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($data['filter_product']) . "%'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_author'])) {
|
||||
$sql .= " AND r.author LIKE '" . $this->db->escape($data['filter_author']) . "%'";
|
||||
}
|
||||
|
||||
if (isset($data['filter_status']) && $data['filter_status'] !== '') {
|
||||
$sql .= " AND r.status = '" . (int)$data['filter_status'] . "'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_date_added'])) {
|
||||
$sql .= " AND DATE(r.date_added) = DATE('" . $this->db->escape($data['filter_date_added']) . "')";
|
||||
}
|
||||
|
||||
$sort_data = array(
|
||||
'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;
|
||||
}
|
||||
|
||||
public function getTotalReviews($data = array()) {
|
||||
$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($data['filter_product']) . "%'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_author'])) {
|
||||
$sql .= " AND r.author LIKE '" . $this->db->escape($data['filter_author']) . "%'";
|
||||
}
|
||||
|
||||
if (isset($data['filter_status']) && $data['filter_status'] !== '') {
|
||||
$sql .= " AND r.status = '" . (int)$data['filter_status'] . "'";
|
||||
}
|
||||
|
||||
if (!empty($data['filter_date_added'])) {
|
||||
$sql .= " AND DATE(r.date_added) = DATE('" . $this->db->escape($data['filter_date_added']) . "')";
|
||||
}
|
||||
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
return $query->row['total'];
|
||||
}
|
||||
|
||||
public function getTotalReviewsAwaitingApproval() {
|
||||
$query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "review WHERE status = '0'");
|
||||
|
||||
return $query->row['total'];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user