更改Opencart 3 Category Bestseller模块中的过滤方法
Change filtration method in Opencart 3 Category Bestseller module
我有一个 Opencart 3 模块 - 类别畅销书。它显示了售出最多商品的热门类别。我想更改此过滤器。使其显示查看次数最多的产品类别。整理了一下资料,发现模型里面是这么写的
这是模型文件
<?php
class ModelExtensionModuleBestsellerCategory extends Model {
public function getBestSellerCategories($limit) {
$category_data = $this->cache->get('category.bestseller.' . (int)$this->config->get('config_language_id') . '.' . (int)$this->config->get('config_store_id') . '.' . $this->config->get('config_customer_group_id') . '.' . (int)$limit);
if (!$category_data) {
$category_data = array();
$query = $this->db->query("SELECT c.category_id, SUM(op.quantity) AS total FROM " . DB_PREFIX . "order_product op LEFT JOIN `" . DB_PREFIX . "order` o ON (op.order_id = o.order_id) LEFT JOIN `" . DB_PREFIX . "product` p ON (op.product_id = p.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN `" . DB_PREFIX . "product_to_category` p2c ON (p2c.product_id = p.product_id) LEFT JOIN `" . DB_PREFIX . "category` c ON (p2c.category_id = c.category_id) WHERE o.order_status_id > '0' AND p.status = '1' AND c.status = '1' AND p.date_available <= NOW() AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' GROUP BY p2c.category_id ORDER BY total DESC LIMIT " . (int)$limit);
$category_data = $query->rows;
$this->cache->set('category.bestseller.' . (int)$this->config->get('config_language_id') . '.' . (int)$this->config->get('config_store_id') . '.' . $this->config->get('config_customer_group_id') . '.' . (int)$limit, $category_data);
}
return $category_data;
}
}
我认为排序就在这里。我需要改变什么?
$query = $this->db->query("SELECT c.category_id, SUM(op.quantity) AS total FROM " . DB_PREFIX . "order_product op LEFT JOIN `" . DB_PREFIX . "order` o ON (op.order_id = o.order_id) LEFT JOIN `" . DB_PREFIX . "product` p ON (op.product_id = p.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN `" . DB_PREFIX . "product_to_category` p2c ON (p2c.product_id = p.product_id) LEFT JOIN `" . DB_PREFIX . "category` c ON (p2c.category_id = c.category_id) WHERE o.order_status_id > '0' AND p.status = '1' AND c.status = '1' AND p.date_available <= NOW() AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' GROUP BY p2c.category_id ORDER BY total DESC LIMIT " . (int)$limit);
用这个替换查询字符串。因此,将使用来自 {prefix}_products
table.
的 viewed
属性 按观看次数过滤类别
$query = $this->db->query("SELECT c.category_id, SUM(p.viewed) AS total FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN `" . DB_PREFIX . "product_to_category` p2c ON (p2c.product_id = p.product_id) LEFT JOIN `" . DB_PREFIX . "category` c ON (p2c.category_id = c.category_id) WHERE p.status = '1' AND c.status = '1' AND p.date_available <= NOW() AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' GROUP BY p2c.category_id ORDER BY total DESC LIMIT " . (int)$limit);
After changing the model, you need to reset the modification cache.
我有一个 Opencart 3 模块 - 类别畅销书。它显示了售出最多商品的热门类别。我想更改此过滤器。使其显示查看次数最多的产品类别。整理了一下资料,发现模型里面是这么写的
这是模型文件
<?php
class ModelExtensionModuleBestsellerCategory extends Model {
public function getBestSellerCategories($limit) {
$category_data = $this->cache->get('category.bestseller.' . (int)$this->config->get('config_language_id') . '.' . (int)$this->config->get('config_store_id') . '.' . $this->config->get('config_customer_group_id') . '.' . (int)$limit);
if (!$category_data) {
$category_data = array();
$query = $this->db->query("SELECT c.category_id, SUM(op.quantity) AS total FROM " . DB_PREFIX . "order_product op LEFT JOIN `" . DB_PREFIX . "order` o ON (op.order_id = o.order_id) LEFT JOIN `" . DB_PREFIX . "product` p ON (op.product_id = p.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN `" . DB_PREFIX . "product_to_category` p2c ON (p2c.product_id = p.product_id) LEFT JOIN `" . DB_PREFIX . "category` c ON (p2c.category_id = c.category_id) WHERE o.order_status_id > '0' AND p.status = '1' AND c.status = '1' AND p.date_available <= NOW() AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' GROUP BY p2c.category_id ORDER BY total DESC LIMIT " . (int)$limit);
$category_data = $query->rows;
$this->cache->set('category.bestseller.' . (int)$this->config->get('config_language_id') . '.' . (int)$this->config->get('config_store_id') . '.' . $this->config->get('config_customer_group_id') . '.' . (int)$limit, $category_data);
}
return $category_data;
}
}
我认为排序就在这里。我需要改变什么?
$query = $this->db->query("SELECT c.category_id, SUM(op.quantity) AS total FROM " . DB_PREFIX . "order_product op LEFT JOIN `" . DB_PREFIX . "order` o ON (op.order_id = o.order_id) LEFT JOIN `" . DB_PREFIX . "product` p ON (op.product_id = p.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN `" . DB_PREFIX . "product_to_category` p2c ON (p2c.product_id = p.product_id) LEFT JOIN `" . DB_PREFIX . "category` c ON (p2c.category_id = c.category_id) WHERE o.order_status_id > '0' AND p.status = '1' AND c.status = '1' AND p.date_available <= NOW() AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' GROUP BY p2c.category_id ORDER BY total DESC LIMIT " . (int)$limit);
用这个替换查询字符串。因此,将使用来自 {prefix}_products
table.
viewed
属性 按观看次数过滤类别
$query = $this->db->query("SELECT c.category_id, SUM(p.viewed) AS total FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN `" . DB_PREFIX . "product_to_category` p2c ON (p2c.product_id = p.product_id) LEFT JOIN `" . DB_PREFIX . "category` c ON (p2c.category_id = c.category_id) WHERE p.status = '1' AND c.status = '1' AND p.date_available <= NOW() AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' GROUP BY p2c.category_id ORDER BY total DESC LIMIT " . (int)$limit);
After changing the model, you need to reset the modification cache.