更改 Opencart 3 类别畅销书模块中的过滤方法

发布于 2025-01-18 02:35:05 字数 2562 浏览 6 评论 0原文

我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

听你说爱我 2025-01-25 02:35:05

用此替换查询字符串。因此,将使用 {prefix}_products 表中的 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);

更改模型后,需要重置修改缓存。

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.

$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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文