Ok this little bit of coding will display a picture when a drop down is selected. This is not done automatically via ADMIN control. You will need to do manual labor basically double the work and setup each product you wish to have this feature.
By no means am I fully knowledgable of the inner workings of Zen-Cart/PHP/Java but I decided to post this to see if it gives anyone an idea on how to integrate it with zen-cart without being such a manual process.
This was tested on 1.38a on offline test server on IE7. No other mods were installed so I do not know how this will impact your site if you decide to enter the code. The good thing is all you need to do is delete the lines out of the template. Obvisously make sure you back the tpl_modules_attributes.php just in case.
Working directory : /includes/templates/YOUR_CUSTOM_FOLDER/templates
Templates to modify: tpl_modules_attributes.php
Step 1: Create the attribute option in Zen-Cart like normal and add all the drop down options to your product
Step 2: Open tpl_modules_attributes.php in your custom directory. After you see this line
<div class="wrapperAttribsOptions">
<h4 class="optionName back"><?php echo $options_name[$i]; ?></h4>
<div class="back"><?php echo "\n" . $options_menu[$i]; ?></div>
<br class="clearBoth" />
</div>
Insert this code:
<!--bof DROP DOWN SELECT -->
<?php
/*CHNGE THE $I==1 TO WHERE U WANT THE ATTRIBUTE. SO IF YOUR DROP DOWN IS YOUR 2ND ATTRIBUTE ON THE PRODUCTS PAGE, THIS SHOULD BE 2 IF YOUR DROP DOWN IS THE 3RD THIS SHOULD BE 3 ETC. JUST CLICK ON YOUR PRODUCT PAGE AND SEE WHAT POSITION THE ATTRIBUTE IS IN IF IT IS IN POSTION 1 then $i==0*/
if ($i == 1) {
/*CHNGE THE PRODUCT ID TO THE ID THAT YOU WANT THE DROP DOWN FOR*/
if (($_GET['products_id']) == 105) {
include 'PROD_105.php';/*THIS WILL BE THE PHP FILE WE WILL CALL FOR PRODUCT 105*/
}
}
?>
<!--eof END OF DROP DOWN SELECT -->
Step3: Open your editor and paste the attached code into it. Save it in /includes/templates/YOUR_CUSTOM_FOLDER/templates and name it the same name from the include statement above. In this case we will use PROD_105.php
<style type="text/css">
#attrib-2 {display: none;}; <!-- You will need the attribute for the dropdown created for the product number. Easiest way is to load the page in your browser, view source and scroll down to where the attribute is located. You should see a for="attrib-X" where x is the number. Just capture it and replace attrib-2 with whatever it is. Or you can got into PRODUCT OPTIONS in admin and see the ID number that is assigned to the option. This will hide the attribute box that was created in zen cart -->
</style>
<!-- this is the table that is used you may need to change size based on your needs -->
<table border="0" cellspacing="0" cellpadding="0" width="387">
<tr><td width="134">
<!--this calls the picture change function-->
<select name="picture" size="1" onChange="showimage()">
<option selected value="19">Red</option><!--you will need to do the same thing as you did above. Load the page, view source, find the values for the dropdown and update these selects with those values. Basically copy the option vaules between the select and paste over these option values-->
<option value="18">Green</option>
<option value="20">Blue</option>
</select>
</td>
<td width="253">
<!-- Now you need to set the directory where the pictures are stored. I selected includes/templates/custom/images/PROD_15 and created a different directory for each of the products. The graphic files are in that folder WITHOUT the extension. The files names point to the value that is selected. In IE7 the browser opens the image without the extension. I'm not sure if it works on other browsers-->
<align="center"><img src="includes/templates/custom/images/PROD_105/18 " name="pictures"> <!--this sets the first image to display. 18 is the name of the file I want to display first basically the default selection--></table>
<script type="text/javascript">
function showimage()
{
if (!document.images)
return
<!--change the attribute name below, attrib-2, to the name of the attribute you are working with this makes sure the option is added to the shopping cart-->
document.getElementById("attrib-2").value = cart_quantity.picture.options[document.cart_quantity.picture.selectedIndex].value;
<!--change the src to where you have the pictures stored for the download -->
document.images.pictures.src="includes/templates/custom/images/PROD_15/"+
document.cart_quantity.picture.options[document.cart_quantity.picture.selectedIndex].value
}
</script>
Now if you have other products you wish to do this with then follow the same process. When you set it once it is a matter of just copy and paste.
Hopefully someone can build on this and intergrate it with Zen-Cart directly to minimize the manual process. It is best to have the thumbnails all the same size so it doesnt disrupt the rest of the page.
Bookmarks