3

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

3

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; ?>
  • Hi thank you, but I think is not the best idea to use explode – Robert Mar 22 '17 at 13:33
  • without explode command it will gives all you select values in comma separated. For example, value1, value2, value 3 – Abhishek Panchal Mar 22 '17 at 13:39
  • can you give me an example? how will work with explode? can you edit your answer with the code that contain explode too? – Robert Mar 22 '17 at 13:45
  • Please check my edited code and let me know if you have any query in that – Abhishek Panchal Mar 22 '17 at 13:56
  • Warning: Invalid argument supplied for foreach() – Robert Mar 22 '17 at 14:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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