public IHttpActionResult GetNewProduct(string catalogId, string categoryId) { var retVal = new webModel.Product { CategoryId = categoryId, CatalogId = catalogId, IsActive = true, }; if (catalogId != null) { var properites = GetAllCatalogProperies(catalogId, categoryId); retVal.Properties = properites.Select(x => x.ToWebModel()).ToList(); foreach (var property in retVal.Properties) { property.Values = new List<webModel.PropertyValue>(); property.IsManageable = true; property.IsReadOnly = property.Type != coreModel.PropertyType.Product && property.Type != coreModel.PropertyType.Variation; } } retVal.Code = _skuGenerator.GenerateSku(retVal.ToModuleModel(null)); return Ok(retVal); }
private coreModel.CatalogProduct UpdateProduct(webModel.Product product) { var moduleProduct = product.ToModuleModel(_blobUrlResolver); if (moduleProduct.Id == null) { if (moduleProduct.SeoInfos == null || !moduleProduct.SeoInfos.Any()) { var slugUrl = GenerateProductDefaultSlugUrl(product); if (!string.IsNullOrEmpty(slugUrl)) { var catalog = _catalogService.GetById(product.CatalogId); var defaultLanguageCode = catalog.Languages.First(x => x.IsDefault).LanguageCode; var seoInfo = new SeoInfo { LanguageCode = defaultLanguageCode, SemanticUrl = slugUrl }; moduleProduct.SeoInfos = new SeoInfo[] { seoInfo }; } } base.CheckCurrentUserHasPermissionForObjects(CatalogPredefinedPermissions.Create, moduleProduct); return(_itemsService.Create(moduleProduct)); } else { base.CheckCurrentUserHasPermissionForObjects(CatalogPredefinedPermissions.Update, moduleProduct); _itemsService.Update(new[] { moduleProduct }); } return(null); }
public static moduleModel.CatalogProduct ToModuleModel(this webModel.Product product, IBlobUrlResolver blobUrlResolver) { var retVal = new moduleModel.CatalogProduct(); retVal.InjectFrom(product); retVal.SeoInfos = product.SeoInfos; if (product.Images != null) { retVal.Images = product.Images.Select(x => x.ToCoreModel()).ToList(); var index = 0; foreach (var image in retVal.Images) { image.SortOrder = index++; } } if (product.Assets != null) { retVal.Assets = product.Assets.Select(x => x.ToCoreModel()).ToList(); } if (product.Properties != null) { retVal.PropertyValues = new List <moduleModel.PropertyValue>(); foreach (var property in product.Properties) { foreach (var propValue in property.Values) { //Need populate required fields propValue.PropertyName = property.Name; propValue.ValueType = property.ValueType; retVal.PropertyValues.Add(propValue.ToModuleModel()); } } } if (product.Variations != null) { retVal.Variations = product.Variations.Select(x => x.ToModuleModel(blobUrlResolver)).ToList(); } if (product.Links != null) { retVal.Links = product.Links.Select(x => x.ToModuleModel()).ToList(); } if (product.Reviews != null) { retVal.Reviews = product.Reviews.Select(x => x.ToModuleModel()).ToList(); } if (product.Associations != null) { retVal.Associations = product.Associations.Select(x => x.ToModuleModel()).ToList(); } retVal.MainProductId = product.TitularItemId; return(retVal); }
public IHttpActionResult GetNewProduct(string catalogId, string categoryId) { var retVal = new webModel.Product { CategoryId = categoryId, CatalogId = catalogId, IsActive = true, }; if (catalogId != null) { var properites = GetAllCatalogProperies(catalogId, categoryId); retVal.Properties = properites.Select(x => x.ToWebModel()).ToList(); foreach (var property in retVal.Properties) { property.Values = new List <webModel.PropertyValue>(); property.IsManageable = true; property.IsReadOnly = property.Type != coreModel.PropertyType.Product && property.Type != coreModel.PropertyType.Variation; } } retVal.Code = _skuGenerator.GenerateSku(retVal.ToModuleModel(null)); return(Ok(retVal)); }
public IHttpActionResult GetNewProductByCatalogAndCategory(string catalogId, string categoryId) { var retVal = new webModel.Product { CategoryId = categoryId, CatalogId = catalogId, IsActive = true, }; base.CheckCurrentUserHasPermissionForObjects(CatalogPredefinedPermissions.Create, retVal.ToModuleModel(_blobUrlResolver)); if (catalogId != null) { var properites = GetAllCatalogProperies(catalogId, categoryId); retVal.Properties = properites.Select(x => x.ToWebModel()).ToList(); foreach (var property in retVal.Properties) { property.Values = new List <webModel.PropertyValue>(); property.IsManageable = true; property.IsReadOnly = property.Type != coreModel.PropertyType.Product && property.Type != coreModel.PropertyType.Variation; } } retVal.Code = _skuGenerator.GenerateSku(retVal.ToModuleModel(null)); return(Ok(retVal)); }
public IHttpActionResult SaveProduct(webModel.Product product) { var result = InnerSaveProducts(new[] { product }).FirstOrDefault(); if (result != null) { return(Ok(result.ToWebModel(_blobUrlResolver))); } return(StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult Update(webModel.Product product) { var updatedProduct = UpdateProduct(product); if (updatedProduct != null) { return(Ok(updatedProduct)); } return(StatusCode(HttpStatusCode.NoContent)); }
public ListEntryProduct(Product product) : base(TypeName) { Id = product.Id; ImageUrl = product.ImgSrc; Code = product.Code; Name = product.Name; ProductType = product.ProductType; IsActive = product.IsActive ?? true; if (product.Links != null) { Links = product.Links.Select(x => new ListEntryLink(x) ).ToArray(); } }
private string GenerateProductDefaultSlugUrl(webModel.Product product) { var retVal = new List <string>(); retVal.Add(product.Name); if (product.Properties != null) { foreach (var property in product.Properties.Where(x => x.Type == coreModel.PropertyType.Variation && x.Values != null)) { retVal.AddRange(property.Values.Select(x => x.PropertyName + "-" + x.Value)); } } return(String.Join(" ", retVal).GenerateSlug()); }
public IHttpActionResult GetNewVariation(string productId) { var product = _itemsService.GetById(productId, coreModel.ItemResponseGroup.ItemLarge); if (product == null) { return(NotFound()); } base.CheckCurrentUserHasPermissionForObjects(CatalogPredefinedPermissions.Create, product); var properties = GetAllCatalogProperies(product.CatalogId, product.CategoryId); var mainWebProduct = product.ToWebModel(_blobUrlResolver, properties); var newVariation = new webModel.Product { Name = product.Name, CategoryId = product.CategoryId, CatalogId = product.CatalogId, TitularItemId = product.MainProductId ?? productId, Properties = mainWebProduct.Properties.Where(x => x.Type == coreModel.PropertyType.Variation).ToList(), }; foreach (var property in newVariation.Properties) { //Need reset value ids foreach (var val in property.Values.ToArray()) { val.Id = null; } // Mark variation property as required if (property.Type == coreModel.PropertyType.Variation) { property.Required = true; } property.IsManageable = true; } newVariation.Code = _skuGenerator.GenerateSku(newVariation.ToModuleModel(null)); return(Ok(newVariation)); }
public IHttpActionResult GetNewProductByCatalogAndCategory(string catalogId, string categoryId) { var retVal = new webModel.Product { CategoryId = categoryId, CatalogId = catalogId, IsActive = true, SeoInfos = new SeoInfo[0] }; CheckCurrentUserHasPermissionForObjects(CatalogPredefinedPermissions.Create, retVal.ToModuleModel(_blobUrlResolver)); if (catalogId != null) { var catalog = _catalogService.GetById(catalogId); retVal.Catalog = catalog.ToWebModel(); retVal.Properties = catalog.Properties.Select(x => x.ToWebModel()).ToList(); } if (categoryId != null) { var category = _categoryService.GetById(categoryId, coreModel.CategoryResponseGroup.WithProperties); retVal.Category = category.ToWebModel(); retVal.Properties = category.Properties.Select(x => x.ToWebModel()).ToList(); } foreach (var property in retVal.Properties) { property.Values = new List <webModel.PropertyValue>(); property.IsManageable = true; property.IsReadOnly = property.Type != coreModel.PropertyType.Product && property.Type != coreModel.PropertyType.Variation; } retVal.Code = _skuGenerator.GenerateSku(retVal.ToModuleModel(null)); return(Ok(retVal)); }
protected virtual void ReduceSearchResult(ISearchCriteria criteria, ItemResponseGroup responseGroup, catalogModel.Product product) { if (!responseGroup.HasFlag(ItemResponseGroup.ItemAssets)) { product.Assets = null; } if (!responseGroup.HasFlag(ItemResponseGroup.ItemAssociations)) { product.Associations = null; } if (!responseGroup.HasFlag(ItemResponseGroup.ItemEditorialReviews)) { product.Reviews = null; } if (!responseGroup.HasFlag(ItemResponseGroup.ItemInfo)) { product.Properties = null; } if (!responseGroup.HasFlag(ItemResponseGroup.Links)) { product.Links = null; } if (!responseGroup.HasFlag(ItemResponseGroup.Outlines)) { product.Outlines = null; } if (!responseGroup.HasFlag(ItemResponseGroup.Seo)) { product.SeoInfos = null; } if (!responseGroup.HasFlag(ItemResponseGroup.Variations)) { product.Variations = null; } }
public static webModel.Product ToWebModel(this moduleModel.CatalogProduct product, IBlobUrlResolver blobUrlResolver) { var retVal = new webModel.Product(); retVal.Id = product.Id; retVal.CatalogId = product.CatalogId; retVal.CategoryId = product.CategoryId; retVal.Code = product.Code; retVal.CreatedBy = product.CreatedBy; retVal.CreatedDate = product.CreatedDate; retVal.DownloadExpiration = product.DownloadExpiration; retVal.DownloadType = product.DownloadType; retVal.EnableReview = product.EnableReview; retVal.Gtin = product.Gtin; retVal.HasUserAgreement = product.HasUserAgreement; retVal.Height = product.Height; retVal.IndexingDate = product.IndexingDate; retVal.IsActive = product.IsActive; retVal.IsBuyable = product.IsBuyable; retVal.Length = product.Length; retVal.ManufacturerPartNumber = product.ManufacturerPartNumber; retVal.MaxNumberOfDownload = product.MaxNumberOfDownload; retVal.MaxQuantity = product.MaxQuantity; retVal.MeasureUnit = product.MeasureUnit; retVal.MinQuantity = product.MinQuantity; retVal.ModifiedBy = product.ModifiedBy; retVal.ModifiedDate = product.ModifiedDate; retVal.Name = product.Name; retVal.PackageType = product.PackageType; retVal.Priority = product.Priority; retVal.ProductType = product.ProductType; retVal.TaxType = product.TaxType; retVal.TrackInventory = product.TrackInventory; retVal.Vendor = product.Vendor; retVal.Weight = product.Weight; retVal.WeightUnit = product.WeightUnit; retVal.Width = product.Width; retVal.SeoInfos = product.SeoInfos; if (!product.Outlines.IsNullOrEmpty()) { //Minimize outline size retVal.Outlines = product.Outlines.Select(x => x.ToWebModel()).ToList(); } if (product.Images != null) { retVal.Images = product.Images.Select(x => x.ToWebModel(blobUrlResolver)).ToList(); } if (product.Assets != null) { retVal.Assets = product.Assets.Select(x => x.ToWebModel(blobUrlResolver)).ToList(); } if (product.Variations != null) { retVal.Variations = product.Variations.Select(x => x.ToWebModel(blobUrlResolver)).ToList(); //For nested variations leave only variation properties to decrease resulting JSON foreach (var variation in retVal.Variations) { if (variation.Properties != null) { variation.Properties = variation.Properties.Where(x => x.Type == moduleModel.PropertyType.Variation).ToList(); } } } if (product.Links != null) { retVal.Links = product.Links.Select(x => x.ToWebModel()).ToList(); } if (product.Reviews != null) { retVal.Reviews = product.Reviews.Select(x => x.ToWebModel()).ToList(); } if (product.Associations != null) { retVal.Associations = product.Associations.Select(x => x.ToWebModel(blobUrlResolver)).ToList(); } if (product.ReferencedAssociations != null) { retVal.ReferencedAssociations = product.ReferencedAssociations.Select(a => a.ToWebModel(blobUrlResolver)).ToList(); } //Init outline and path if (product.Category != null) { var parents = new List <moduleModel.Category>(); if (product.Category.Parents != null) { parents.AddRange(product.Category.Parents); } parents.Add(product.Category); retVal.Outline = string.Join("/", parents.Select(x => x.Id)); retVal.Path = string.Join("/", parents.Select(x => x.Name)); } retVal.TitularItemId = product.MainProductId; retVal.Properties = new List <webModel.Property>(); //Need add property for each meta info if (product.Properties != null) { foreach (var property in product.Properties) { var webModelProperty = property.ToWebModel(); //Reset dict values to decrease response size webModelProperty.DictionaryValues = null; webModelProperty.Values = new List <webModel.PropertyValue>(); webModelProperty.IsManageable = true; webModelProperty.IsReadOnly = property.Type != moduleModel.PropertyType.Product && property.Type != moduleModel.PropertyType.Variation; retVal.Properties.Add(webModelProperty); } } //Populate property values if (product.PropertyValues != null) { foreach (var propValue in product.PropertyValues.Select(x => x.ToWebModel())) { var property = retVal.Properties.FirstOrDefault(x => x.Id == propValue.PropertyId); if (property == null) { property = retVal.Properties.FirstOrDefault(x => x.Name.EqualsInvariant(propValue.PropertyName)); } if (property == null) { //Need add dummy property for each value without property property = new webModel.Property(propValue, product.CatalogId, moduleModel.PropertyType.Product); retVal.Properties.Add(property); } property.Values.Add(propValue); } } return(retVal); }
public IHttpActionResult GetNewProductByCatalogAndCategory(string catalogId, string categoryId) { var retVal = new webModel.Product { CategoryId = categoryId, CatalogId = catalogId, IsActive = true, }; base.CheckCurrentUserHasPermissionForObjects(CatalogPredefinedPermissions.Create, retVal.ToModuleModel(_blobUrlResolver)); if(catalogId != null) { var catalog = _catalogService.GetById(catalogId); retVal.Properties = catalog.Properties.Select(x => x.ToWebModel()).ToList(); } if (categoryId != null) { var category = _categoryService.GetById(categoryId, Domain.Catalog.Model.CategoryResponseGroup.WithProperties); retVal.Properties = category.Properties.Select(x => x.ToWebModel()).ToList(); } foreach (var property in retVal.Properties) { property.Values = new List<webModel.PropertyValue>(); property.IsManageable = true; property.IsReadOnly = property.Type != coreModel.PropertyType.Product && property.Type != coreModel.PropertyType.Variation; } retVal.Code = _skuGenerator.GenerateSku(retVal.ToModuleModel(null)); return Ok(retVal); }
public IHttpActionResult GetNewVariation(string productId) { var product = _itemsService.GetById(productId, coreModel.ItemResponseGroup.ItemLarge); if (product == null) { return NotFound(); } base.CheckCurrentUserHasPermissionForObjects(CatalogPredefinedPermissions.Create, product); var mainWebProduct = product.ToWebModel(_blobUrlResolver); var newVariation = new webModel.Product { Name = product.Name, CategoryId = product.CategoryId, CatalogId = product.CatalogId, TitularItemId = product.MainProductId ?? productId, Properties = mainWebProduct.Properties.Where(x => x.Type == coreModel.PropertyType.Variation).ToList(), }; foreach (var property in newVariation.Properties) { // Mark variation property as required if (property.Type == coreModel.PropertyType.Variation) { property.Required = true; property.Values.Clear(); } property.IsManageable = true; } newVariation.Code = _skuGenerator.GenerateSku(newVariation.ToModuleModel(null)); return Ok(newVariation); }
public static webModel.Product ToWebModel(this moduleModel.CatalogProduct product, IBlobUrlResolver blobUrlResolver) { var retVal = new webModel.Product(); retVal.InjectFrom(product); retVal.SeoInfos = product.SeoInfos; if (product.Catalog != null) { retVal.Catalog = product.Catalog.ToWebModel(); //Reset catalog properties and languages for response size economy retVal.Catalog.Properties = null; } if (product.Category != null) { retVal.Category = product.Category.ToWebModel(blobUrlResolver); //Reset category catalog, properties for response size economy retVal.Category.Catalog = null; retVal.Category.Properties = null; } if (product.Images != null) { retVal.Images = product.Images.Select(x => x.ToWebModel(blobUrlResolver)).ToList(); } if (product.Assets != null) { retVal.Assets = product.Assets.Select(x => x.ToWebModel(blobUrlResolver)).ToList(); } if (product.Variations != null) { retVal.Variations = product.Variations.Select(x => x.ToWebModel(blobUrlResolver)).ToList(); } if (product.Links != null) { retVal.Links = product.Links.Select(x => x.ToWebModel()).ToList(); } if (product.Reviews != null) { retVal.Reviews = product.Reviews.Select(x => x.ToWebModel()).ToList(); } if (product.Associations != null) { retVal.Associations = product.Associations.Select(x => x.ToWebModel(blobUrlResolver)).ToList(); } //Init parents if (product.Category != null) { retVal.Parents = new List <webModel.Category>(); if (product.Category.Parents != null) { retVal.Parents.AddRange(product.Category.Parents.Select(x => x.ToWebModel())); } retVal.Parents.Add(product.Category.ToWebModel()); foreach (var parent in retVal.Parents) { //Reset some props to decrease size of resulting json parent.Catalog = null; parent.Properties = null; } } retVal.TitularItemId = product.MainProductId; retVal.Properties = new List <webModel.Property>(); //Need add property for each meta info if (product.Properties != null) { foreach (var property in product.Properties) { var webModelProperty = property.ToWebModel(); //Reset dict values to decrease response size webModelProperty.DictionaryValues = null; webModelProperty.Category = null; webModelProperty.Values = new List <webModel.PropertyValue>(); webModelProperty.IsManageable = true; webModelProperty.IsReadOnly = property.Type != moduleModel.PropertyType.Product && property.Type != moduleModel.PropertyType.Variation; retVal.Properties.Add(webModelProperty); } } //Populate property values if (product.PropertyValues != null) { foreach (var propValue in product.PropertyValues.Select(x => x.ToWebModel())) { var property = retVal.Properties.FirstOrDefault(x => x.Id == propValue.PropertyId); if (property == null) { //Need add dummy property for each value without property property = new webModel.Property(propValue, product.CatalogId, product.CategoryId, moduleModel.PropertyType.Product); retVal.Properties.Add(property); } property.Values.Add(propValue); } } return(retVal); }
public static webModel.Product ToWebModel(this moduleModel.CatalogProduct product, IBlobUrlResolver blobUrlResolver, moduleModel.Property[] properties = null) { var retVal = new webModel.Product(); retVal.InjectFrom(product); retVal.SeoInfos = product.SeoInfos; if (product.Catalog != null) { retVal.Catalog = product.Catalog.ToWebModel(); } if (product.Category != null) { retVal.Category = product.Category.ToWebModel(); } if (product.Assets != null) { var assetBases = product.Assets.Select(x => x.ToWebModel(blobUrlResolver)).ToList(); retVal.Images = assetBases.OfType <webModel.ProductImage>().ToList(); retVal.Assets = assetBases.OfType <webModel.ProductAsset>().ToList(); } if (product.Variations != null) { retVal.Variations = product.Variations.Select(x => x.ToWebModel(blobUrlResolver)).ToList(); } if (product.Links != null) { retVal.Links = product.Links.Select(x => x.ToWebModel()).ToList(); } if (product.Reviews != null) { retVal.Reviews = product.Reviews.Select(x => x.ToWebModel()).ToList(); } if (product.Associations != null) { retVal.Associations = product.Associations.Select(x => x.ToWebModel(blobUrlResolver)).ToList(); } retVal.TitularItemId = product.MainProductId; retVal.Properties = new List <webModel.Property>(); //Need add property for each meta info if (properties != null) { foreach (var property in properties) { var webModelProperty = property.ToWebModel(); webModelProperty.Category = null; webModelProperty.Values = new List <webModel.PropertyValue>(); webModelProperty.IsManageable = true; webModelProperty.IsReadOnly = property.Type != moduleModel.PropertyType.Product && property.Type != moduleModel.PropertyType.Variation; retVal.Properties.Add(webModelProperty); } } //Populate property values if (product.PropertyValues != null) { foreach (var propValue in product.PropertyValues.Select(x => x.ToWebModel())) { var property = retVal.Properties.FirstOrDefault(x => x.IsSuitableForValue(propValue)); if (property == null) { //Need add dummy property for each value without property property = new webModel.Property(propValue, product.CatalogId, product.CategoryId, moduleModel.PropertyType.Product); retVal.Properties.Add(property); } property.Values.Add(propValue); } } return(retVal); }
public static webModel.Product ToWebModel(this moduleModel.CatalogProduct product, IBlobUrlResolver blobUrlResolver, moduleModel.Property[] properties = null) { var retVal = new webModel.Product(); retVal.InjectFrom(product); retVal.SeoInfos = product.SeoInfos; if (product.Catalog != null) { retVal.Catalog = product.Catalog.ToWebModel(); } if (product.Category != null) { retVal.Category = product.Category.ToWebModel(blobUrlResolver); } if (product.Images != null) { retVal.Images = product.Images.Select(x => x.ToWebModel(blobUrlResolver)).ToList(); } if(product.Assets != null) { retVal.Assets = product.Assets.Select(x => x.ToWebModel(blobUrlResolver)).ToList(); } if (product.Variations != null) { retVal.Variations = product.Variations.Select(x => x.ToWebModel(blobUrlResolver)).ToList(); } if (product.Links != null) { retVal.Links = product.Links.Select(x => x.ToWebModel()).ToList(); } if (product.Reviews != null) { retVal.Reviews = product.Reviews.Select(x => x.ToWebModel()).ToList(); } if (product.Associations != null) { retVal.Associations = product.Associations.Select(x => x.ToWebModel(blobUrlResolver)).ToList(); } retVal.TitularItemId = product.MainProductId; retVal.Properties = new List<webModel.Property>(); //Need add property for each meta info if (properties != null) { foreach (var property in properties) { var webModelProperty = property.ToWebModel(); webModelProperty.Category = null; webModelProperty.Values = new List<webModel.PropertyValue>(); webModelProperty.IsManageable = true; webModelProperty.IsReadOnly = property.Type != moduleModel.PropertyType.Product && property.Type != moduleModel.PropertyType.Variation; retVal.Properties.Add(webModelProperty); } } //Populate property values if (product.PropertyValues != null) { foreach (var propValue in product.PropertyValues.Select(x=>x.ToWebModel())) { var property = retVal.Properties.FirstOrDefault(x => x.IsSuitableForValue(propValue)); if (property == null) { //Need add dummy property for each value without property property = new webModel.Property(propValue, product.CatalogId, product.CategoryId, moduleModel.PropertyType.Product); retVal.Properties.Add(property); } property.Values.Add(propValue); } } return retVal; }
public IHttpActionResult GetNewVariation(string productId) { var product = _itemsService.GetById(productId, coreModel.ItemResponseGroup.ItemLarge); if (product == null) { return NotFound(); } var properties = GetAllCatalogProperies(product.CatalogId, product.CategoryId); var mainWebProduct = product.ToWebModel(_blobUrlResolver, properties); var newVariation = new webModel.Product { Name = product.Name, CategoryId = product.CategoryId, CatalogId = product.CatalogId, TitularItemId = product.MainProductId ?? productId, Properties = mainWebProduct.Properties.Where(x => x.Type == coreModel.PropertyType.Variation).ToList(), }; foreach (var property in newVariation.Properties) { //Need reset value ids foreach (var val in property.Values.ToArray()) { val.Id = null; } // Mark variation property as required if (property.Type == coreModel.PropertyType.Variation) { property.Required = true; } property.IsManageable = true; } newVariation.Code = _skuGenerator.GenerateSku(newVariation.ToModuleModel(null)); return Ok(newVariation); }
public static moduleModel.CatalogProduct ToModuleModel(this webModel.Product product, IBlobUrlResolver blobUrlResolver) { var retVal = new moduleModel.CatalogProduct(); retVal.InjectFrom(product); retVal.SeoInfos = product.SeoInfos; if (product.Images != null) { retVal.Assets = new List <moduleModel.ItemAsset>(); bool isMain = true; foreach (var productImage in product.Images) { var image = productImage.ToModuleModel(); image.Type = moduleModel.ItemAssetType.Image; image.Group = isMain ? "primaryimage" : "images"; retVal.Assets.Add(image); isMain = false; } } if (product.Assets != null) { if (retVal.Assets == null) { retVal.Assets = new List <moduleModel.ItemAsset>(); } foreach (var productAsset in product.Assets) { var asset = productAsset.ToModuleModel(); asset.Type = moduleModel.ItemAssetType.File; retVal.Assets.Add(asset); } } if (product.Properties != null) { retVal.PropertyValues = new List <moduleModel.PropertyValue>(); foreach (var property in product.Properties) { foreach (var propValue in property.Values) { //Need populate required fields propValue.PropertyName = property.Name; propValue.ValueType = property.ValueType; retVal.PropertyValues.Add(propValue.ToModuleModel()); } } } if (product.Variations != null) { retVal.Variations = product.Variations.Select(x => x.ToModuleModel(blobUrlResolver)).ToList(); } if (product.Links != null) { retVal.Links = product.Links.Select(x => x.ToModuleModel()).ToList(); } if (product.Reviews != null) { retVal.Reviews = product.Reviews.Select(x => x.ToModuleModel()).ToList(); } if (product.Associations != null) { retVal.Associations = product.Associations.Select(x => x.ToModuleModel()).ToList(); } retVal.MainProductId = product.TitularItemId; return(retVal); }
public static webModel.Product ToWebModel(this moduleModel.CatalogProduct product, IBlobUrlResolver blobUrlResolver) { var retVal = new webModel.Product(); retVal.InjectFrom(product); retVal.SeoInfos = product.SeoInfos; if (product.Catalog != null) { retVal.Catalog = product.Catalog.ToWebModel(); //Reset catalog properties and languages for response size economy retVal.Catalog.Properties = null; } if (product.Category != null) { retVal.Category = product.Category.ToWebModel(blobUrlResolver); //Reset category catalog, properties for response size economy retVal.Category.Catalog = null; retVal.Category.Properties = null; } if (product.Images != null) { retVal.Images = product.Images.Select(x => x.ToWebModel(blobUrlResolver)).ToList(); } if(product.Assets != null) { retVal.Assets = product.Assets.Select(x => x.ToWebModel(blobUrlResolver)).ToList(); } if (product.Variations != null) { retVal.Variations = product.Variations.Select(x => x.ToWebModel(blobUrlResolver)).ToList(); } if (product.Links != null) { retVal.Links = product.Links.Select(x => x.ToWebModel()).ToList(); } if (product.Reviews != null) { retVal.Reviews = product.Reviews.Select(x => x.ToWebModel()).ToList(); } if (product.Associations != null) { retVal.Associations = product.Associations.Select(x => x.ToWebModel(blobUrlResolver)).ToList(); } //Init parents if(product.Category != null) { retVal.Parents = new List<webModel.Category>(); if(product.Category.Parents != null) { retVal.Parents.AddRange(product.Category.Parents.Select(x => x.ToWebModel())); } retVal.Parents.Add(product.Category.ToWebModel()); foreach(var parent in retVal.Parents) { //Reset some props to decrease size of resulting json parent.Catalog = null; parent.Properties = null; } } retVal.TitularItemId = product.MainProductId; retVal.Properties = new List<webModel.Property>(); //Need add property for each meta info if (product.Properties != null) { foreach (var property in product.Properties) { var webModelProperty = property.ToWebModel(); //Reset dict values to decrease response size webModelProperty.DictionaryValues = null; webModelProperty.Category = null; webModelProperty.Values = new List<webModel.PropertyValue>(); webModelProperty.IsManageable = true; webModelProperty.IsReadOnly = property.Type != moduleModel.PropertyType.Product && property.Type != moduleModel.PropertyType.Variation; retVal.Properties.Add(webModelProperty); } } //Populate property values if (product.PropertyValues != null) { foreach (var propValue in product.PropertyValues.Select(x=>x.ToWebModel())) { var property = retVal.Properties.FirstOrDefault(x => x.Id == propValue.PropertyId); if (property == null) { //Need add dummy property for each value without property property = new webModel.Property(propValue, product.CatalogId, product.CategoryId, moduleModel.PropertyType.Product); retVal.Properties.Add(property); } property.Values.Add(propValue); } } return retVal; }