获得Category上所有产品集合
获得Category下所有产品集合
如果想得到一个Category下所有产品集合,可以用Magento内置的方法
但是,结果却不能输出产品名字。这时需要调用
再输出产品名字就OK了。不过Magento默认分类页面调用的是:
这将加载catalog模块下config.xml的/config/frontend/product/collection/attributes标签下所有的属性
如果想得到一个Category下所有产品集合,可以用Magento内置的方法
<?php $collection = $category->getProductCollection(); foreach($collection AS $_product) { echo $_product->getName(); }
但是,结果却不能输出产品名字。这时需要调用
$collection->addAttributeToSelect('name');
再输出产品名字就OK了。不过Magento默认分类页面调用的是:
$collection->addAttributeToSelect(Mage::getSingleton('catalog/config')->getProductAttributes());
这将加载catalog模块下config.xml的/config/frontend/product/collection/attributes标签下所有的属性