How do I check if an attribute value is assigned to any product? I have a product attribute A with values aa, bb, cc, dd, and I want to know if any product has aa or bb or cc or dd attribute value.
i.e if count(aa) in product attribute table >0
MY code so far
/*Get the Attributes for cat id 9 */
$layer = Mage::getModel("catalog/layer");
$layer->setCurrentCategory(Mage::getModel('catalog/category')->load(9));
$validAttributes = array();
foreach ($layer->getFilterableAttributes() as $attribute) {
//allow only select attributes - you can implement your additional filters here
if ($attribute->getFrontendInput() == 'select'){
$validAttributes[] = $attribute;
}
}
$i=0;
$name='';
/*Create the menu html in loop*/
foreach ($validAttributes as $attribute) {
$options = $attribute->getSource()->getAllOptions();
$attr=$attribute->getData();
$name = $attr['frontend_label'];
$temp.= '<li class=" nav-item level0 nav-1 level-top level-top first last nav-item--parent classic nav-item--only-subcategories parent">
<a href="#" class="level-top">
<span>'.$name.'</span>
<span class="caret"> </span>
</a>
<span class="opener"></span><ul class="level0 nav-submenu nav-panel--dropdown nav-panel" style="left: 44px; top: 40px; display: none;">';
foreach ($options as $option)
{
//Here I want to check count($option['value']) in product >0
$temp.='<li class="nav-item level1 nav-1-1 first last classic" >
<a href="'.$catUrl.'?'.$attr['attribute_code'].'='.$option['value'].'">
<span> '.$option['label'].'</span>
</a></li>';
}
$temp.= '</ul></li>';
$i++;
}