我是magento的新手。我有自定义属性字段名为" author"。我需要根据当前类别显示不同的作者姓名。请帮帮我!我对此感到困惑。目前它显示两次或三次,相同的作者姓名。任何帮助都会很感激。以下是无效的代码。
<?php
$cat_idD = Mage::getModel('catalog/layer')->getCurrentCategory()->getId();
$loadcatID = Mage::getModel('catalog/category')->load($cat_idD);
$collection = $loadcatID ->getProductCollection();
$collection->addAttributeToSelect('author');
$collection->getSelect()->distinct(true);
$authname = "";
foreach( $collection as $product){
$authname .="<li>";
$authname .="<input type='radio' id='".$product->getId()."' name='author' value='".$product->getauthor()."' class='left authfilter'>";
$authname .="<label for='".$product->getId()."' class='left'>".$product->getauthor()."</label>";
$authname .="</li>";
}
echo $authname;
?>
答案 0 :(得分:0)
你应该按“作者”分组。
$collection->getSelect()->group('author');
如果要调试执行的查询:
$collection->getSelect()->__toString();
希望这会对你有所帮助。