get attributes of products in magento programatically


<?php
require_once 'app/Mage.php';
umask(0);
Mage::app('default');
$app = Mage::app();
function toOptionArray()
    {
    	$ignoreAttributes = array
                            ('sku','name', 'attribute_set_id', 'type_id',
                             'qty','price', 'status', 'visibility',
                             'description','enable_googlecheckout','special_from_date','special_price',
                             'url_key','weight','short_description');
        //$ignoreAttributes = array('sku', 'name', 'attribute_set_id', 'type_id', 'qty', 'price', 'status', 'visibility');
    	$collection = Mage::getResourceModel('catalog/product_attribute_collection')
            ->addVisibleFilter();

        $result = array();
    	foreach ($collection as $model) {
    		if(in_array($model->getAttributeCode(), $ignoreAttributes)) {
    			continue;
    		}
    		$productCollection = Mage::getModel('catalog/product')->getCollection();
    		$productCollection->addAttributeToSelect(array($model->getAttributeCode()));
    		$productCollection->addAttributeToFilter($model->getAttributeCode(), array('gt' => 0));

    		if(count($productCollection->getData()) > 0) {
    			$result[] = array('value' => $model->getAttributeCode(), 'label'=>$model->getFrontendLabel());
    		}

        }

       return $result;

    }

     echo "<br />start";
    $a = toOptionArray();
    echo '<pre>';
    print_r($a);
    echo '</pre>';

    echo "<br />end";
?>

Share on Facebook




About Pragnesh Karia

Pragnesh Karia, Open Source Enthusiast, Software Professional, Software Developer, Technical Lead ,Magento, Joomla ,Joomla LMS , Moodel LMS ,PHP ,Mysql, Ajax, Javascript, Jquery, Linux, Fan of Open Sources , Annet Technologies , SEO Analyst , Mootools