1

我是 opencart 的新手,我在 opencart 中创建了一个类似于 latest 模块的模块,但不同之处在于唯一的最新模块显示最新产品,而我的模块适用于所有产品并以随机方式显示产品。这个我的模块工作正常..但是显示每个产品的实际评级时出现问题..现在我想在我的模块中添加评级系统。所以我想知道 whta 应该是 mysql 的正确查询,以获取所有产品信息,如名称、描述、评论、评级、product_id 等。

4

1 回答 1

4

你还没有展示你的方法,所以它只是一般的指针

首先你在你的控制器文件中加载 product.php 模型$this->load->model('catalog/product');

然后你决定在调用 getProducts 时你的过滤器是什么,如果你不提供任何过滤器,它将返回数据库中的所有产品,假设你决定没有过滤器,然后只传递一个空的数据数组(或者根本不传递任何东西)

$data = array();

然后你调用函数

    $results = $this->model_catalog_product->getProducts($data); //or without $data

现在你可以做类似的事情

foreach ($results as $result) {
$this->data['products'][] = array(
                    'product_id'  => $result['product_id'],
                    'name'        => $result['name'],
                    'rating'      => $result['rating'],

                );

现在你可以在你的 tpl 文件中使用它,比如

<?php foreach ($products as $product) { ?>
some code here
<?php echo $product['rating']; ?>
<?php } ?>

这是您应该使用的通用方式,并且也很容易,如果您知道 getProducts 函数如何从数据库中取出数据并返回结果,请参阅目录/模型/目录/product.php 中的 getProducts 函数

于 2013-02-11T16:14:03.767 回答