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;
}
?>
1 Answer 1
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 explodeRobert– Robert2017年03月22日 13:33:02 +00:00Commented Mar 22, 2017 at 13:33
-
without explode command it will gives all you select values in comma separated. For example, value1, value2, value 3Abhishek Panchal– Abhishek Panchal2017年03月22日 13:39:09 +00:00Commented 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?Robert– Robert2017年03月22日 13:45:02 +00:00Commented Mar 22, 2017 at 13:45
-
Please check my edited code and let me know if you have any query in thatAbhishek Panchal– Abhishek Panchal2017年03月22日 13:56:12 +00:00Commented Mar 22, 2017 at 13:56
-
Warning: Invalid argument supplied for foreach()Robert– Robert2017年03月22日 14:02:00 +00:00Commented Mar 22, 2017 at 14:02
Explore related questions
See similar questions with these tags.