Reputation: 351
Pardon if this has been asked before. I have found several posts about loading attributes but I haven't been able to load the ones I need based on what I've read.
I'm trying to create a select box to display the values of a custom attribute on a page that lives within the app but does not belong to it (just a custom PHP product display page). I know I'm close, I just don't know what is the proper method to call for this.
Here is what I have so far:
$attributeInfo = Mage::getResourceModel('eav/entity_attribute_collection')
->setCodeFilter('color_attribute')
->getFirstItem();
If I print $attributeInfo I get an array with the attribute info but I am at a loss as to how to display ONLY the name and value of the color_attribute that applies to the current product only.
echo "<pre>"; print_r($attributeInfo->getData()); echo "</pre>";
Basically, I want to load all of the "color_attribute"s that apply to a particular product in a select box. That way the user can view a product and select its color by selecting the color from the select.
THANKS!
Upvotes: 2
Views: 2712
Reputation: 23205
Better to work with the attribute config.
/* @var $attr Mage_Eav_Model_Entity_Attribute */
$entityType = 'catalog_product';
$attrCode = 'some_attr';
$attr = Mage::getModel('eav/config')->getAttribute($entityType,$attrCode);
var_dump($attr->getSource()->getAllOptions());
Upvotes: 3