Could someone teach me how to retrieve the option label for current store view? There is a table eav_attribute_option_value
where these information are already stored, but I don't know what model I must use.
1 Answer
Step1: First get the attribute id, for example by attibute code from the eav/entity_attribute
model:
$attributeModel = Mage::getModel('eav/entity_attribute')->loadByCode('catalog_product', $YourattributeCode)
Step2: Using the attribute id, load the catalog/entity_attribute
attribute model:
$attribute = Mage::getModel('catalog/product')
->getResource()
->getAttribute($attributeModel->getId());
Step3: set the current store id:
$attribute
->setStoreId(Mage::app()->getStore()->getId());
Step4: get the option value:
/* @var $attribute Mage_Catalog_Model_Entity_Attribute */
if ($attribute) :
$options = array();
if ($attribute->usesSource()) {
foreach ($attribute->getSource()->getAllOptions() as $optionId => $optionValue) {
if (is_array($optionValue)) {
$options[] = $optionValue;
} else {
$options[] = array(
'value' => $optionId,
'label' => $optionValue
);
}
}
}
endif;