private void ContentService_Saved(IContentService sender, SaveEventArgs <IContent> e) { if (_autoCreateNopItem) { foreach (var entity in e.SavedEntities) { if (entity.ContentType.Alias == GlobalSettings.UmbracoSettings.CategoryDocumentTypeAlias) { LogHelper.Info <Startup>($"Creating new category [{entity.Name}] in nopCommerce"); if (string.IsNullOrEmpty(entity.GetValue <string>(GlobalSettings.UmbracoSettings.CategoryIdPropertyAlias))) { var category = new PostCategoryObject() { Name = entity.Name }; var categoryId = _nopService.CreateCategory(category); entity.SetValue(GlobalSettings.UmbracoSettings.CategoryIdPropertyAlias, categoryId); LogHelper.Info <Startup>($"Category [{entity.Name}] created, NopId is [{categoryId}]"); } else { LogHelper.Info <Startup>($"Category [{entity.Name}] was skipped"); } } if (entity.ContentType.Alias == GlobalSettings.UmbracoSettings.ProductDocumentTypeAlias) { LogHelper.Info <Startup>($"Creating new product [{entity.Name}] in nopCommerce"); if (string.IsNullOrEmpty(entity.GetValue <string>(GlobalSettings.UmbracoSettings.ProductIdPropertyAlias))) { var product = new PostProductObject() { Name = entity.Name }; var productId = _nopService.CreateProduct(product); entity.SetValue(GlobalSettings.UmbracoSettings.ProductIdPropertyAlias, productId); LogHelper.Info <Startup>($"Product [{entity.Name}] created, NopId is [{productId}]"); } else { LogHelper.Info <Startup>($"Poduct [{entity.Name}] was skipped"); } } } } }
public string Create([System.Web.Http.FromBody] string name) { var category = new PostCategoryObject() { Name = name }; var categoryId = _nopService.CreateCategory(category); return(categoryId); }
public string Create([System.Web.Http.FromBody] string name) { var storeId = GlobalSettings.UmbracoSettings.NopStoreId; var isCreateProductLimitToStore = GlobalSettings.UmbracoSettings.CreateProductLimitToStore; var category = new PostCategoryObject() { Name = name }; if (storeId != 0 && isCreateProductLimitToStore) { category.StoreIds = new[] { storeId } } ; var categoryId = _nopService.CreateCategory(category); return(categoryId); }