Today we were trying to get store and default translated value of the select (drop down) and
multi-select attributes in Magento and it was a bit of a struggle so we decided to share the solution with the community. Before coming directly to the solution, let us share the situation where we required default and the store value of the drop down/multi-select.
One of our clients came to us with the requirement for showing swatches on layered navigation for colour attribute. It could have been a really simple solution if it was implemented on non multiligual site because we could have given the same name to the swatch image as colour label for example black colour swatch could have been named as black.gif but we had a situation that we had to implement this for 5 stores and all stores were in different languages which means we could have ended up having 5 black images instead of 1 black image, which is of course not ideal solution. So we came up with the solution to get the original and store label value for the given colour using the following piece of code -:
$attributeLabels = Mage::getModel('eav/entity_attribute_option') ->getCollection() ->setStoreFilter() ->join('attribute','attribute.attribute_id=main_table.attribute_id', 'attribute_code'); foreach ($attributeLabels as $attributeLabel) : if ($attributeLabel->getAttributeCode() == 'color' && $attributeLabel->getStoreValue()==$_item->getLabel()) $label = $attributeLabel->getDefaultValue(); endforeach;
Please note getDefaultValue() and getStoreValue() functions, the getDefaultValue() will return the default value of the actual colour and the getStoreValue() will return store defined value or label of the colour. In our case, we will always use default value because we want for each colour there should be only one image.
Hope this article helped you in some way. Please leave us your comment and let us know what do you think? Thanks.