Home / Magento / How to Filter Products Based on Attribute Value & Attribute set | magento | Magento 1.9

How to Filter Products Based on Attribute Value & Attribute set | magento | Magento 1.9

You can follow the code :

<?php
    ob_start();  ini_set('max_execution_time', 0);  set_time_limit(0);   ignore_user_abort(true); 
    require_once '/chroot/home/powerme1/powermedicalsupplies.com/html/app/Mage.php';    
    
    
    Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);   
    $_write = Mage::getSingleton('core/resource')->getConnection('core_write');
    $_read = Mage::getSingleton('core/resource')->getConnection('core_read');
    
    
    
    $collection = Mage::getModel('catalog/product')->getCollection()->addAttributeToFilter('attribute_set_id',9)->addAttributeToFilter('brand', array('eq' => 1674));
    
    
    foreach($collection as $_product):
        $_product = $_product->load($_product->getId());
        echo $_product->getSku() . ' >>> ' . $_product->getUpc() .'<br>';
        
    endforeach;

    echo '<hr />';

    $collection = Mage::getModel('catalog/product')->getCollection()->addAttributeToFilter('attribute_set_id',9)->addAttributeToFilter('brand', array('eq' => 1853));    
    foreach($collection as $_product):
        $_product = $_product->load($_product->getId());
        echo $_product->getSku() . ' >>> ' . $_product->getUpc() .'<br>';
        
    endforeach;
?>

Hits: 9

Leave a Reply