Ejemplo n.º 1
0
        protected virtual async Task <List <ProductMainImage> > GetImagesAsync(IEnumerable <ProductWithVariant> products)
        {
            var imageRequests = products.Select(identifier =>
            {
                var imageRequest = new ProductImageRequest
                {
                    ProductId = identifier.Product.Id,
                    Variant   = identifier.Variant == null ? VariantKey.Empty : new VariantKey
                    {
                        Id = identifier.Variant.Id,
                        KeyVariantAttributeValues = identifier.Variant.PropertyBag
                    },
                    ProductDefinitionName = identifier.Product.DefinitionName
                };

                var imageUrl = DamProvider.GetMediaImageUrl(identifier.Product, identifier.Variant?.Id);
                if (imageUrl != null)
                {
                    imageRequest.PropertyBag = new Dictionary <string, object> {
                        ["ImageUrl"] = imageUrl
                    };
                }
                return(imageRequest);
            }).ToList();

            var imageRequestParam = new GetProductMainImagesParam
            {
                ImageSize            = ProductConfiguration.ProductSummaryImageSize,
                ProductImageRequests = imageRequests
            };

            var mainImages = await DamProvider.GetProductMainImagesAsync(imageRequestParam).ConfigureAwait(false);

            return(mainImages);
        }
Ejemplo n.º 2
0
        protected virtual GetProductMainImagesParam GetImagesParam(IEnumerable <ProductWithVariant> products)
        {
            var imageRequests = products.Select(identifier =>
            {
                var imageRequest = new ProductImageRequest
                {
                    ProductId = identifier.Product.Id,
                    Variant   = identifier.Variant == null ? VariantKey.Empty : new VariantKey
                    {
                        Id = identifier.Variant.Id,
                        KeyVariantAttributeValues = identifier.Variant.PropertyBag
                    },
                    ProductDefinitionName = identifier.Product.DefinitionName
                };

                identifier.Product.PropertyBag.TryGetValue("ImageUrl", out var imageUrlProperty);
                var imageUrl = imageUrlProperty?.ToString() ?? DamProvider.GetMediaImageUrl(identifier.Product, identifier.Variant?.Id);

                if (imageUrl != null)
                {
                    imageRequest.PropertyBag = new Dictionary <string, object> {
                        ["ImageUrl"] = imageUrl
                    };
                }
                return(imageRequest);
            }).ToList();

            return(new GetProductMainImagesParam
            {
                ImageSize = ProductConfiguration.ThumbnailImageSize,
                ProductImageRequests = imageRequests
            });
        }