Magento Coding Solutions

Get product and there All Attribute by the category Id

***********************************************************************
Get product and there attribute by category Id
**********************************************************************
require_once '../app/Mage.php'; Mage::app();
<?
$cateColl='35+36+37+';
$categoryid=explode('+',$cateColl);
$brandname=array();
$brandIdcoll=array();
for($i=0;$i<count($categoryid)-1;$i++)
{

$category=Mage::getModel('catalog/category')->load($categoryid[$i])->getProductCollection()->addAttributeToSelect('*');
foreach ($category as $_product)
{

$attribute=$_product->getResource()->getAttribute("brand");
/* Checking if the attribute is either select or multiselect type.*/
if($attribute->usesSource())
{
/* Getting all the sources (options) and print as label-value pair */
$options = $attribute->getSource()->getAllOptions(false);
foreach($options as $optionval)
{

echo "Lable:".$optionval['label']."Value:".$optionval['value'];

}
}
}
}
} ?>

No comments:

Post a Comment