从属性值magento中选择图像

时间:2014-03-07 16:48:15

标签: magento

我有这段代码:

$collection = Mage::getModel('catalog/product')->getCollection()
->addAttributeToSelect('*') 
->setPageSize(4) 
->setCurPage(4); 

foreach ($collection as $product) {
$image = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA).'catalog/product'.$product->getImage();

echo '<img src="'.$image.'" WIDTH=245 HEIGHT=245>';
}

这完美并展示了4个产品图片。 当属性颜色等于白色时,如何从属性颜色中获取4个产品图像?

当我尝试这个时,我得到一个错误:

->addAttributeToSelect('color', 'white')

1 个答案:

答案 0 :(得分:1)

$collection = Mage::getModel('catalog/product')->getCollection()
->addAttributeToSelect('*') 
->addAttributeToFilter('color', 'white')
->setPageSize(4) 
->setCurPage(4);
相关问题