Magento -> How can I list products with same multiple select attribute?
I'm trying to retrieve products that carry same attribute. Specifically multiple select type. It seems the basic methods don't work. Selecting only the "name" attribute, I get all my products listed. When I try to filter "shop_by_color", it filters down, but not entirely. Not sure why it removes some and leaves others, even though they are the wrong ones. Any tips appreciated.
<?php
$model = Mage::getModel('catalog/product');
$collection = $model->getCollection();
$collection->addAttributeToSelect('name');
$collection->addAttributeToFilter('shop_by_color'); // multiple select attribute
$collection->addFieldToFilter(array(array('attribute'=>'shop_by_color','finset'=>array('Yellow, White'),
)));
$collection->load();
?>
<ul>
<?php foreach($collection as $product) : ?>
<li><a href="<?php echo $product->getProductUrl() ?>"><?php echo $pro开发者_JS百科duct->getName() ?></a></li>
<?php endforeach; ?>
</ul>
Hi I am not sure about your syntax I have never seen this sort of thing before.
<ul>
<?php foreach($collection as $product) : ?>
<li><a href="<?php echo $product->getProductUrl() ?>"><?php echo $product->getName()
?></a></li>
<?php endforeach; ?>
</ul>
Shouldn't it be...
<ul>
<?php foreach($collection as $product) { ?>
<li><a href="<?php echo $product->getProductUrl() ?>"><?php echo $product->getName()
?></a></li>
<?php } ?>
</ul>
DC
<?php
$_productCollection=$this->getLoadedProductCollection();
$_productCollection->clear()
->addAttributeToSelect('*')
->addAttributeToFilter('type_id', array('eq' => 'simple'))
->addAttributeToSort('name', 'ASC')
->addAttributeToSort('created_at', 'ASC')
->load();?>
on list page please use this type collection filter it's working fine.
精彩评论