0

I made a new Product Dropdown Attribute that will show on a Group Product Page.

My idea:

<?php IF echo $this->htmlEscape($_item->getAttributeText('etickettype')) = 'GREEN'?> <img src="/Picture-GREEN.jpg"> <?php IF echo $this->htmlEscape($_item->getAttributeText('etickettype')) = 'RED'?> <img src="/Picture-RED.jpg"> <?php IF echo $this->htmlEscape($_item->getAttributeText('etickettype')) = 'BLUE'?> <img src="/Picture-BLUE.jpg"> <?php endif; ?> 

I know this code is not the correct, but does anyone know how I can find or explain the correct code?

2
  • Should be if($this->htmlEscape($_item->getAttributeText('etickettype')) == this->__('GREEN')) Commented Sep 11, 2014 at 16:17
  • it works! But easyer then i mean, here is the working code ;-) <img src="/media/wysiwyg/tickettype/<?php echo $this->htmlEscape($_item->getAttributeText('etickettype')) ?>.jpg" /> Thanks for all. Commented Sep 12, 2014 at 5:49

2 Answers 2

3

I'd use a switch statement instead like this.

<?php switch ($this->htmlEscape($_item->getAttributeText('etickettype')) { case 'GREEN': $color="GREEN"; break; case 'RED': $color="RED"; break; case 'BLUE': $color="BLUE"; break; default: $color="NA"; break; } ?> <img src="/Picture-<?php echo $color;?>.jpg" /> 

Although also I'd say you probably need to figure out what exactly you are doing in the end because even that doesn't seem to be the Magento way but I'm not sure what you are trying to accomplish overall.

Also if the attribute text is always going to be the same you could just spit out that instead like this:

<img src="/Picture-<?php echo $this->htmlEscape($_item->getAttributeText('etickettype');?>.jpg" /> 
0

First try to find a product naming conversion

E.g

{product name}-{color}.jpg {product sku}-{color}.jpg 

Assuming that every product attribute has an image

<img src="/<?php echo $product->getName() . '-' . $this->htmlEscape($_item->getAttributeText('etickettype'))?>.jpg"> 

No need to do a if or case statement, if the image may not exist see Check if file exists before displaying in Magento PHP?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.