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

Pankaj Sharma
1,3912 gold badges21 silver badges41 bronze badges
asked Mar 22, 2017 at 13:04

1 Answer 1

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; ?>
answered Mar 22, 2017 at 13:28
18
  • Hi thank you, but I think is not the best idea to use explode Commented Mar 22, 2017 at 13:33
  • without explode command it will gives all you select values in comma separated. For example, value1, value2, value 3 Commented Mar 22, 2017 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? Commented Mar 22, 2017 at 13:45
  • Please check my edited code and let me know if you have any query in that Commented Mar 22, 2017 at 13:56
  • Warning: Invalid argument supplied for foreach() Commented Mar 22, 2017 at 14:02

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.