Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • David Godfrey 14 posts 83 karma points
    Aug 08, 2017 @ 10:44
    David Godfrey
    0

    Product Option Content Types

    Hi All,

    I have been working on the AddTOBasketForm view in order to replace my dropdown lists with image selectors.

    I have the following code which works:

    @{
    var product = Merchello.TypedProductContent(Model.ProductKey);
    

    }

            foreach (var opt in product.Options)
            {
                <br/>
                @opt.Name.ToUpper();
                @Html.Raw("<div class=\"container\">")
    
                foreach (var choice1 in opt.Choices)
                    {
                    var image1 = choice1.GetPropertyValue("productImageSelector");
                    @Html.Raw(image1);
    
                    var umbracoHelper = new UmbracoHelper(UmbracoContext.Current);
                    var image = umbracoHelper.Media(image1); // mediaId =  the (int)ID of the media
    
                        <div class="col-md-2">
                            <div class="product-choice-selector">
                                <img src="@image.Url" onclick="javascript:selectDRP('@choice1.Key', @oindex)" data-imagezoom="true" class="img-responsive">
                                @choice1.Name
                            </div>
                        </div>
    

    Although this code works it will only work on one product at a time, I have a site made up of three products and I can only get the image to show on one of them.

    If i build the site it will then show on this product i view first. It will not work on any product if I am not in debug="true".

    Can anyone help with this I have no idea why this is happening?

    *I am using the starter kit.

    Thanks

    David

  • David Godfrey 14 posts 83 karma points
    Aug 18, 2017 @ 09:57
    David Godfrey
    0

    I have found a work around that does work, but I dont like it.

           // Generate the drop down boxes to select choices for each option
                            foreach (var option in product.ProductOptions)
                            {
    
                                var choices = option.Choices.OrderBy(x => x.SortOrder).Select(choice => new System.Web.Mvc.SelectListItem { Value = choice.Key.ToString(), Text = choice.Name }).ToList();
                                choices.First().Selected = true;
    
    
    
    
                                <br />
                                if (option.Name.ToLower() == "size")
                                {
    
                                    var oindex = 0;
                                    foreach (var choice in option.Choices)
                                    {
    
                                        if (@choice.DetachedDataValues.FirstOrDefault().Key == "productImageSelector")
                                        {
    
                                            string str = choice.DetachedDataValues.FirstOrDefault().Value;
    
                                            str = str.Substring(1, str.Length - 2);
    
                                            var umbracoHelper = new UmbracoHelper(UmbracoContext.Current);
                                            var image = umbracoHelper.Media(str); // mediaId =  the (int)ID of the media
    
                                            <div class="col-md-3 column">
                                                <div class='panel-widget'>
                                                    <a href="@Html.Raw(product.GetPropertyValue<string>("categorylink"))">
                                                        <div class="panel-body">
                                                            <h3>@choice.Name</h3>
                                                            <img src="@image.Url" data-imagezoom="true" class="img-responsive">
    
                                                        </div>
                                                </div>
                                                </div>
    
                                        }
                                        oindex = oindex + 1;
                                        if (oindex == 4)
                                        {
                                            break;
                                        }
                                    }
                                }
    
                            }
    

    Has anyone else experiences problems with getting the Product Option Content Types to show?

Please Sign in or register to post replies

Write your reply to:

Draft