문제

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 } ?>
도움이 되었습니까?

해결책 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.

다른 팁

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top