I have problem when I try to load multiselect values for product. I have:
$product->getSportTypes()
But these can give me only "sport type" Ids, not and names. How to get names?
Magento Stack Exchange is a question and answer site for users of the Magento e-Commerce platform. It only takes a minute to sign up.
Sign up to join this communityI suppose you want to display the value of the multiselect attribute named sport_types
in the frontend. To do so you need to follow below steps:
$sportTypes = explode(",",$_product->getResource()
->getAttribute('sport_types')->getFrontend()
->getValue($_product));
foreach($sportTypes as $key => $value){
echo $value;
}
Better use:
foreach($product->getAttributeText('sport_types') as $type) {
echo $type;
}
Amit already mentioned this but I want to make sure, that everyone understands, that getAttributeText returns you the attribute name for selects and an array for multiselects.
Magento:
$product->getSportTypes(); give array of option ids
And below give array of option
$product->getAttributeText('sport_types');
$attributeId = Mage::getResourceModel('eav/entity_attribute')->getIdByCode('catalog_product','sport_types');
$collection =Mage::getResourceModel('eav/entity_attribute_option_collection')
->setPositionOrder('asc')
->setAttributeFilter($attributeId)
->setStoreFilter(Mage::app()->getStore()->getId())
->load();
echo "<pre>";
print_r($collection->toOptionArray());
echo "</pre>";
For getting all Selected option of shop_types attribute try below code
$Collection=Mage::getModel('catalog/product')->getCollection()->addFieldToSelect('sport_types'')->groupByAttribute('sport_types'');