我尝试在不同的论坛上找到以下代码对我有帮助,但它并没有为我返回任何内容。
$limit = ($limit == 0) ? 50 : $limit;
$category = Mage::getModel('catalog/category')->load($cat_id);
$category->setIsAnchor(1);
$products = Mage::getResourceModel('catalog/product_collection')
->addAttributeToSelect('*')
->addAttributeToFilter("status", array("eq" => 1))
->addAttributeToFilter("visibility", array("eq" => 1))
->setPageSize($limit)
->addCategoryFilter($category)
->load();
$products
始终为零长度。
答案 0 :(得分:0)
好吧,我们需要为获取集合w.r.t类别设置storeId
。我使用了以下代码
$category = Mage::getModel('catalog/category')->load($cat_id);
$products = Mage::getResourceModel('catalog/product_collection')
->setStoreId(1)
->setPageSize($limit)
->addAttributeToFilter(
'status',
array('eq' => Mage_Catalog_Model_Product_Status::STATUS_ENABLED)
)
->addAttributeToFilter('visibility',
Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH)
->addCategoryFilter($category);