Product Image in Downloadable Products

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
12 anni tempo fa
Hello Friends

Can someone please tell me how I can get the product image to show inside the Downloadable Products Page :(

I know the model needs changing, and I have changed it to the following:

namespace Nop.Web.Models.Customer
{
    public class CustomerDownloadableProductsModel : BaseNopModel
    {
        public CustomerDownloadableProductsModel()
        {
            Items = new List<DownloadableProductsModel>();
        }

        public IList<DownloadableProductsModel> Items { get; set; }
        public CustomerNavigationModel NavigationModel { get; set; }

        #region Nested classes
        public class DownloadableProductsModel : BaseNopModel
        {
            public DownloadableProductsModel()
            {
                DefaultPictureModel = new PictureModel();
            }
            public Guid OrderProductVariantGuid { get; set; }

            public int OrderId { get; set; }

            public int ProductId { get; set; }
            public string ProductName { get; set; }
            public string ProductSeName { get; set; }
            public PictureModel DefaultPictureModel { get; set; }
            public string ProductAttributes { get; set; }

            public int DownloadId { get; set; }
            public int LicenseId { get; set; }

            public DateTime CreatedOn { get; set; }
        }
        #endregion
    }

    public class UserAgreementModel : BaseNopModel
    {
        public Guid OrderProductVariantGuid { get; set; }
        public string UserAgreementText { get; set; }
    }
}


As you can see, I have added the PictureModel in there, hoping that I would be able to extract the product image for each product, but in Razor view, it returns blank, instead of the product image URL ! What am I doing wrong ?

Would greatly appreciate any help.

Thank You.
12 anni tempo fa
anyone ?
12 anni tempo fa
Ciwan wrote:
anyone ?


First thing I would check is if you correctly mapped the product image model inside of the controller (just adding members on a view model won't automatically map the domain members).

You're going to need to add code inside of your controller that looks similar to the code I provided below. I took this code from ShoppingCartController at approximately line 344.


//picture
if (_shoppingCartSettings.ShowProductImagesOnShoppingCart)
{
    var picture = _pictureService.GetPictureById(sci.ProductVariant.PictureId);
    if (picture == null)
    {
        picture = _pictureService.GetPicturesByProductId(sci.ProductVariant.Product.Id, 1).FirstOrDefault();
    }
    cartItemModel.Picture = new PictureModel() // This is the section you need.
   {
      ImageUrl = _pictureService.GetPictureUrl(picture, _mediaSetting.CartThumbPictureSize, true),
      Title = string.Format(_localizationService.GetResource("Media.Product.ImageLinkTitleFormat"), cartItemModel.ProductName),
      AlternateText = string.Format(_localizationService.GetResource("Media.Product.ImageAlternateTextFormat"), cartItemModel.ProductName),

     };
}


edit Don't forget to add IPictureService to the controller constructor if it doesn't already exist.
12 anni tempo fa
Thanks Sky. You're an awesome help in this community. :)
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.