private IEnumerable <ProductViewModel> CreateProductViewModels(IContentResult <BaseProduct> searchResult) { var market = _currentMarket.GetCurrentMarket(); var currency = _currencyService.GetCurrentCurrency(); return(searchResult.Select(product => { var originalPrice = product.OriginalPrices.FirstOrDefault( p => p.MarketId == market.MarketId && p.UnitPrice.Currency == currency); var listingPrice = product.ListingPrices.FirstOrDefault( p => p.MarketId == market.MarketId && p.UnitPrice.Currency == currency); return new ProductViewModel { Brand = product.Brand, Code = product.Code, DisplayName = product.DisplayName, PlacedPrice = originalPrice?.UnitPrice ?? new Money(0, currency), DiscountedPrice = listingPrice?.UnitPrice ?? new Money(0, currency), ImageUrl = _assetUrlResolver.GetAssetUrl <IContentImage>(product), Url = _urlResolver.GetUrl(product.ContentLink), IsAvailable = originalPrice != null && originalPrice.UnitPrice.Amount > 0, MarketFilter = product.MarketFilter?.ToString() ?? string.Empty }; })); }
private IEnumerable <FacetGroupOption> BuildFacetGroupList(IContent currentContent, FilterOptionViewModel filterOptions) { var query = BuildBaseQuery(currentContent, filterOptions); query = query.Take(0); query = query.TermsFacetFor(p => p.ParentName, r => r.Size = MaxNumberOfFacets); query = query.TermsFacetFor(p => p.AvailableColorList, r => r.Size = MaxNumberOfFacets); query = query.TermsFacetFor(p => p.AvailableSizeList, r => r.Size = MaxNumberOfFacets); query = query.TermsFacetFor(p => p.Brand, r => r.Size = MaxNumberOfFacets); query = query.TermsFacetFor(p => p.TopCategory, r => r.Size = MaxNumberOfFacets); IContentResult <BaseProduct> results = query.GetContentResult(); var facetGroups = new List <FacetGroupOption>(); AddFacet(facetGroups, results.TermsFacetFor(p => p.ParentName), filterOptions.FacetGroups.FirstOrDefault(fg => fg.GroupFieldName.Equals(Constants.Product.Categories)), Constants.Product.Categories); AddFacet(facetGroups, results.TermsFacetFor(p => p.AvailableColorList), filterOptions.FacetGroups.FirstOrDefault(fg => fg.GroupFieldName.Equals(Constants.Product.AvailableColors)), Constants.Product.AvailableColors); AddFacet(facetGroups, results.TermsFacetFor(p => p.AvailableSizeList), filterOptions.FacetGroups.FirstOrDefault(fg => fg.GroupFieldName.Equals(Constants.Product.AvailableSizes)), Constants.Product.AvailableSizes); AddFacet(facetGroups, results.TermsFacetFor(p => p.Brand), filterOptions.FacetGroups.FirstOrDefault(fg => fg.GroupFieldName.Equals(Constants.Product.Brand)), Constants.Product.Brand); AddFacet(facetGroups, results.TermsFacetFor(p => p.TopCategory), filterOptions.FacetGroups.FirstOrDefault(fg => fg.GroupFieldName.Equals(Constants.Product.TopCategory)), Constants.Product.TopCategory); return(facetGroups); }
private string PublishBinaryContent(IContentLibraryMultimediaItem eclItem, Component eclStubComponent) { IContentResult eclContent = eclItem.GetContent(_emptyAttributes); string uniqueFilename = $"{Path.GetFileNameWithoutExtension(eclItem.Filename)}_{eclStubComponent.Id.ToString().Substring(4)}{Path.GetExtension(eclItem.Filename)}"; return(_pipeline.RenderedItem.AddBinary(eclContent.Stream, uniqueFilename, string.Empty, eclStubComponent, eclContent.ContentType).Url); }
public static void Convert <C>(C content, IContentResult result) { ContentConverterAttribute attribute = result.GetType().GetTypeInfo().GetCustomAttribute <ContentConverterAttribute>(); if (attribute != null) { attribute.Convert(content as Content, result); } }
public static C Convert <C>(IContentResult result) { ContentConverterAttribute attribute = result.GetType().GetTypeInfo().GetCustomAttribute <ContentConverterAttribute>(); if (attribute != null) { return((C)attribute.Convert(result)); } return(default(C)); }
public List <string> GetNames(IContentResult <PersonItemPage> persons) { List <string> lstNames = new List <string>(); foreach (var person in persons) { lstNames.Add(person.Name); } return(lstNames.Distinct().OrderBy(x => x).ToList()); }
private IEnumerable <ProductViewModel> CreateProductViewModels(IContentResult <FashionProduct> searchResults) { return(searchResults.Select(product => new ProductViewModel { Brand = product.Brand, Code = product.Code, DisplayName = product.DisplayName, ImageUrl = product.DefaultImageUrl(), PlacedPrice = product.DefaultPrice(), DiscountedPrice = product.DiscountPrice(), Url = _urlResolver.GetUrl(product.ContentLink), IsAvailable = true })); }
public IEnumerable <ProductTileViewModel> CreateProductViewModels(IContentResult <EntryContentBase> searchResult, IContent content, string searchQuery) { List <ProductTileViewModel> productViewModels = null; var market = _currentMarket.GetCurrentMarket(); var currency = _currencyService.GetCurrentCurrency(); if (searchResult == null) { throw new ArgumentNullException(nameof(searchResult)); } productViewModels = searchResult.Select(document => document.GetProductTileViewModel(market, currency)).ToList(); ApplyBoostedProperties(ref productViewModels, searchResult, content, searchQuery); return(productViewModels); }
private string PublishBinaryContent(IContentLibraryMultimediaItem eclItem, string eclStubComponentId) { IContentResult eclContent = eclItem.GetContent(null); string uniqueFilename = string.Format("{0}_{1}{2}", Path.GetFileNameWithoutExtension(eclItem.Filename), eclStubComponentId.Substring(4), Path.GetExtension(eclItem.Filename)); Tridion.ContentManager.ContentManagement.Component eclStubComponent = (Tridion.ContentManager.ContentManagement.Component)_engine.GetObject(eclStubComponentId); Tridion.ContentManager.Publishing.Rendering.Binary binary = (_binariesStructureGroup == null) ? _engine.PublishingContext.RenderedItem.AddBinary(eclContent.Stream, uniqueFilename, string.Empty, eclStubComponent, eclContent.ContentType) : _engine.PublishingContext.RenderedItem.AddBinary(eclContent.Stream, uniqueFilename, _binariesStructureGroup, string.Empty, eclStubComponent, eclContent.ContentType); _log.Debug(string.Format("Added binary content of ECL Item '{0}' (Stub Component: '{1}', MimeType: '{2}') as '{3}' in '{4}'.", eclItem.Id, eclStubComponentId, eclContent.ContentType, binary.Url, (_binariesStructureGroup == null) ? "(default)" : _binariesStructureGroup.PublishPath)); return(binary.Url); }
/// <summary> /// Sets Featured Product property and Best Bet Product property to ProductViewModels. /// </summary> /// <param name="searchResult">The search result (product list).</param> /// <param name="currentContent">The product category.</param> /// <param name="searchQuery">The search query string to filter Best Bet result.</param> /// <param name="productViewModels">The ProductViewModels is added two properties: Featured Product and Best Bet.</param> private void ApplyBoostedProperties(ref List <ProductTileViewModel> productViewModels, IContentResult <EntryContentBase> searchResult, IContent currentContent, string searchQuery) { var node = currentContent as GenericNode; var products = new List <EntryContentBase>(); if (node != null) { //products = node.FeaturedProducts?.FilteredItems?.Select(x => x.GetContent() as EntryContentBase).ToList() ?? new List<EntryContentBase>(); var featuredProductList = productViewModels.Where(v => products.Any(p => p.ContentLink.ID == v.ProductId)).ToList(); featuredProductList.ForEach(x => { x.IsFeaturedProduct = true; }); productViewModels.RemoveAll(v => products.Any(p => p.ContentLink.ID == v.ProductId)); productViewModels.InsertRange(0, featuredProductList); } var bestBetList = new BestBetRepository().List().Where(i => i.PhraseCriterion.Phrase.CompareTo(searchQuery) == 0); //Filter for product best bet only. var productBestBet = bestBetList.Where(i => i.BestBetSelector is CommerceBestBetSelector); var ownStyleBestBet = bestBetList.Where(i => i.BestBetSelector is CommerceBestBetSelector && i.HasOwnStyle); productViewModels.ToList() .ForEach(p => { if (productBestBet.Any(i => ((CommerceBestBetSelector)i.BestBetSelector).ContentLink.ID == p.ProductId)) { p.IsBestBetProduct = true; } if (ownStyleBestBet.Any(i => ((CommerceBestBetSelector)i.BestBetSelector).ContentLink.ID == p.ProductId)) { p.HasBestBetStyle = true; } }); }
/// <summary> /// Sets Featured Product property and Best Bet Product property to ProductViewModels. /// </summary> /// <param name="searchResult">The search result (product list).</param> /// <param name="currentContent">The product category.</param> /// <param name="searchQuery">The search query string to filter Best Bet result.</param> /// <param name="productViewModels">The ProductViewModels is added two properties: Featured Product and Best Bet.</param> private void ApplyBoostedProperties(ref List <ProductTileViewModel> productViewModels, IContentResult <EntryContentBase> searchResult, IContent currentContent, string searchQuery) { var node = currentContent as GenericNode; var products = new List <EntryContentBase>(); if (node != null) { UpdateListWithFeatured(ref productViewModels, node); } var bestBetList = new BestBetRepository().List().Where(i => i.PhraseCriterion.Phrase.CompareTo(searchQuery) == 0); //Filter for product best bet only. var productBestBet = bestBetList.Where(i => i.BestBetSelector is CommerceBestBetSelector); var ownStyleBestBet = bestBetList.Where(i => i.BestBetSelector is CommerceBestBetSelector && i.HasOwnStyle); productViewModels.ToList() .ForEach(p => { if (productBestBet.Any(i => ((CommerceBestBetSelector)i.BestBetSelector).ContentLink.ID == p.ProductId)) { p.IsBestBetProduct = true; } if (ownStyleBestBet.Any(i => ((CommerceBestBetSelector)i.BestBetSelector).ContentLink.ID == p.ProductId)) { p.HasBestBetStyle = true; } }); }
private string ImportSingleItem(IEclUri eclUri) { string id = "tcm:0-0-0"; IContentLibraryMultimediaItem eclItem = (IContentLibraryMultimediaItem)_eclContentLibraryContext.GetItem(eclUri); string extension = eclItem.Filename.Substring(eclItem.Filename.LastIndexOf('.') + 1); MemoryStream ms = null; string tempPath; try { // create some template attributes IList <ITemplateAttribute> attributes = CreateTemplateAttributes(eclItem); // determine if item has content or is available online string publishedPath = eclItem.GetDirectLinkToPublished(attributes); if (string.IsNullOrEmpty(publishedPath)) { // we can directly get the content IContentResult content = eclItem.GetContent(attributes); ms = new MemoryStream(); content.Stream.CopyTo(ms); ms.Position = 0; } else { // read the content from the publish path using (WebClient webClient = new WebClient()) { byte[] thumbnailData = webClient.DownloadData(publishedPath); ms = new MemoryStream(thumbnailData, false); } } // upload binary (using netTcp binding as configured in SDL Tridion, because this Model extension is running inside the UI) using (StreamUploadClient suClient = new StreamUploadClient("streamUpload_netTcp_2012")) { tempPath = suClient.UploadBinaryContent(eclItem.Filename, ms); } } finally { if (ms != null) { ms.Dispose(); } } // create tcm item var mmComponent = new ComponentData { Id = id, Title = eclItem.Title, Schema = new LinkToSchemaData { IdRef = _schemaUri }, LocationInfo = new LocationInfo { OrganizationalItem = new LinkToOrganizationalItemData { IdRef = _folderUri } } }; // put binary data in tcm item (using netTcp binding as configured in SDL Tridion, because this Model extension is running inside the UI) using (SessionAwareCoreServiceClient client = new SessionAwareCoreServiceClient("netTcp_2012")) { // impersonate with current user client.Impersonate(_username); // set metadata var schemaFields = client.ReadSchemaFields(_schemaUri, true, new ReadOptions()); if (schemaFields.MetadataFields.Any()) { var fields = Fields.ForMetadataOf(schemaFields, mmComponent); if (!string.IsNullOrEmpty(eclItem.MetadataXml)) { XNamespace ns = GetNamespace(eclItem.MetadataXml); XDocument metadata = XDocument.Parse(eclItem.MetadataXml); var children = metadata.Element(ns + "Metadata").Descendants(); for (int i = 0; i < children.Count(); i++) { fields.AddFieldElement(new ItemFieldDefinitionData { Name = "data" }); var embeddedFields = fields["data"].GetSubFields(i); embeddedFields.AddFieldElement(new ItemFieldDefinitionData { Name = "key" }); embeddedFields.AddFieldElement(new ItemFieldDefinitionData { Name = "value" }); embeddedFields["key"].Value = children.ElementAt(i).Name.LocalName; embeddedFields["value"].Value = children.ElementAt(i).Value; } } mmComponent.Metadata = fields.ToString(); } // find multimedia type var list = client.GetSystemWideList(new MultimediaTypesFilterData()); var multimediaType = list.OfType <MultimediaTypeData>().Single(mt => mt.FileExtensions.Contains(extension)); // set BinaryContent of a component mmComponent.BinaryContent = new BinaryContentData { UploadFromFile = tempPath, Filename = eclItem.Filename, MultimediaType = new LinkToMultimediaTypeData { IdRef = multimediaType.Id } }; // create (and save) component ComponentData data = (ComponentData)client.Create(mmComponent, new ReadOptions()); id = data.Id; } //string result = string.Format("created {0}, from {1}, in {2}, using {3}, for {4}", id, eclUri, _folderUri, _schemaUri, _username); return(id); }