duanpao4522 2010-01-04 02:11
浏览 79

Magento - >如何列出具有相同多重选择属性的产品?

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 $product->getName() ?></a></li>            
<?php endforeach; ?> 
</ul>
  • 写回答

2条回答 默认 最新

  • doudang2817 2010-01-04 02:57
    关注

    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

    评论

报告相同问题?

悬赏问题

  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用