Skip to content

Commit

Permalink
#1933 Fixed default image display if product images are not set.
Browse files Browse the repository at this point in the history
  • Loading branch information
RomanovM committed Jun 22, 2022
1 parent c79cc17 commit d71e77d
Showing 1 changed file with 11 additions and 15 deletions.
26 changes: 11 additions & 15 deletions src/Presentation/Nop.Web/Factories/ProductModelFactory.cs
Expand Up @@ -628,20 +628,11 @@ protected virtual async Task<IList<PictureModel>> PrepareProductOverviewPictures

var cachedPictures = await _staticCacheManager.GetAsync(cacheKey, async () =>
{
var pictures = await _pictureService.GetPicturesByProductIdAsync(product.Id,
_catalogSettings.DisplayAllPicturesOnCatalogPages ? 0 : 1);
string fullSizeImageUrl, imageUrl;
//all pictures
var pictureModels = new List<PictureModel>();
for (var i = 0; i < pictures.Count; i++)
async Task<PictureModel> preparePictureModelAsync(Picture picture)
{
var picture = pictures[i];
(imageUrl, picture) = await _pictureService.GetPictureUrlAsync(picture, pictureSize);
(fullSizeImageUrl, picture) = await _pictureService.GetPictureUrlAsync(picture);
var pictureModel = new PictureModel
var (imageUrl, _) = await _pictureService.GetPictureUrlAsync(picture, pictureSize);
var (fullSizeImageUrl, _) = await _pictureService.GetPictureUrlAsync(picture);
return new PictureModel
{
ImageUrl = imageUrl,
FullSizeImageUrl = fullSizeImageUrl,
Expand All @@ -656,10 +647,15 @@ protected virtual async Task<IList<PictureModel>> PrepareProductOverviewPictures
: string.Format(await _localizationService.GetResourceAsync("Media.Product.ImageAlternateTextFormat"),
productName)
};
pictureModels.Add(pictureModel);
}
//all pictures
var pictures = (await _pictureService
.GetPicturesByProductIdAsync(product.Id, _catalogSettings.DisplayAllPicturesOnCatalogPages ? 0 : 1))
.DefaultIfEmpty(null);
var pictureModels = await pictures
.SelectAwait(async picture => await preparePictureModelAsync(picture))
.ToListAsync();
return pictureModels;
});

Expand Down

0 comments on commit d71e77d

Please sign in to comment.