Magento - get product count by attribute -


i've been searching quite few hours , can't seem come answer.

i have bunch of different products, , bunch of different attributes , attribute sets.

i'm looking count number of products have valid attribute value entire list of attributes. so, want loop through each attribute, count number of products have attribute, , have value attribute.

all of our attributes sources third party. so, either leave value blank, or put "n/a".

the problem facing right fact can't products have specific attribute available them. 'notnull' filter isn't working me. i've tried many different ways. current code isn't working, looks promising. i'll give error getting one, if has solution love share me.

    $productattrs = mage::getresourcemodel('catalog/product_attribute_collection');     $x = 0;     foreach ($productattrs $productattr) {          $collection_size = mage::getmodel('catalog/product')->getcollection()             ->addattributetoselect($productattr->getattributecode())             ->addattributetofilter(                 array                 (                     array                     (                         'attribute' => $productattr->getattributecode(),                          'notnull' => true                     ),                     array                     (                         'attribute' => $productattr->getattributecode(),                         'nin' => array('n/a', '', ' ')                     )                 )             );         echo count($collection_size->getdata());         echo "<br>";         $x++;         if($x>50) {             break;         }     } 

so, above, i'm showing first 50 attributes. specific code gives error. gives error after showing count first attribute, assume because category_id attribute needs ignored (i'll now), doesn't counting products -- seems give value of products in store, when know not products have specific attributes in question.

fatal error:  uncaught exception 'pdoexception' message 'sqlstate[42s22]: column not found: 1054 unknown column 'at_category_ids.category_ids' in 'field list'' in /var/www/html/store/lib/zend/db/statement/pdo.php:228 

i'm not sure go here.

also, reason me doing this..... have layered navigation , want turn attributes on set in more 200 products. don't want 4000 attributes available layered navigation. so, if has better way of solving layered navigation issues, i'm ears there well.

thanks in advance!

here's did. still have figure out count going use given attributes , set attributes available layered navigation, go through , find out number of products have seemingly values given attribute.

if wanted, print out number of products per attribute including like.....

                echo $productattr->getattributecode();                 echo " : ";                 echo count($collection->getdata());                              echo "<br>"; 

put somewhere after "collection" piece of code.

    //get list of attributes     $productattrs = mage::getresourcemodel('catalog/product_attribute_collection');     $x = 0;     $y = array();     //go through each attribute , number of products exist attribute     foreach ($productattrs $productattr) {          //exclude attributes don't match criteria         if($productattr->getattributecode() == 'category_ids' || substr($productattr->getattributecode(), 0, 2) != 'i_') {                 continue;         }         //get attributes match following         $collection = mage::getmodel('catalog/product')->getcollection()             ->addattributetoselect($productattr->getattributecode())             ->addattributetofilter(                 array                 (                     array                     (                         'attribute' => $productattr->getattributecode(),                          'notnull' => true                     ),                     array                     (                         'attribute' => $productattr->getattributecode(),                         'nin' => array('n/a', '', ' ')                     )                 )             );         //use y array count how many attributes have more amount of products         //this loop give 100, 200, 300, 400, 500, 600, 700, 800, 900, , 1000         //loops backwards , breaks if count on current number          for($z=0; $z<=10; $z++) {             if(count($collection->getdata()) > $z*100)  {                 $y[$z]++;                 // break;             }         }         $x++;     }     //after finding out numbers, print results     $number_over = 0;     foreach($y $num) {         $number_under = $number_over+100;         echo "<br>total number of attributes set in on " . $number_over;         echo " products total is: " .$num;         $number_over = $number_over + 100;     } } 

edit: said previously, using icecat product syndication. so, want @ icecat attributes, prefixed "i_", without quotes. so, excluding attributes not have "i_" prefix.


Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -