搜索
开启辅助访问 切换到宽版

QQ登录

只需一步,快速开始

扫一扫,访问微社区

注册 找回密码
查看: 5070|回复: 1

Opencart 首页最新产品(Latest Products)随机显示方法

[复制链接]
发表于 2012-5-25 11:25:40 | 显示全部楼层 |阅读模式
Opencart 首页最新产品(Latest Products)随机显示方法

Opencart 首页Latest Products产品是不可控的,如果一直不上传新产品, Latest Products显示固定不变,不像zen-cart每次刷新都有变化。我帮它动一下小手术。

文件位置:catalog\model\catalog\product.php.

方法一

把getLatestProducts修改成以下代码:

public function getLatestProducts($limit) {

$query = $this->db->query("SELECT *, pd.name AS name, p.image, m.name AS manufacturer, ss.name AS stock, (SELECT AVG(r.rating) FROM " . DB_PREFIX . "review r WHERE p.product_id = r.product_id GROUP BY r.product_id) AS rating 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_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) LEFT JOIN " . DB_PREFIX . "stock_status ss ON (p.stock_status_id = ss.stock_status_id) WHERE p.status = '1' AND p.date_available <= NOW() AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "' ORDER BY rand() DESC LIMIT " . (int)$limit);


$product_data = $query->rows;

return $product_data;
}

方法二

把getLatestProducts修改成以下代码:

    public function getLatestProducts($limit) {
        $product_data = $this->cache->get('product.latest.' . $this->config->get('config_language_id') . '.' . (int)$this->config->get('config_store_id') . '.' . $limit);

        if (!$product_data) {

            $query = $this->db->query("SELECT *, pd.name AS name, p.image, m.name AS manufacturer, ss.name AS stock, (SELECT AVG(r.rating) FROM " . DB_PREFIX . "review r WHERE p.product_id = r.product_id GROUP BY r.product_id) AS rating 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_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) LEFT JOIN " . DB_PREFIX . "stock_status ss ON (p.stock_status_id = ss.stock_status_id) WHERE p.status = '1' AND p.date_available <= NOW() AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "' ORDER BY rand() DESC LIMIT " . (int)$limit);


            $product_data = $query->rows;

            $this->cache->set('product.latest.' . $this->config->get('config_language_id') . '.' . (int)$this->config->get('config_store_id') . '.' . $limit, $product_data);
        }
        
        return $product_data;
    }

去前台刷新 一下,看一下效果

方法一和方法二区别,方法二执行速度比方法一快。但是每次都要删除system\cache\cache.product.latest.*这个文件才有更新。如果产品很多最好选用方法二


注意设置产品上架时间一致

回复

使用道具 举报

发表于 2016-8-15 15:35:06 | 显示全部楼层
那如果我想把(推荐产品)Featured,最新产品(Latest Products)替换成(热卖产品)hot sale或者其他文字应该怎么修改呢?
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

关闭

站长推荐 上一条 /1 下一条

QQ|手机版|OpenCart - 中文官方网站 ( 蜀ICP备09033774号|人工智能|网站地图

GMT+8, 2021-6-20 03:45 , Processed in 0.086866 second(s), 36 queries , Gzip On.

快速回复 返回顶部 返回列表