magento attriubte基地的产品系列
我想在magento中获取产品集合。为此,我使用了一些代码,但我认为这些代码不是我所需要的。我想在属性基础上获取集合。我获取了一些产品,但它与那些从该属性的高级结果中筛选出来的产品不匹配。这意味着与我的集合和高级搜索结果不同。还有产品url无效。可能有人知道问题出在哪里?提前谢谢。我的代码是:magento attriubte基地的产品系列,magento,collections,product,Magento,Collections,Product,我想在magento中获取产品集合。为此,我使用了一些代码,但我认为这些代码不是我所需要的。我想在属性基础上获取集合。我获取了一些产品,但它与那些从该属性的高级结果中筛选出来的产品不匹配。这意味着与我的集合和高级搜索结果不同。还有产品url无效。可能有人知道问题出在哪里?提前谢谢。我的代码是: <?php $collection = Mage::getModel('catalog/product') ->getCollection()->addAttributeToSe
<?php $collection = Mage::getModel('catalog/product')
->getCollection()->addAttributeToSelect('*')
->addFieldToFilter(array(
array('attribute'=>'manufacturer','eq'=>'23'),
));
foreach ($collection as $product) {
?>
<div class="brand_name">
<p>Audi</p>
<a href="<?php echo $product->getProductUrl();?>"><?php echo substr($product->getName(),0,10);?></a>
</div>
<?php } ?>
奥迪
请使用addAttributeToFilter('Manufacture',23)
而不是
adfieldtofilter
您在字段中使用了2数组进行筛选。试试看
它应该能正常工作:
$attrToSelect = '*'; // or Mage::getSingleton('catalog/config')->getProductAttributes();
$collection = Mage::getModel('catalog/product')->getCollection()
->addAttributeToSelect($attrToSelect)
->addAttributeToFilter('manufacturer', 23)
;
foreach ($collection as $product) {
echo $product->getProductUrl();
}
同时签入admin-Catalog->Attributes->Manage Attributes-用于产品列表设置Yes。控制了产品和目录以及属性,并重新编制了索引。感谢您的重播。我收到了此错误解析错误:语法错误,意外的“=>”(T_双箭头)在
@Adda中,您能否验证错误是由于这一行代码本身还是由于其他代码造成的?您正在尝试在不使用数组的情况下传递数组元素。->addFieldToFilter('attribute'=>'manufacturer','eq'=>'23')
。请看这句话。@Adda您是对的,我的错。尽管我在回答中提到使用一个数组,但我在代码中省略了array
,对不起。现在对你有用吗?