1

カテゴリーごとに、そのカテゴリーに関連する商品のみを表示する特別な商品を表示することはできますか? たとえば、カテゴリが「Nokia」の場合、Nokia の下にあるスペシャルのみを表示し、他のスペシャルは表示しません。

注目商品も同様。

出来ますか?できれば初心者にもわかるようにやり方を教えていただけないでしょうか?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 に答える