0

嗨,我想自定义通过管理员设置类别的功能模块显示相关产品而不是特色模块

当我选择类别时,它会显示类别产品什么将是控制器的代码获取类别 n 将产品数组分配给该类别

下面是类别选择输入的视图代码

        <td><select name="category_id">

        <?php foreach($categories as $category) { ?>
        <option value="<?php echo $category['category_id'];?>"><?php echo $category['name'];?></option>
         <?php } ?>

        </select>
4

1 回答 1

-1
$categories = $this->model_catalog_product->getProductCategories(
    $this->request->get['product_id']);
foreach($categories as $category_id) {
   // do something
}

getProductCategories函数添加到model/catalog/product.php

public function getProductCategories($product_id) {
    $product_category_data = array();
    $query = $this->db->query("SELECT * FROM " . DB_PREFIX .
           "product_to_category WHERE product_id = '" . (int)$product_id . "'");
    foreach ($query->rows as $result) {
            $product_category_data[] = $result['category_id'];
    }
    return $product_category_data;
}
于 2014-01-28T06:52:21.957 回答