简体   繁体   中英

Magento - List products with a specific attribute

How can we list in Magento, products whose attribute, which I defined myself "generatepdf" is equal 1 ?

I wrote the following code :

    $collection = Mage::getModel('catalog/product')->getCollection();
    $collection->addAttributeToSelect('*');
    $collection->addFieldToFilter(array(
        array('name'=>'generatepdf','eq'=>'1')
    ));
    foreach ($collection as $product) {
        var_dump($product->getData());
    }

But I get the following error:

    Fatal error: Call to a member function getBackend() on a non-object in /var/www/app/code/core/Mage/Eav/Model/Entity/Abstract.php on line 816

My code isn't good or is there a specific method to set the attributes, so they can be used in this type of request ?

$collection = Mage::getModel('catalog/product')->getCollection();
$collection->addAttributeToSelect('*');
$collection->addAttributeToFilter('generatepdf','1');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM