0

我在不同的论坛上尝试过,发现以下代码对我有帮助,但它没有为我返回任何东西。

    $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总是零长度。

4

1 回答 1

0

好吧,我们需要设置storeId用于获取集合 wrt 类别。我使用了以下代码

    $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);
于 2014-01-08T08:08:33.357 回答