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 }); }
private void AddPrices(ISearchDocument document, IEnumerable <EntryContentBase> skuEntries) { var prices = _pricingService.GetCatalogEntryPrices(skuEntries.Select(x => new CatalogKey(x.Code))).ToList(); var validPrices = prices.Where(x => x.ValidFrom <= DateTime.Now && (x.ValidUntil == null || x.ValidUntil >= DateTime.Now)); foreach (var marketPrices in validPrices.GroupBy(x => x.MarketId)) { foreach (var currencyPrices in marketPrices.GroupBy(x => x.UnitPrice.Currency)) { var topPrice = currencyPrices.OrderByDescending(x => x.UnitPrice).FirstOrDefault(); if (topPrice == null) { continue; } var variationPrice = new SearchField(IndexingHelper.GetOriginalPriceField(topPrice.MarketId, topPrice.UnitPrice.Currency), topPrice.UnitPrice.Amount); var discountedPrice = new SearchField(IndexingHelper.GetPriceField(topPrice.MarketId, topPrice.UnitPrice.Currency), _pricingService.GetDiscountPrice(topPrice.CatalogKey, topPrice.MarketId, topPrice.UnitPrice.Currency).UnitPrice.Amount); document.Add(variationPrice); document.Add(discountedPrice); } } }
private Money?GetDiscountedPrice(ICart cart, ILineItem lineItem) { if (cart.Name.Equals(_cartService.DefaultWishListName)) { return(_pricingService.GetDiscountPrice(lineItem.Code)?.UnitPrice); } return(_pricingService.GetDiscountedPrice(lineItem, cart.Currency)); }
protected override Entry GenerateEntry(CatalogContentBase catalogContent) { var variationContent = catalogContent as FashionVariant; if (variationContent == null) { return(null); } var product = _contentLoader.Get <CatalogContentBase>(variationContent.GetParentProducts().FirstOrDefault()) as FashionProduct; var variantCode = variationContent.Code; var defaultPrice = _pricingService.GetDefaultPrice(variantCode); var entry = new Entry { Id = variantCode, Title = variationContent.DisplayName, Description = product?.Description.ToHtmlString(), Link = variationContent.GetUrl(), Condition = "new", Availability = "in stock", Brand = product?.Brand, MPN = string.Empty, GTIN = "725272730706", GoogleProductCategory = string.Empty, Shipping = new List <Shipping> { new Shipping { Price = "1 USD", Country = "US", Service = "Standard" } } }; var image = variationContent.GetDefaultAsset <IContentImage>(); if (!string.IsNullOrEmpty(image)) { entry.ImageLink = Uri.TryCreate(new Uri(_siteUrl), image, out var imageUri) ? imageUri.ToString() : image; } if (defaultPrice != null) { var discountPrice = _pricingService.GetDiscountPrice(variantCode); entry.Price = defaultPrice.UnitPrice.FormatPrice(); entry.SalePrice = discountPrice != null?discountPrice.UnitPrice.FormatPrice() : string.Empty; entry.SalePriceEffectiveDate = $"{DateTime.UtcNow:yyyy-MM-ddThh:mm:ss}/{DateTime.UtcNow.AddDays(7):yyyy-MM-ddThh:mm:ss}"; } return(entry); }
private Money?GetDiscountPrice(EntryContentBase entry) { var originalPrice = _pricingService.GetPrice(entry.Code); if (originalPrice != null) { var discountedPrice = _pricingService.GetDiscountPrice(entry.Code); return(discountedPrice?.UnitPrice ?? originalPrice.UnitPrice); } return(null); }
private void UpdateRecommendation(RecommendationData recommendation, EntryContentBase entry) { var imageUrl = entry.GetAssets <IContentImage>(_contentLoader, _urlResolver).FirstOrDefault() ?? ""; var originalPrice = _pricingService.GetPrice(entry.Code); var salePrice = _pricingService.GetDiscountPrice(entry.Code); if (recommendation.Attributes == null) { recommendation.Attributes = new Dictionary <string, string>(); } recommendation.Attributes.Add(Title, entry.DisplayName); recommendation.Attributes.Add(Url, entry.GetUrl(recommendation.Lang)); recommendation.Attributes.Add(Image, imageUrl); recommendation.Attributes.Add(UnitPrice, originalPrice?.UnitPrice.ToString()); recommendation.Attributes.Add(SalePrice, salePrice?.UnitPrice.ToString()); }
public override List <Feed> Build() { var generatedFeeds = new List <Feed>(); var siteUrl = _siteDefinitionRepository.List().FirstOrDefault()?.SiteUrl.ToString(); var feed = new Feed { Updated = DateTime.UtcNow, Title = "My products", Link = siteUrl }; var entries = new List <Entry>(); var catalogReferences = _contentLoader.GetDescendents(_referenceConverter.GetRootLink()); foreach (var catalogReference in catalogReferences) { var catalogContent = _contentLoader.Get <CatalogContentBase>(catalogReference); var variationContent = catalogContent as FashionVariant; if (variationContent != null) { var product = _contentLoader.Get <CatalogContentBase>(variationContent.GetParentProducts().FirstOrDefault()) as FashionProduct; var variantCode = variationContent.Code; var defaultPrice = _pricingService.GetDefaultPrice(variantCode); var entry = new Entry { Id = variantCode, Title = variationContent.DisplayName, Description = product?.Description.ToHtmlString(), Link = variationContent.GetUrl(), Condition = "new", Availability = "in stock", Brand = product?.Brand, MPN = string.Empty, GTIN = "725272730706", GoogleProductCategory = string.Empty, Shipping = new List <Shipping> { new Shipping { Price = "1 USD", Country = "US", Service = "Standard" } } }; var image = variationContent.GetDefaultAsset <IContentImage>(); if (!string.IsNullOrEmpty(image)) { entry.ImageLink = Uri.TryCreate(new Uri(siteUrl), image, out var imageUri) ? imageUri.ToString() : image; } if (defaultPrice != null) { var discountPrice = _pricingService.GetDiscountPrice(variantCode); entry.Price = defaultPrice.UnitPrice.FormatPrice(); entry.SalePrice = discountPrice != null?discountPrice.UnitPrice.FormatPrice() : string.Empty; entry.SalePriceEffectiveDate = $"{DateTime.UtcNow:yyyy-MM-ddThh:mm:ss}/{DateTime.UtcNow.AddDays(7):yyyy-MM-ddThh:mm:ss}"; } entries.Add(entry); } } feed.Entries = entries; generatedFeeds.Add(feed); return(generatedFeeds); }