private void MapProductVariantToProductVm(Product product, ProductDetail model) { var variations = productVariationRepository .Query() .Include(x => x.OptionCombinations).ThenInclude(o => o.Option) .Include(x => x.Product) .Where(x => x.ProductId == product.Id && !x.IsDeleted) .ToList(); foreach (var variation in variations) { var variationVm = new ProductDetailVariation { Id = variation.Id, Name = variation.Name, PriceOffset = variation.PriceOffset, Price = product.Price + variation.PriceOffset }; foreach (var combination in variation.OptionCombinations) { variationVm.Options.Add(new ProductDetailVariationOption { OptionId = combination.OptionId, OptionName = combination.Option.Name, Value = combination.Value }); } model.Variations.Add(variationVm); } }
private void MapProductVariantToProductVm(Product product, ProductDetail model) { var variations = _productRepository .Query() .Include(x => x.OptionCombinations).ThenInclude(o => o.Option) .Where(x => x.LinkedProductLinks.Any(link => link.ProductId == product.Id && link.LinkType == ProductLinkType.Super)) .Where(x => x.IsPublished) .ToList(); foreach (var variation in variations) { var variationVm = new ProductDetailVariation { Id = variation.Id, Name = variation.Name, NormalizedName = variation.NormalizedName, Price = variation.Price, OldPrice = variation.OldPrice }; var optionCombinations = variation.OptionCombinations.OrderBy(x => x.SortIndex); foreach (var combination in optionCombinations) { variationVm.Options.Add(new ProductDetailVariationOption { OptionId = combination.OptionId, OptionName = combination.Option.Name, Value = combination.Value }); } model.Variations.Add(variationVm); } }
private void MapProductVariantToProductVm(Product product, ProductDetail model) { if (!product.ProductLinks.Any(x => x.LinkType == ProductLinkType.Super)) { return; } var variations = _productRepository .Query() .Include(x => x.OptionCombinations).ThenInclude(o => o.Option) .Include(x => x.Medias).ThenInclude(m => m.Media) .Where(x => x.LinkedProductLinks.Any(link => link.ProductId == product.Id && link.LinkType == ProductLinkType.Super)) .Where(x => x.IsPublished) .ToList(); foreach (var variation in variations) { var variationVm = new ProductDetailVariation { Id = variation.Id, Name = variation.Name, NormalizedName = variation.NormalizedName, IsAllowToOrder = variation.IsAllowToOrder, IsCallForPricing = variation.IsCallForPricing, StockTrackingIsEnabled = variation.StockTrackingIsEnabled, StockQuantity = variation.StockQuantity, CalculatedProductPrice = _productPricingService.CalculateProductPrice(variation), Images = variation.Medias.Where(x => x.Media.MediaType == Core.Models.MediaType.Image).Select(productMedia => new MediaViewModel { Url = _mediaService.GetMediaUrl(productMedia.Media), ThumbnailUrl = _mediaService.GetThumbnailUrl(productMedia.Media) }).ToList() }; var optionCombinations = variation.OptionCombinations.OrderBy(x => x.SortIndex); foreach (var combination in optionCombinations) { variationVm.Options.Add(new ProductDetailVariationOption { OptionId = combination.OptionId, OptionName = combination.Option.Name, Value = combination.Value }); } model.Variations.Add(variationVm); } }
private void MapProductVariantToProductVm(Product product, ProductDetail model) { var variations = _productRepository .Query() .Include(x => x.OptionCombinations).ThenInclude(o => o.Option) .Where(x => x.LinkedProductLinks.Any(link => link.ProductId == product.Id && link.LinkType == ProductLinkType.Super)) .Where(x => x.IsPublished) .ToList(); foreach (var variation in variations) { var variationVm = new ProductDetailVariation { Id = variation.Id, Name = variation.Name, NormalizedName = variation.NormalizedName, IsAllowToOrder = variation.IsAllowToOrder, IsCallForPricing = variation.IsCallForPricing, StockTrackingIsEnabled = variation.StockTrackingIsEnabled, StockQuantity = variation.StockQuantity, CalculatedProductPrice = _productPricingService.CalculateProductPrice(variation) }; var optionCombinations = variation.OptionCombinations.OrderBy(x => x.SortIndex); foreach (var combination in optionCombinations) { variationVm.Options.Add(new ProductDetailVariationOption { OptionId = combination.OptionId, OptionName = combination.Option.Name, Value = combination.Value }); } model.Variations.Add(variationVm); } }