更改 Opencart 3 类别畅销书模块中的过滤方法
我有一个 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);
I have a module for Opencart 3 - Category Bestseller. It shows the popular categories in which the most items are sold. I would like to change this filter. Make it so that it shows the categories in which the most viewed products. After sorting through the files, I found that this was written in the model.
Here is model file
<?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;
}
}
I think that sorting is here. What I need to change?
$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);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
用此替换查询字符串。因此,将使用
{prefix}_products
表中的viewed
属性按浏览次数过滤类别。Replace the query string with this. So the categories will be filtered by number of views using the
viewed
property from the{prefix}_products
table.