1

I am trying to display a custom multiselect attribute as images on the frontend if they have been selected by the store admin.

So far I have been able to get the values "as text" on the frontend but I am not sure how I can go about associating each value with an image...

Here is what I have so far

 <?php
 $multiSelectArray = $this->getProduct ()->getAttributeText('suitable_for');
 $lastItem = end ($multiSelectArray);
 foreach ($multiSelectArray as $multiSelectItem) {
 echo $multiSelectItem;
 if ($multiSelectItem != $lastItem) echo ", ";
 }
 ?>

The above code will show the values of the multiselect but I am stuck on how to associate the values with an image instead of text.

I anyone can assist I'd be very grateful!

asked Jul 30, 2014 at 20:01

1 Answer 1

2

Do this:

 <?php
 $multiSelectArray = $this->getProduct ()->getAttributeText('suitable_for');
 $lastItem = end ($multiSelectArray);
 foreach ($multiSelectArray as $multiSelectItem) :?>
 <img src="/media/img/<?php echo $multiSelectItem ?>"></img>
 <?php endforeach;
 ?>

and store your images in /media/img/[item].[ext], the same value as the text stored.

answered Jul 30, 2014 at 20:22
3
  • Nice approach. May be file extension (jpeg or similar) needed as well as basic file name validation. Commented Jul 30, 2014 at 20:53
  • Fantastic!!! Thankyou so much, I really appreciate your help... Commented Jul 30, 2014 at 20:53
  • good one!!!!!!! Commented Nov 11, 2018 at 15:24

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.