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 product = new PostProductObject() { Name = name }; var productId = _nopService.CreateProduct(product); return(productId); }
public string Create([System.Web.Http.FromBody] string name) { var storeId = GlobalSettings.UmbracoSettings.NopStoreId; var isCreateProductLimitToStore = GlobalSettings.UmbracoSettings.CreateProductLimitToStore; var product = new PostProductObject() { Name = name }; if (storeId != 0 && isCreateProductLimitToStore) { product.StoreIds = new[] { storeId } } ; var productId = _nopService.CreateProduct(product); return(productId); }