3

I have this code to get values from select/multiselect attributes

<?php
$attributes = $_product->getAttributes();
$themeColor = $attributes['theme_color']->getFrontend()->getValue($_product);
echo $themeColor;
?>

But it works only for select. When I'm pointing it to multiselect attribute it show nothing.

1
  • Try this: $attribute_value = $product->getResource()->getAttribute($attribute_code)->getFrontend()->getValue($product);
    – pzirkind
    Commented Jun 22, 2014 at 17:00

3 Answers 3

1

To be more descriptive,

$_product = $this->getProduct();
$_product -> getThemeColor(); //this will return the attribute values separated by comma
$_product -> getAttributeText('theme_color'); //this will return the labels of the options separated by comma.
0

Try with

$_product->getAttributeText('theme_color');
1
  • No - it isn't working Commented Feb 24, 2014 at 13:48
0

You should be able to get the value(s) of the multiselect attribute for a given product by using the following code:

$attribute_value = $product->getResource()->getAttribute($attribute_code)->getFrontend()->getValue($product);

If however you want to get all possible options for a given mutli-select attribute use this code:

$attributeId = Mage::getResourceModel('eav/entity_attribute')->getIdByCode('catalog_product','attribute_code_here');

$attribute = Mage::getModel('catalog/resource_eav_attribute')->load($attributeId);

$attributeOptions = $attribute ->getSource()->getAllOptions();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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