Magento 1.9 – How to Get Multiple Select Attribute Values

adminattributesmagento-1.9product

I have one multiple select attribute with the name 'recommendations' and I want to get the attribute values in the product list.

I create this code to get values. But now I want to replace i tag with Admin value: <i class="admin value"></i> and <span><?php echo $_target ?></span> with Default Store View values. How I can get this values separately?

I need to get Admin value and Default Store View in the same code.

<?php  if ($targetValues = $_product->getAttributeText('recommendations')) { ?> 
<div class="recommended-title"><?php echo $this->__('recommendations') ?></div>
<?php 
if (is_string($targetValues)) {
$targetValues = array($targetValues);
}
foreach($targetValues as $_target) :?>
<ul class="list-inline recommended-logo">
<li>
<i class="<?php echo $_target ?>"></i><span><?php echo $_target ?></span></li>
</ul>
<?php endforeach;
 }
?>

enter image description here

Best Answer

Use below code to get multi-select values and then you can foreach loop for each attribute value.

<?php $targetValue = explode(",", $_product->getResource()->getAttribute('recommendations')->getFrontend()->getValue($_product)); ?>
<?php  if(count($targetValue) > 0 ): ?> 
    <div class="recommended-title"><?php echo $this->__('recommendations') ?></div>
    <?php foreach($targetValues as $key=>$val): ?>
    <ul class="list-inline recommended-logo">
        <li>
            <i class="<?php echo $key ?>"></i><span><?php echo $val ?></span>
        </li>
    </ul>
    <?php endforeach; ?>
<?php endif; ?>