3

I am trying to retrieve all the featured product like this in my .phtml block:

$collection = Mage::getResourceModel('catalog/product_collection')
                           ->setStoreId(Mage::app()->getStore()->getId())
                           ->addAttributeToFilter('featured_product', array(1))
                           ->addAttributeToFilter('status', array(1));

But i keep getting an error like this:

PHP Fatal error: Uncaught Error: Call to a member function getBackend() on boolean in /var/www/gv/app/code/core/Mage/Eav/Model/Entity/Abstract.php:816\nStack trace:\n #0 /var/www/gv/app/code/core/Mage/Eav/Model/Entity/Collection/Abstract.php(1377): Mage_Eav_Model_Entity_Abstract->isAttributeStatic('featured_produc...')\n#1 /var/www/gv/app/code/core/Mage/Eav/Model/Entity/Collection/Abstract.php(321): Mage_Eav_Model_Entity_Collection_Abstract->_getAttributeConditionSql('featured_produc...', Array, 'inner')\n#2 /var/www/gv/app/code/core/Mage/Catalog/Model/Resource/Product/Collection.php(1440): Mage_Eav_Model_Entity_Collection_Abstract->addAttributeToFilter('featured_produc...',

2

This is tested code on 1.9.x

 $collection = Mage::getResourceModel('productslider/product_collection')
                ->addAttributeToSelect('*')
                ->addAttributeToFilter('featured', array('eq' => '1'))
                 ->addAttributeToFilter('status', array(1)) ;
        foreach($collection as $product){

            echo '<pre>'; print_r($product->getName()); die('ok');
    }
1

Try this code:

<?php
    $collection = Mage::getResourceModel('catalog/product_collection')
        ->addAttributeToSelect('*')
        ->addAttributeToSelect('featured') //add your featured attribute code here if not created then first create attribute in admin side 
        ->addAttributeToFilter('featured', 1); //

    Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($collection);
    Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($collection);

    if($collection->getSize()) {
        foreach($collection as $product) {
            print_r($product);
        }
    }
?>
1

Try Below code

 $collection = Mage::getResourceModel('catalog/product_collection')
               ->setStoreId(Mage::app()->getStore()->getId())
               ->addAttributeToFilter('featured_product', array('eq'=>1))
               ->addAttributeToFilter('status',array('eq' => Mage_Catalog_Model_Product_Status::STATUS_ENABLED));   
0

Step 1:You have to create attribute of named featured

Step 2:

You can Use Below code to get the featured product collection in your phtml

page

$_productCollection = Mage::getModel('catalog/product')
                        ->getCollection()
                        ->addAttributeToSort('created_at', 'DESC')
                        ->addAttributeToSelect('*')
                        ->addAttributeToFilter('featured', array('yes' => true))
                        ->load();
foreach ($_productCollection as $key => $product) {
                     echo $product->getId()."<br>";
                     echo $product->getName();
                     } 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.