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), IsAvailable = defaultPrice != null }); }
public virtual MiniCartViewModel CreateMiniCartViewModel(ICart cart) { if (cart == null) { return(new MiniCartViewModel { ItemCount = 0, CheckoutPage = _contentLoader.Get <StartPage>(ContentReference.StartPage).CheckoutPage, Shipments = Enumerable.Empty <ShipmentViewModel>(), Total = _pricingService.GetMoney(0) }); } return(new MiniCartViewModel { ItemCount = GetCartLineItems(cart).Sum(x => x.Quantity), CheckoutPage = _contentLoader.Get <StartPage>(ContentReference.StartPage).CheckoutPage, Shipments = _shipmentViewModelFactory.CreateShipmentsViewModel(cart), Total = _orderGroupCalculator.GetSubTotal(cart) }); }
private ProductTileViewModel CreateProductViewModelForEntry(EntryContentBase entry) { var originalPrice = _pricingService.GetPrice(entry.Code); var image = entry.GetAssets <IContentImage>(_contentLoader, _urlResolver).FirstOrDefault() ?? ""; return(new ProductTileViewModel { Code = entry.Code, DisplayName = entry.DisplayName, PlacedPrice = originalPrice?.UnitPrice ?? _pricingService.GetMoney(0), DiscountedPrice = GetDiscountPrice(entry), ImageUrl = image, Url = entry.GetUrl(), IsAvailable = originalPrice != null }); }
public virtual CartItemViewModel CreateCartItemViewModel(ICart cart, ILineItem lineItem, EntryContentBase entry) { var viewModel = new CartItemViewModel { Code = lineItem.Code, DisplayName = entry.DisplayName, ImageUrl = entry.GetAssets <IContentImage>(_contentLoader, _urlResolver).FirstOrDefault() ?? "", DiscountedPrice = GetDiscountedPrice(cart, lineItem), PlacedPrice = _pricingService.GetMoney(lineItem.PlacedPrice), Quantity = lineItem.Quantity, Url = entry.GetUrl(_relationRepository, _urlResolver), Entry = entry, IsAvailable = _pricingService.GetPrice(entry.Code) != null, DiscountedUnitPrice = GetDiscountedUnitPrice(cart, lineItem), IsGift = lineItem.IsGift }; var productLink = entry is VariationContent? entry.GetParentProducts(_relationRepository).FirstOrDefault() : entry.ContentLink; FashionProduct product; if (_contentLoader.TryGet(productLink, out product)) { viewModel.Brand = GetBrand(product); } var variant = entry as FashionVariant; if (variant != null) { viewModel.AvailableSizes = GetAvailableSizes(product, variant); } return(viewModel); }