protected virtual AllProductImages CreateAllProductImages(GetAllProductImagesParam param, string variantId, int sequenceNumber)
 {
     return(new AllProductImages
     {
         ImageUrl = GetImageUrl(param.ImageSize, param.ProductId, variantId, sequenceNumber),
         ThumbnailUrl = GetImageUrl(param.ThumbnailImageSize, param.ProductId, variantId, sequenceNumber),
         // If support for XL images is disabled put "null" in the ProductZoomImageUrl property.
         ProductZoomImageUrl = IsProductZoomImageEnabled ? GetImageUrl(param.ProductZoomImageSize, param.ProductId, variantId, sequenceNumber) : null,
         ProductId = param.ProductId,
         VariantId = variantId,
         SequenceNumber = sequenceNumber,
         FallbackImageUrl = GetFallbackImageUrl()
     });
 }
        protected virtual List <AllProductImages> GetAllProductLocalImages(GetAllProductImagesParam param)
        {
            var result = new List <AllProductImages>();

            for (var sequenceNumber = 0; sequenceNumber < ConventionBasedDamProviderConfiguration.MaxThumbnailImages; sequenceNumber++)
            {
                result.Add(CreateAllProductImages(param, null, sequenceNumber));

                if (param.Variants != null)
                {
                    result.AddRange(param.Variants.Select(variantKey => CreateAllProductImages(param, variantKey.Id, sequenceNumber)));
                }
            }
            return(result);
        }
        protected virtual List <AllProductImages> GetAllProductMediaImages(GetAllProductImagesParam param)
        {
            var globalMediaSet = FilterImages(param.MediaSet) ?? new List <ProductMedia>()
            {
                null
            };
            var result = globalMediaSet.Select(productMedia => CreateAllProductImages(productMedia, _productMediaSettings, param, null)).ToList();

            if (param.Variants != null)
            {
                foreach (Variant variant in param.Variants)
                {
                    var variantMediaSet = GetVariantMediaSet(param.VariantMediaSet, variant);
                    var mediaSet        = variantMediaSet.Any() ? variantMediaSet : globalMediaSet;
                    result.AddRange(mediaSet.Select(productMedia => CreateAllProductImages(productMedia, _productMediaSettings, param, variant.Id)));
                }
            }
            return(result);
        }
        public virtual async Task <List <AllProductImages> > GetAllProductImagesAsync(GetAllProductImagesParam param)
        {
            if (param == null)
            {
                throw new ArgumentNullException("param", "The method parameter is required.");
            }
            if (string.IsNullOrWhiteSpace(param.ImageSize))
            {
                throw new ArgumentException("The image size is required.");
            }
            if (string.IsNullOrWhiteSpace(param.ThumbnailImageSize))
            {
                throw new ArgumentException("The thumbnail image size is required.");
            }
            if (string.IsNullOrWhiteSpace(param.ProductZoomImageSize))
            {
                throw new ArgumentException("The product zoom image size is required.");
            }
            if (string.IsNullOrWhiteSpace(param.ProductId))
            {
                throw new ArgumentException("The product id is required.");
            }

            _productMediaSettings = await ProductMediaSettingsRepository.GetProductMediaSettings().ConfigureAwait(false);

            if (IsProductHaveMedia(param.MediaSet, param.VariantMediaSet, param.Variants))
            {
                return(GetAllProductMediaImages(param));
            }

            return(GetAllProductLocalImages(param));
        }
 protected virtual AllProductImages CreateAllProductImages(ProductMedia productMedia, MediaSettings mediaSettings, GetAllProductImagesParam param, string variantId)
 {
     return(new AllProductImages
     {
         ImageUrl = productMedia != null?GetSizedImageUrl(productMedia, mediaSettings, param.ImageSize) : "",
                        ThumbnailUrl = productMedia != null?GetSizedImageUrl(productMedia, mediaSettings, param.ThumbnailImageSize) : "",
                                           ProductZoomImageUrl = productMedia != null?GetSizedImageUrl(productMedia, mediaSettings, param.ProductZoomImageSize) : "",
                                                                     ProductId = param.ProductId,
                                                                     VariantId = variantId,
                                                                     SequenceNumber = productMedia?.Position ?? 0,
                                                                     FallbackImageUrl = GetFallbackImageUrl(),
                                                                     Alt = productMedia?.Title,
     });
 }
        public virtual async Task <List <AllProductImages> > GetAllProductImagesAsync(GetAllProductImagesParam param)
        {
            if (param == null)
            {
                throw new ArgumentNullException(nameof(param));
            }
            if (string.IsNullOrWhiteSpace(param.ImageSize))
            {
                throw new ArgumentException(GetMessageOfNullWhiteSpace(nameof(param.ImageSize)), nameof(param));
            }
            if (string.IsNullOrWhiteSpace(param.ThumbnailImageSize))
            {
                throw new ArgumentException(GetMessageOfNullWhiteSpace(nameof(param.ThumbnailImageSize)), nameof(param));
            }
            if (string.IsNullOrWhiteSpace(param.ProductZoomImageSize))
            {
                throw new ArgumentException(GetMessageOfNullWhiteSpace(nameof(param.ProductZoomImageSize)), nameof(param));
            }
            if (string.IsNullOrWhiteSpace(param.ProductId))
            {
                throw new ArgumentException(GetMessageOfNullWhiteSpace(nameof(param.ProductId)), nameof(param));
            }

            _productMediaSettings = await ProductMediaSettingsRepository.GetProductMediaSettings().ConfigureAwait(false);

            if (IsProductHaveMedia(param.MediaSet, param.VariantMediaSet, param.Variants))
            {
                return(GetAllProductMediaImages(param));
            }

            return(GetAllProductLocalImages(param));
        }