1
Vote

Catalog Control for products without image exception

description

Hi!
I find one issue in your Catalog control:
For example, I create new product, and no set Image tor this product.
Then I set some category for this product and open this category ( using CommerceHome/categorylist.aspx).
In this way, I find this category Empty.

The source problem is in the Catalog control BindProductList function:

void BindProductList()
    {
        try
        {
            dtProducts.DataSource = ds.Tables[4];

            foreach (DataRow dr in ds.Tables[4].Rows)
            {
               int mediaId = int.Parse(dr["imageFile"].ToString());
               dr["imageFile"] = new Media(mediaId).getProperty("umbracoFile").Value.ToString();
            }

            dtProducts.DataBind();
        }
        catch
        {
            // set safe display
        }

    }
If product have no image, dr["imageFile"].ToString() return empty string and int.Parse(dr["imageFile"].ToString()); return exception.
So I just add check of Empty string:

foreach (DataRow dr in ds.Tables[4].Rows)
            {
                if (dr["imageFile"].ToString() != String.Empty){
                    int mediaId = int.Parse(dr["imageFile"].ToString());
                    dr["imageFile"] = new Media(mediaId).getProperty("umbracoFile").Value.ToString();
                }
            }
After it, all work fine. Catalog control show all products ( but some of them without image)

Also we can set default image for products without image in some config and if product have no image, apply this image.

Hope it helps.

comments