几天后,我放弃了这一点--我想不通。
这是我的OpenCart XML提要代码的相关部分:
代码:
$this->load->model('catalog/category');
$this->load->model('catalog/product');
$this->load->model('tool/image');
$products = $this->model_catalog_product->getProducts();
foreach ($products as $product) {
if ($product['description']) {
$output .= '<PRODUCT>';
$output .= '<NAME>' . $product['name'] . '</NAME>';
$output .= '<DESCRIPTION>' . $product['description'] . '</DESCRIPTION>';
$output .= '</PRODUCT>';我希望能够只显示某些类别的产品,例如通过category_id。
假设我想显示类别(id) 1和2中的产品,应该做哪些更改?
我使用的是OpenCart 1.5.1.3
发布于 2013-04-23 13:53:37
如果查看getProducts()函数,您会发现它接受array作为参数。您可以向其传递过滤参数,并获取特定类别、厂商等的产品。参数包括:
filter_category_id
filter_sub_category
filter_filter
filter_name
filter_tag
filter_description
filter_manufacturer_id编辑:基于注释1:示例
创建一个您想要作为参数传递的数组,例如(获取类别id为10的所有产品及其子类别)
$data = array(
'filter_category_id' => '10',
'filter_sub_category' => 'true'
);然后调用
getProducts($data);或者以内联方式执行
getProducts(array('filter_category_id' => '10'));如果您需要多个类别,请单独获取它们,然后加入它们:
$set1 = $this->model_catalog_product->getProducts(array('filter_category_id' => '10'));
$set2 = $this->model_catalog_product->getProducts(array('filter_category_id' => '11'));
$products = $set1 + $set2;
...https://stackoverflow.com/questions/16157727
复制相似问题