0

I have some php code I am trying to use to get a listing of product names based on specific criteria. That criteria is the status of the product is enabled and the visibility is set to either catalog or catalog,search My issue is the below code gives me an error that says "Fatal error: Call to a member function getBackend() on a non-object in public_html/app/code/core/Mage/Eav/Model/Entity/Abstract.php on line 816";

   $allProduct = Mage::getModel('catalog/product')->getCollection()->addAttributeToSelect('*')->addAttributeToFilter(array(
array(
    'attribute' => 'status',
    'eq'        => 1),
    ),
array(
    'attribute' => 'visibility',
    'eq'      > '1',
    ),
));
$product_media = Mage::getModel('catalog/product_media_config');
$temp = "";
$itemCounter = 0;
$currentItem = 0;
$currentItemName = $_helper->productAttribute($_product, $_product->getName(), 'name');
foreach($allProduct as $p){
    $tempName = $product_media->getMediaUrl($p->getNailImage());
    if($currentItemName == $p['name']){
        $currentItem = $itemCounter;
    }
    $itemCounter++;
    if(!$p['rgba']){
        $p['rgba'] = '666';
    }       

However the below code works except for it lists all products that are enabled. I just am trying to add the visibility filter to my above code.

   $allProduct = Mage::getModel('catalog/product')->getCollection()->addAttributeToSelect('*')->addAttributeToFilter('status', array('eq' => 1));
$product_media = Mage::getModel('catalog/product_media_config');
$temp = "";
$itemCounter = 0;
$currentItem = 0;
$currentItemName = $_helper->productAttribute($_product, $_product->getName(), 'name');
foreach($allProduct as $p){
    $tempName = $product_media->getMediaUrl($p->getNailImage());
    if($currentItemName == $p['name']){
        $currentItem = $itemCounter;
    }
    $itemCounter++;
    if(!$p['rgba']){
        $p['rgba'] = '666';
    }
2

Try this:

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

Or this:

$allProduct = Mage::getModel('catalog/product')->getCollection()->addAttributeToSelect('*')
->addAttributeToFilter('status', array('eq' => 1))
->addAttributeToFilter('visibility', array('eq' => 1));

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.