0

I have a multi select attribute with some values. I get the values with this code:

<?php $targetValue = explode(",", $_product->getResource()->getAttribute('nf_allergie')->getFrontend()->getValue($_product)); ?>

    <?php if(count($targetValue) > 0 ): ?>
        <?php foreach($targetValue as $key=>$val): ?>
            <div class="<?php echo $key ?>">
                <span>
                    <?php echo $val ?>
                </span>
            </div>
            <br>
        <?php endforeach; ?>
    <?php endif;?>

For example some values: - Gluten - Mosterd - Noten - Schaaldieren

How can I check if the value is Gluten, then show Gluten.jpg. And if also Mosterd is selected, then show also Mosterg.jpg

How can I achieve such thing?

  • Possible duplicate of Magento multiple selection attribute – sv3n Jun 22 '17 at 14:33
  • Yes but the question was a little bit different, this is only for checking if a value is, then show this. – n00bly Jun 22 '17 at 14:42
  • Do you want to show images instead of labels? – Rinto George Jan 24 at 10:48
0

Easy Method - Keep your images in media location or skin location in Magento, with these names.

I believe these labels are fixed.

<?php $targetValue = explode(",", $_product->getResource()->getAttribute('nf_allergie')->getFrontend()->getValue($_product)); ?>

<?php if(count($targetValue) > 0 ): ?>
    <?php foreach($targetValue as $key=>$val): ?>
        <div class="<?php echo $key ?>">
            <span>
                <img src="skinurl/<?php echo $val ?>.jpg >
            </span>
        </div>
        <br>
    <?php endforeach; ?>
<?php endif;?>

Another Method - Upload image with attribute options values.

Please read this tutorial for more details http://www.bubblecode.net/en/2012/02/05/magento-add-images-to-product-attribute-options/

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.