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)); }
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 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 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)); }
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 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 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); }