6

I need to retrieve product attribute value based on the attribute id, here's how I get the id and label for each attribute

$attributes= Mage::getResourceModel('catalog/product_attribute_collection')->getItems();
foreach ($attributes as $attribute) {
   $id[] = $attribute->getAttributecode();
   $label[] = $attribute->getFrontendLabel();
}
4

Try this:

$attributeModel = Mage::getModel('eav/entity_attribute')->loadByCode('catalog_product','color');
echo $attributeModel->getStoreLabel($storeId);

If you want to get any attribute value of any product ;

$_product = Mage::getModel('catalog/product')->load($productId);
echo $_product->getData($attributeCode);
1

Try this

Retrieve product attribute value based on the attribute code

<?php
   $attributeCode = "size";
   $attribute = Mage::getModel('eav/entity_attribute')->loadByCode('catalog_product', $attributeCode);
   $options = Mage::getModel('eav/entity_attribute_source_table')
            ->setAttribute($attribute)
            ->getAllOptions(false);

   foreach ($options as $option) {
        echo $option['label']." => ".$option['value']."<br>";
   }
?>

Retrieve product attribute value based on the attribute id

<?php
  $attributeId = 198;
  $attribute = Mage::getModel('eav/entity_attribute')->load($attributeId);
  $options = Mage::getModel('eav/entity_attribute_source_table')
            ->setAttribute($attribute)
            ->getAllOptions(false);

   foreach ($options as $option) {
        echo $option['label']." => ".$option['value']."<br>";
   }
?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.