Portal Engine Questions on portal engine and web parts.
Version 7.x > Portal Engine > product option image View modes: 
User avatar
Member
Member
kArtemy - 11/6/2013 2:01:06 AM
   
product option image
Hello.

How can i display product option image by selecting item from my dropdown menu?, Can't find any samples

Best regards.

User avatar
Kentico Consulting
Kentico Consulting
Kentico_RichardS - 11/6/2013 3:54:52 AM
   
RE:product option image
Hi,

Thank you for your message.

Could you please more elabore on the issue? I'm not sure what you are trying to do. Also the product options are listed here -> http://devnet.kentico.com/docs/ecommerceguide/index.html?product_options.htm Do you want to show an image based on this product option in the transformation of product?

Also this is more of a html/javascript question so I would refer to something like: http://stackoverflow.com/questions/18110413/dropdown-menu-select-selecting-an-item-and-picture-shows-based-on-the-selec you can also have something like: http://stackoverflow.com/questions/9508029/dropdown-select-with-images

Kind regards,
Richard Sustek

User avatar
Member
Member
kArtemy - 11/6/2013 6:44:26 AM
   
RE:product option image
Thank you for answer,

i'm trying to do something like that:
http://www.slopeseeker.com/t-shirts-and-hoodies
http://www.dlyarebenka.ru/products/5701590-emmaljunga-scooter-2010.aspx

Was sure i able to do this with default kits by adding product option image and somehow display it on my datalist. But now it looks impossible for me, since i dont know how to integrate js.

Anyway thank you for answer!

Best Regards

User avatar
Certified Developer 10
Certified Developer 10
josha-bpstudios - 11/6/2013 1:31:48 PM
   
RE:product option image
Below is code that was posted in another forum previously. I only modified it to change the image onmouseover. Here is the code that willl allow this to happen. One thing to note is that this code goes in the file /CMSModules/Ecommerce/Controls/ProductOptions/ProductOptionSelector.ascx.cs file under the method loadselector(). Place it right before the comment //WAI validation. (you can place in other places, but this is where I verified that it works)

Also, the code below will only change the options that are in the horizontal radio button list. You can change this by changing the switch statement or adding other cases with the same code, just choose a different enum type.
 //Added
switch (this.OptionCategory.CategorySelectionType)
{
case OptionCategorySelectionTypeEnum.RadioButtonsHorizontal:

LocalizedRadioButtonList boxListHorizontal = (LocalizedRadioButtonList)this.SelectionControl;
foreach (ListItem item in boxListHorizontal.Items)
{
if (item != null)
{
SKUInfo sku = SKUInfoProvider.GetSKUInfo(ValidationHelper.GetInteger(item.Value, 0));

if (sku != null && !string.IsNullOrEmpty(sku.SKUImagePath))
{
item.Text += " <div class=\"OptionImage\"><img alt=\"" + sku.SKUName + "\" src=\"" + URLHelper.ResolveUrl(sku.SKUImagePath) + "\" width=\"50\" height=\"50\" /></div>";
//Set for the onclick event- Changes the "MainProductImage" to whichever image was clicked.
item.Attributes.Add("onclick", "jQuery('.fancyboxProductImg').html('<img alt=\"" + sku.SKUName + "\" src=\"" + URLHelper.ResolveUrl(sku.SKUImagePath) + "\" width=\"240\" height=\"240\" />')");
//Added for the onmouseover event, when a customer hovers over the image, it will perform the same action as above.
item.Attributes.Add("onmouseover", "jQuery('.fancyboxProductImg').html('<img alt=\"" + sku.SKUName + "\" src=\"" + URLHelper.ResolveUrl(sku.SKUImagePath) + "\" width=\"240\" height=\"240\" />')");
}
}
}
break;
}
//End Added

User avatar
Member
Member
kArtemy - 11/6/2013 3:40:39 PM
   
RE:product option image
Thanks alot for your answer!

I'm new in kentico and not sure about properly, but after these moves i'm getting next error message in productoptions:
Line 79: case OptionCategorySelectionTypeEnum.RadioButtonsHorizontal:
Line 80:
Line 81: LocalizedRadioButtonList boxListHorizontal = (LocalizedRadioButtonList)this.SelectionControl;
Line 82: foreach (ListItem item in boxListHorizontal.Items)
Line 83: {

Source File: ~KenticoCMS7\CMSModules\Ecommerce\Controls\ProductOptions\ProductOptionSelector.ascx.cs Line: 81

something wrong with LocalizedRadioButtonList

User avatar
Certified Developer 10
Certified Developer 10
josha-bpstudios - 11/6/2013 3:45:16 PM
   
RE:product option image
What is the error message saying? The localizedradiobuttonlist should be a member of the class CMS.ExtendedControls. So make sure that at the top of the productoptions file that you have the using statement. Also make sure you have the globalhelper reference. Insert these two lines in the top of the same file.
using CMS.ExtendedControls;
using CMS.GlobalHelper;

User avatar
Member
Member
kArtemy - 11/6/2013 4:05:25 PM
   
RE:product option image
Thanks! had no using CMS.ExtendedControls;

But main product image still didn't change after choosing one of options

User avatar
Certified Developer 10
Certified Developer 10
josha-bpstudios - 11/6/2013 5:41:45 PM
   
RE:product option image
I guess the only other thing could be JQuery loading. Try to run firebug or another javascript debugger and see if you get any errors, or maybe view your page source and see if there is any JQuery being loaded, if not, then place a script tag with the file location pointing to the latest JQuery library in the header of the page.

User avatar
Member
Member
kArtemy - 11/6/2013 11:54:07 PM
   
RE:product option image
Thanks alot! Working perfect!

Best regards

User avatar
Member
Member
kArtemy - 11/13/2013 1:48:02 PM
   
RE:product option image
Sorry again, but i'm getting another problem.
Your code working perfect with checkboxes/radiobuttons, but i can't adapt it for dropdownlist
did something like that, but actually i have no idea what am i doing:
switch (this.OptionCategory.CategorySelectionType)
{
case OptionCategorySelectionTypeEnum.Dropdownlist:

LocalizedDropDownList dropDown = (LocalizedDropDownList)this.SelectionControl;
foreach (ListItem item in dropDown.Items)
{
if (item != null)
{
SKUInfo sku = SKUInfoProvider.GetSKUInfo(ValidationHelper.GetInteger(item.Value, 0));

if (sku != null && !string.IsNullOrEmpty(sku.SKUImagePath))
{

item.Attributes.Add("onclick", "jQuery('.fancyboxProductImg').html('<img alt=\"" + sku.SKUName + "\" src=\"" + URLHelper.ResolveUrl(sku.SKUImagePath) + "\" width=\"240\" height=\"240\" />')");

}
}
}
break;
}

Getting no errors but no image as well

User avatar
Certified Developer 10
Certified Developer 10
josha-bpstudios - 11/13/2013 1:53:10 PM
   
RE:product option image
Check to make sure that the product options are in the dropdown list layout and attached to the product that you are trying to view and also clear your site cache. My guess is that you do not have the options connected to the product or that the options aren't specified to display in a dropdownlist. To clear the cache, go to sitemanager and click the administration tab. Click system and then restart the application, or clear the cache.

User avatar
Member
Member
kArtemy - 11/13/2013 3:04:58 PM
   
RE:product option image
Thank you for your answer,

Cleared my cache and still same thing, with options everything looks fine.
i'm sure something wrong with my code above

Best regards

User avatar
Certified Developer 10
Certified Developer 10
josha-bpstudios - 11/13/2013 5:39:41 PM
   
RE:product option image
I will drop that same code into a test site and let you know.

User avatar
Certified Developer 10
Certified Developer 10
josha-bpstudios - 11/13/2013 7:54:00 PM
   
RE:product option image
The problem is that you didn't include all of the code. There is no item to attach the onclick event to. You are missing the actual image.

This code brings the image in and sets the src tag to the url of the product image
item.Text += " <div class=\"OptionImage\"><img alt=\"" + sku.SKUName + "\" src=\"" + URLHelper.ResolveUrl(sku.SKUImagePath) + "\" width=\"50\" height=\"50\" /></div>";

The code that you have in the snippet only attaches an onclick event to change the main picture to the options picture.

User avatar
Member
Member
kArtemy - 11/14/2013 1:40:42 AM
   
RE:product option image
With this code im getting next:
User image


Mean, i dont need attach image to options in ddmenu, i need to change my main product option image on click and its working perfect with horizontal/vertical radio buttons:

switch (this.OptionCategory.CategorySelectionType)
{
case OptionCategorySelectionTypeEnum.RadioButtonsHorizontal:

LocalizedRadioButtonList boxListHorizontal = (LocalizedRadioButtonList)this.SelectionControl;
foreach (ListItem item in boxListHorizontal.Items)
{
if (item != null)
{
SKUInfo sku = SKUInfoProvider.GetSKUInfo(ValidationHelper.GetInteger(item.Value, 0));

if (sku != null && !string.IsNullOrEmpty(sku.SKUImagePath))
{
item.Attributes.Add("onclick", "jQuery('.fancyboxProductImg').html('<img alt=\"" + sku.SKUName + "\" src=\"" + URLHelper.ResolveUrl(sku.SKUImagePath) + "\" width=\"240\" height=\"240\" />')");
}
}
}
break;
}


User avatar
Member
Member
kArtemy - 11/14/2013 1:41:23 AM
   
RE:product option image
* http://www.image-share.com/ipng-2338-206.html

User avatar
Certified Developer 10
Certified Developer 10
josha-bpstudios - 11/14/2013 10:03:03 AM
   
RE:product option image
You will have to step through the code and see what is happening. Try stepping through the code of the productoptionselector and make sure everything is coming in. Then make sure that you aren't getting any javascript errors. I am not sure exactly what you want, so all I can recommend is that you step through the code and see what it is doing. Modifications should be minimal if any.

User avatar
Member
Member
kArtemy - 11/16/2013 10:26:43 AM
   
RE:product option image
Hello, thank your for your answer,

Tried to do that step by step, but still didn't get any errors or something,

item.Text += ... working properly but onclick method didn't bring any changes however working with other button types

All i want to do is change my main product image on that one, which i added in product option in ecomerce by choosing option from dropdown menu.

User avatar
Member
Member
kArtemy - 2/12/2014 4:35:44 AM
   
RE:product option image
Hello,
I finally found the problem, the problem is that we are binding event to the <option> instead of binding it to the <select> element, thats why same code not working with dropdown list. Looks like i found what i need, but still got some issues in adapt, here is sample:

drp.Items.Add(new ListItem("Ladies T-shirt", "1"));
drp.Items.Add(new ListItem("Mens T-shirt", "2"));
string script = @"
function changeImg(drp)
{
var item = drp.value;
switch(item)
{
";
foreach (ListItem item in drp.Items)
{
script += "case '" + item.Value + "': jQuery('.fancyboxProductImg').html('<img alt=\"" + sku.SKUName + "\" src=\"" + URLHelper.ResolveUrl(sku.SKUImagePath) + "\" width=\"240\" height=\"240\" />');break;";

}

script += "}}";

ScriptHelper.RegisterClientScriptBlock(this, typeof(string), "myscript", script, true);
drp.Attributes.Add("onchange", "changeImg(this);");

But im a bit confused, what should be here instead of
drp.Items.Add(new ListItem
to get this list from productoptions

Best regards