Magento->如何列出具有相同多选属性的产品?
我正在尝试检索具有相同属性的产品。具体来说是多选类型。看来基本的方法都行不通。仅选择“名称”属性,我会列出所有产品。当我尝试过滤“shop_by_color”时,它会过滤掉,但不完全过滤。不知道为什么它会删除一些并留下其他一些,即使它们是错误的。任何提示表示赞赏。
<?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>
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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
嗨,我不确定你的语法,我以前从未见过这种事情。
该不会是……
DC吧
Hi I am not sure about your syntax I have never seen this sort of thing before.
Shouldn't it be...
DC
在列表页面上,请使用这种类型的集合过滤器,它工作正常。
on list page please use this type collection filter it's working fine.