更新时间:2023-08-26 15:35:52
您可以通过调用$category->getProductCollection()
来获得类别中的产品.
You can obtain the products in a category by calling $category->getProductCollection()
.
示例:
$categories = Mage::getModel('catalog/category')->getCollection()->addAttributeToSelect('name');
$categories = Mage::getModel('catalog/category')->getCollection()->addAttributeToSelect('name');
foreach ($categories as $category) { $products = $category->getProductCollection()->addAttributeToSelect('name'); echo sprintf("< h1>%d. %s", $category->getId(), $category->getName()); foreach ($products as $product) { echo sprintf("%d. %s< br />", $product->getId(), $product->getName()); } }
foreach ($categories as $category) { $products = $category->getProductCollection()->addAttributeToSelect('name'); echo sprintf("< h1>%d. %s", $category->getId(), $category->getName()); foreach ($products as $product) { echo sprintf("%d. %s< br />", $product->getId(), $product->getName()); } }
我故意将html标记弄错了,以防止它们被解析.
edit: I made the html tags wrong on purpose, to prevent them from being parsed.