1

是否可以在每个类别中显示特殊产品,仅显示与该类别相关的产品?例如,如果类别为“诺基亚”,则显示仅在诺基亚下的特价商品,不显示其他特价商品。

特色产品也一样。

可能吗?如果可能的话,您能否解释一下如何做到这一点,以便初学者能够理解它?我正在使用 OpenCart 1.5.3.1。

4

2 回答 2

1

好的,这里有一些东西可以帮助您入门。我正在使用 Opencart 1.5.5.1。在最后catalog/controller/module/special.php找到这条线:

if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/module/special.tpl')) {

之前,添加这段代码(我希望我的评论足够清楚):

// filter specials by current category code - - - - - - - 

/* check wether current page is a category page (i.e. has 'path' var) */
if (isset($this->request->get['path'])) {

    /* get category ID from path (last number) */
    $parts = explode('_', (string)$this->request->get['path']);
    $category_id = (int)array_pop($parts);

    /* loop through products */
    foreach ($this->data['products'] as $k => $item){
        /* check whether this product is assigned to current category */
        $sql = "SELECT * FROM " . DB_PREFIX ."product_to_category WHERE product_id = ". $item['product_id']. " AND category_id = ".$category_id;

        $query = $this->db->query($sql);

        /* if no match found, remove this item */
        if (count($query->rows) == 0){
            unset ($this->data['products'][$k]);
        }

    }
}

// end of filter specials by current category code - - - -
于 2013-05-09T10:16:59.790 回答
0

我自己就需要这个,这是我的解决方案,你需要修改catalog/model/catalog/product.phpcatalog/controller/module/special.php. 我推荐 VQMod 这样做:

product.php代替_

$sql = "SELECT DISTINCT ps.product_id, (SELECT AVG(rating) FROM " . DB_PREFIX . "review r1 WHERE r1.product_id = ps.product_id AND r1.status = '1' GROUP BY r1.product_id) AS rating FROM " . DB_PREFIX . "product_special ps LEFT JOIN " . DB_PREFIX . "product p ON (ps.product_id = p.product_id) 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) WHERE p.status = '1' AND p.date_available <= NOW() AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND ps.customer_group_id = '" . (int)$customer_group_id . "' AND ((ps.date_start = '0000-00-00' OR ps.date_start < NOW()) AND (ps.date_end = '0000-00-00' OR ps.date_end > NOW())) GROUP BY ps.product_id";

和:

$sql = "SELECT DISTINCT ps.product_id, (SELECT AVG(rating) FROM " . DB_PREFIX . "review r1 WHERE r1.product_id = ps.product_id AND r1.status = '1' GROUP BY r1.product_id) AS rating".(isset($data['category_id']) ? ", (SELECT category_id FROM oc_product_to_category WHERE product_id = ps.product_id AND category_id = '".$data['category_id']."' GROUP BY category_id) as category" : "")." FROM " . DB_PREFIX . "product_special ps LEFT JOIN " . DB_PREFIX . "product p ON (ps.product_id = p.product_id) 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) WHERE p.status = '1' AND p.date_available <= NOW() AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND ps.customer_group_id = '" . (int)$customer_group_id . "' AND ((ps.date_start = '0000-00-00' OR ps.date_start < NOW()) AND (ps.date_end = '0000-00-00' OR ps.date_end > NOW())) GROUP BY ps.product_id".(isset($data['category_id']) ? ",category HAVING category='".$data['category_id']."'" : "");

special.php:添加

if (isset($this->request->get['path'])) {
    $parts = explode('_', (string)$this->request->get['path']);
    $data['category_id'] = (int)array_pop($parts);
}

$results = $this->model_catalog_product->getProductSpecials($data);
于 2013-05-29T14:31:40.250 回答