Copied to clipboard

Flag this post as spam?

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


  • Nguyen Dung Tri 106 posts 606 karma points
    May 16, 2019 @ 15:11
    Nguyen Dung Tri
    0

    Merchello 2.7.1 cannot load product's image on home page

    Hi all,

    I have downloaded Merchello from github and start Merchello.FastTrack.Ui. But when the website is loading it generated an error:

    1. File: Merchello\src\Merchello.FastTrack.Ui\Views\Shared_ProductBox.cshtml
    2. Line: 10 Exception: System.ArgumentNullException: 'Value cannot be null.
    3. Detail:
      var images = Model.GetPropertyValue<List<IPublishedContent>>("image");images return null and images.Any() will generate exception.
    4. Version: Merchello 2.7.1

    Load product's images exception

    Because the product's cannot beloaded, then the home page cannot show the products.

    enter image description here

    Note: When I view the products from admin side, the product's images are available.

  • Nguyen Dung Tri 106 posts 606 karma points
    May 18, 2019 @ 01:44
    Nguyen Dung Tri
    100

    Here is my solution with a custom function:

    /// <summary>
        /// Get product image from IProductContent Model
        /// </summary>
        /// <param name="iProductContent">This model is provided by view file when it call to view product image</param>
        /// <example>_ProductBox.cshtml</example>
        /// <returns></returns>
        public static System.Collections.Generic.List<string> GetProductImageFromModel(Merchello.Web.Models.VirtualContent.IProductContent iProductContent)
        {
            System.Collections.Generic.List<string> images = new System.Collections.Generic.List<string>();
            var properties = iProductContent.Properties;
            foreach (var pro in properties)
            {
                if (pro.PropertyTypeAlias == "image")
                {
                    var id = pro.DataValue;
                    var umbHelper = new Umbraco.Web.UmbracoHelper(Umbraco.Web.UmbracoContext.Current);
                    var content = umbHelper.Media(id);
                    images.Add(content.Url);
                }
            }
            return images;
        }
    

    Somehow Model.GetPropertyValue<List<IPublishedContent>> doesn't work. So I have to look into its property value and try to take image Id to find image url.

Please Sign in or register to post replies

Write your reply to:

Draft