Need help with ProductOptionCollection or ProductVariantColl

For general questions and discussions specific to the AbleCommerce 7.0 Asp.Net product.
Post Reply
cswebtech
Ensign (ENS)
Ensign (ENS)
Posts: 13
Joined: Wed Aug 12, 2009 11:10 am

Need help with ProductOptionCollection or ProductVariantColl

Post by cswebtech » Wed Sep 09, 2009 7:09 am

Hi,
I need help using the ProductOptionCollection or the ProductVariantCollection. is there any documentation on these? I need to figure out where the images are stored for the product options. I want to collect the URLS for the option images to be able to display them on my product page without using the 'swatches' feature. I'm trying to write a ConLib that will just display the option images below all of the product information. But I can't figure out how to get the images from the Product.

This is the start of the code I'm working with.... I'm new to this so I didn't know where to look for documentation:

Code: Select all

public partial class ConLib_OptionImages : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        DataTable dt = new DataTable();
        dt.Columns.Add("ImagePath", typeof(String));
        int _ProductId = AlwaysConvert.ToInt(Request.QueryString["ProductId"]);
        Product _Product = ProductDataSource.Load(_ProductId);
        if (_Product != null)
        {
	 

            ProductImageCollection images = _Product.Images;
            dt.Rows.Add(new Object[] { AlwaysConvert.ToString(_Product.ImageUrl) });
            foreach (ProductImage theimage in images)
            {
                dt.Rows.Add(new Object[] { AlwaysConvert.ToString(theimage.ImageUrl) });
            }


	    ProductOptionCollection productOptions = _Product.ProductOptions;
            int optionCount = productOptions.Count;
            for (int i = 0; i < optionCount; i++)
            {
               

		if (!string.IsNullOrEmpty(productOptions[i].ImageUrl))
                {
                     dt.Rows.Add(new Object[] { AlwaysConvert.ToString(productOptions[i].ImageUrl) });

                }


             }

            ImageList.DataSource = dt;
            ImageList.DataBind();

 
        }
    }
}
But it gives me an error...saying 'CommerceBuilder.Products.ProductOption' does not contain a definition for 'ImageUrl'

How do I get from the ProductOption down to the individual images set for the different options?

Any help would be greatly appreciated!! Thanks!
Rhonda

cswebtech
Ensign (ENS)
Ensign (ENS)
Posts: 13
Joined: Wed Aug 12, 2009 11:10 am

Re: Need help with ProductOptionCollection or ProductVariantColl

Post by cswebtech » Wed Sep 09, 2009 8:14 am

Well I discovered how to add the OptionPicker to my new ConLib and get it to display that. However it is using the swatch URLS and I want it to use the Image URLS instead. How do I do that?

Also, how do I set the image size? It is setting the images as the background of the table. I want it to put the images in the table and be able to set the size of the image. (Hardcoding it is fine!) My images are huge and I can't go back and make smaller images. Have too many products/vaiants to do this on.

Where do I find the code for the display of the OptionPicker?

Here is my code for my ConLib called OptionImages:

Code: Select all

public partial class ConLib_OptionImages : System.Web.UI.UserControl
{

  Dictionary<int, int> _SelectedOptions = null;

    protected void Page_Load(object sender, EventArgs e)
    {
        DataTable dt = new DataTable();
        dt.Columns.Add("ImagePath", typeof(String));
        int _ProductId = AlwaysConvert.ToInt(Request.QueryString["ProductId"]);
        Product _Product = ProductDataSource.Load(_ProductId);
        if (_Product != null)
        {
	 

           

	    HttpRequest request = HttpContext.Current.Request;
	    Dictionary<int, int> selectedChoices = new Dictionary<int, int>();
	    ProductOptionCollection productOptions = _Product.ProductOptions;
            int optionCount = productOptions.Count;

           

            for (int i = 0; i < optionCount; i++)
            {
               Option option = productOptions[i].Option;

                   // CREATE THE OPTION PICKER CONTROL TO THE PLACEHOLDER
                    OptionPicker picker = new OptionPicker();
                    picker.ID = "option" + i;
                    picker.CssClass = "optionPicker";
                    // WE ALWAYS HAVE TO POSTBACK FOR THUMBNAIL PICKER
                    picker.AutoPostBack = true;
                    picker.OptionId = option.OptionId;
                    picker.SelectedChoices = new Dictionary<int, int>(selectedChoices);
                    // ADD THE CONTROL TO THE PLACEHOLDER
                    phImageOptions.Controls.Add(picker);
                    //CHECK WHETHER AN OPTION IS SELECTED
                    string selectedValue = request.Form[picker.UniqueID];
                    if (!string.IsNullOrEmpty(selectedValue))
                    {
                        picker.SelectedChoiceId = AlwaysConvert.ToInt(selectedValue);
                        if (picker.SelectedChoiceId != 0) selectedChoices.Add(option.OptionId, picker.SelectedChoiceId);
                    }

		

             }
           

        }
    }
}
Thanks for any help!!
Rhonda

Post Reply