Frage

I want to get the product collection in magento.For that i use some code but i think this code is not what i need.I want to get collection on attribute base.I got some products but it didn't match to those products that are filters from advance results for that attribute.Means different results from my collection and advance search results.Also the product url is not valid one.May be someone know where is the problem ? thanks in advance.My code is :

<?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 } ?>
War es hilfreich?

Lösung 2

It should work correctly:

$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();
}

Also check in admin - Catalog->Attributes->Manage Attributes - Used in Product Listing set Yes.

Andere Tipps

You have used 2 array in the field to filter. Try with one.

<?php $collection = Mage::getModel('catalog/product') ->getCollection()->addAttributeToSelect('*') ->addFieldToFilter('attribute'=>'manufacturer','eq'=>'23');

please use addAttributeToFilter('manufucture',23)

instead of

adfieldtofilter

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top