public virtual FashionProductViewModel Create(FashionProduct currentContent, string variationCode) { var variants = GetVariants(currentContent).ToList(); FashionVariant variant; if (!TryGetFashionVariant(variants, variationCode, out variant)) { return(new FashionProductViewModel { Product = currentContent, Images = currentContent.GetAssets <IContentImage>(_contentLoader, _urlResolver) }); } var market = _currentMarket.GetCurrentMarket(); var currency = _currencyservice.GetCurrentCurrency(); var defaultPrice = GetDefaultPrice(variant.Code, market, currency); var discountedPrice = GetDiscountPrice(defaultPrice, market, currency); var viewModel = new FashionProductViewModel { Product = currentContent, Variant = variant, ListingPrice = defaultPrice != null ? defaultPrice.UnitPrice : new Money(0, currency), DiscountedPrice = discountedPrice, Colors = variants .Where(x => x.Size != null) .GroupBy(x => x.Color) .Select(g => new SelectListItem { Selected = false, Text = g.Key, Value = g.Key }) .ToList(), Sizes = variants .Where(x => x.Color != null && x.Color.Equals(variant.Color, StringComparison.OrdinalIgnoreCase)) .Select(x => new SelectListItem { Selected = false, Text = x.Size, Value = x.Size }) .ToList(), Color = variant.Color, Size = variant.Size, Images = variant.GetAssets <IContentImage>(_contentLoader, _urlResolver), IsAvailable = defaultPrice != null }; return(viewModel); }
public virtual FashionProductViewModel Create(FashionProduct currentContent, string variationCode) { var variants = _catalogContentService.GetVariants<FashionVariant>(currentContent).ToList(); FashionVariant variant; if (!TryGetFashionVariant(variants, variationCode, out variant)) { return new FashionProductViewModel { Product = currentContent, Images = currentContent.GetAssets<IContentImage>(_contentLoader, _urlResolver) }; } variationCode = variant.Code; var defaultPrice = _pricingService.GetDefaultPrice(variationCode); var discountedPrice = defaultPrice != null ? _pricingService.GetDiscountPrice(variationCode).UnitPrice : (Money?)null; return new FashionProductViewModel { Product = currentContent, Variant = variant, ListingPrice = defaultPrice?.UnitPrice ?? _pricingService.GetMoney(0), DiscountedPrice = discountedPrice, Colors = variants .Where(x => x.Size != null) .GroupBy(x => x.Color) .Select(g => new SelectListItem { Selected = false, Text = g.Key, Value = g.Key }) .ToList(), Sizes = variants .Where(x => x.Color != null && x.Color.Equals(variant.Color, StringComparison.OrdinalIgnoreCase)) .Select(x => new SelectListItem { Selected = false, Text = x.Size, Value = x.Size }) .ToList(), Color = variant.Color, Size = variant.Size, Images = variant.GetAssets<IContentImage>(_contentLoader, _urlResolver), Videos = variant.GetVideos<Screen9Media>(_contentLoader, _urlResolver), IsAvailable = defaultPrice != null }; }