public virtual Collection ToLiquidCollection(storefrontModel.Category category, WorkContext workContext) { var result = new Collection(); result.Id = category.Id; result.Description = null; result.Handle = category.SeoInfo != null ? category.SeoInfo.Slug : category.Id; result.Title = category.Name; result.Url = category.Url; result.DefaultSortBy = "manual"; if (category.PrimaryImage != null) { result.Image = ToLiquidImage(category.PrimaryImage); } if (category.Products != null) { result.Products = new MutablePagedList <Product>((pageNumber, pageSize, sortInfos) => { category.Products.Slice(pageNumber, pageSize, sortInfos); return(new StaticPagedList <Product>(category.Products.Select(x => ToLiquidProduct(x)), category.Products)); }, category.Products.PageNumber, category.Products.PageSize); } if (category.Categories != null) { result.Collections = new MutablePagedList <Collection>((pageNumber, pageSize, sortInfos) => { category.Categories.Slice(pageNumber, pageSize, sortInfos); return(new StaticPagedList <Collection>(category.Categories.Select(x => ToLiquidCollection(x, workContext)), category.Categories)); }, category.Categories.PageNumber, category.Categories.PageSize); } if (workContext.Aggregations != null) { result.Tags = new TagCollection(new MutablePagedList <Tag>((pageNumber, pageSize, sortInfos) => { workContext.Aggregations.Slice(pageNumber, pageSize, sortInfos); var tags = workContext.Aggregations.Where(a => a.Items != null) .SelectMany(a => a.Items.Select(item => ToLiquidTag(item, a.Field, a.Label))); return(new StaticPagedList <Tag>(tags, workContext.Aggregations)); }, workContext.Aggregations.PageNumber, workContext.Aggregations.PageSize)); } if (workContext.CurrentProductSearchCriteria.SortBy != null) { result.SortBy = workContext.CurrentProductSearchCriteria.SortBy; } if (!category.Properties.IsNullOrEmpty()) { result.Metafields = new MetaFieldNamespacesCollection(new[] { new MetafieldsCollection("properties", category.Properties) }); } return(result); }
public static Category ToWebModel(this VirtoCommerceCatalogModuleWebModelCategory category, VirtoCommerceCatalogModuleWebModelProduct[] products = null) { var retVal = new Category(); retVal.InjectFrom<NullableAndEnumValueInjecter>(category); if (category.SeoInfos != null) retVal.SeoInfo = category.SeoInfos.Select(s => s.ToWebModel()).FirstOrDefault(); if (category.Images != null) { retVal.Images = category.Images.Select(i => i.ToWebModel()).ToArray(); retVal.PrimaryImage = retVal.Images.FirstOrDefault(); } return retVal; }
public static Category ToWebModel(this VirtoCommerceCatalogModuleWebModelCategory category, Language currentLanguage, Store store, VirtoCommerceCatalogModuleWebModelProduct[] products = null) { var retVal = new Category(); retVal.InjectFrom<NullableAndEnumValueInjecter>(category); retVal.SeoInfo = category.SeoInfos.GetBestMatchedSeoInfo(store, currentLanguage).ToWebModel(); retVal.Url = "~/" + category.Outlines.GetSeoPath(store, currentLanguage, "category/" + category.Id); if (category.Images != null) { retVal.Images = category.Images.Select(i => i.ToWebModel()).ToArray(); retVal.PrimaryImage = retVal.Images.FirstOrDefault(); } if (category.Properties != null) { retVal.Properties = category.Properties .Where(x => string.Equals(x.Type, "Category", StringComparison.OrdinalIgnoreCase)) .Select(p => p.ToWebModel(currentLanguage)) .ToList(); } return retVal; }
public static Collection ToShopifyModel(this storefrontModel.Category category, WorkContext workContext) { var converter = ServiceLocator.Current.GetInstance <ShopifyModelConverter>(); return(converter.ToLiquidCollection(category, workContext)); }
public static Collection ToShopifyModel(this storefrontModel.Category category, WorkContext workContext) { var converter = new ShopifyModelConverter(); return(converter.ToLiquidCollection(category, workContext)); }