在opencart中按类别ID获取类别产品 [英] get category products by category id in opencart

查看:87
本文介绍了在opencart中按类别ID获取类别产品的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想自定义功能模块,因为通过管理员设置类别可以显示相关产品而不是功能模块

hi i want to customize the feature module that as category is set through admin display the relevant product instead of featured module

当我选择类别时,它会显示类别产品,将获得类别n的控制器代码将给出该类别的产品数组

when ever i select the category it displays category products what will be the code of controller which get category n give products array to that category

下面是类别选择输入的查看代码

below is the view code of category select input

        <td><select name="category_id">

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

        </select>

推荐答案

$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;
}

这篇关于在opencart中按类别ID获取类别产品的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆