you can use it in the
_Productbox.cshmtl file you want to use.
var _pictureService = Nop.Core.Infrastructure.EngineContext.Current.Resolve<Nop.Services.Media.IPictureService>();
var pictures = await _pictureService.GetPicturesByProductIdAsync(Model.Id);
var defaultPicture = pictures.FirstOrDefault();
string fullSizeImageUrl, imageUrl, thumbImageUrl;
(imageUrl, defaultPicture) = await _pictureService.GetPictureUrlAsync(defaultPicture);
(fullSizeImageUrl, defaultPicture) = await _pictureService.GetPictureUrlAsync(defaultPicture, 0);
var defaultPictureModel = new PictureModel
{
ImageUrl = imageUrl,
FullSizeImageUrl = fullSizeImageUrl
};
you can limit the loop if you want.
@for (var i = 0; i < pictures.Count; i++)
{
var picture = pictures[i];
(imageUrl, picture) = await _pictureService.GetPictureUrlAsync(picture);
(fullSizeImageUrl, picture) = await _pictureService.GetPictureUrlAsync(picture);
(thumbImageUrl, picture) = await _pictureService.GetPictureUrlAsync(picture);
var pictureModel = new PictureModel
{
ImageUrl = imageUrl,
ThumbImageUrl = thumbImageUrl,
FullSizeImageUrl = fullSizeImageUrl,
};
<a class="thumb-item" href="@fullSizeImageUrl" alt="" title="">
<img src="@thumbImageUrl" data-defaultsize="@imageUrl" data-fullsize="@fullSizeImageUrl" />
</a>
}
in addition;
You can customize the view with these codes. standard build.
<link rel="stylesheet" href="~/lib_npm/magnific-popup/magnific-popup.css" />
<script asp-exclude-from-bundle="true" src="~/lib_npm/magnific-popup/jquery.magnific-popup.min.js" asp-location="Footer"></script>
<script asp-location="Footer">
$(document).ready(function () {
$('.picture-thumbs').magnificPopup(
{
type: 'image',
delegate: 'a',
removalDelay: 300,
gallery: {
enabled: true,
navigateByImgClick: true,
preload: [0, 1],
tPrev: '@T("Media.MagnificPopup.Previous")',
tNext: '@T("Media.MagnificPopup.Next")',
tCounter: '@T("Media.MagnificPopup.Counter")'
},
tClose: '@T("Media.MagnificPopup.Close")',
tLoading: '@T("Media.MagnificPopup.Loading")'
});
});
</script>
<script asp-location="Footer">
$(document).ready(function () {
$('.thumb-item > img').on('click',
function () {
$('#[email protected]').attr('src', $(this).attr('data-defaultsize'));
$('#[email protected]').attr('title', $(this).attr('title'));
$('#[email protected]').attr('alt', $(this).attr('alt'));
$('#[email protected]').attr('href', $(this).attr('data-fullsize'));
$('#[email protected]').attr('title', $(this).attr('title'));
});
});
</script>