private string GetNewUrl(MoveWebpageModel model, Webpage parent, Webpage page, Webpage immediateParent, MoveWebpageChangedPageModel parentModel) { if (!model.UpdateUrls) { return(page.UrlSegment); } if (immediateParent == null) { return(_webpageUrlService.Suggest(parent, new SuggestParams { DocumentType = page.DocumentType, PageName = page.Name, Template = page.PageTemplate?.Id, UseHierarchy = true, WebpageId = page.Id })); } return(_webpageUrlService.Suggest(immediateParent, new SuggestParams { DocumentType = page.DocumentType, PageName = $"{parentModel.NewUrl}/{page.Name}", Template = page.PageTemplate?.Id, UseHierarchy = false, WebpageId = page.Id })); }
public void WebpageController_SuggestDocumentUrl_ShouldCallGetDocumentUrl() { var textPage = new TextPage(); var suggestParams = new SuggestParams(); _webpageUrlController.Suggest(textPage, suggestParams); A.CallTo(() => _webpageUrlService.Suggest(textPage, suggestParams)).MustHaveHappened(); }
private void UpdateCategory(ISession session, CategoryData categoryData, Webpage parent, HashSet <CategoryData> allData, NopImportContext nopImportContext) { CategoryData data = categoryData; var suggestParams = new SuggestParams { DocumentType = typeof(Category).FullName, PageName = data.Name, UseHierarchy = true }; var category = new Category { Name = data.Name, UrlSegment = string.IsNullOrWhiteSpace(data.Url) ? _webpageUrlService.Suggest(parent, suggestParams) : data.Url, Parent = parent, CategoryAbstract = data.Abstract.LimitCharacters(500), PublishOn = data.Published ? CurrentRequestData.Now.Date : (DateTime?)null, RevealInNavigation = true }; var mediaFile = nopImportContext.FindNew <MediaFile>(data.PictureId); if (mediaFile != null) { category.FeatureImage = mediaFile.FileUrl; } session.Save(category); nopImportContext.AddEntry(data.Id, category); List <CategoryData> children = allData.Where(d => d.ParentId == data.Id).ToList(); foreach (CategoryData child in children) { UpdateCategory(session, child, category, allData, nopImportContext); } }
public string ProcessProducts(NopCommerceDataReader dataReader, NopImportContext nopImportContext) { HashSet <ProductData> productDatas = dataReader.GetProducts(); HashSet <ProductOptionValueData> optionValues = dataReader.GetProductOptionValues(); HashSet <ProductSpecificationValueData> specificationValues = dataReader.GetProductSpecificationValues(); var productContainer = _uniquePageService.GetUniquePage <ProductContainer>(); _session.Transact(session => { foreach (ProductData productData in productDatas) { var suggestParams = new SuggestParams { DocumentType = typeof(Product).FullName, PageName = productData.Name, UseHierarchy = true }; var product = new Product { Name = productData.Name, ProductAbstract = productData.Abstract.LimitCharacters(500), BodyContent = productData.Description, Parent = productContainer, UrlSegment = string.IsNullOrWhiteSpace(productData.Url) ? _webpageUrlService.Suggest(productContainer, suggestParams) : productData.Url, BrandPage = productData.BrandId.HasValue ? nopImportContext.FindNew <Brand>(productData.BrandId.Value) : null, Categories = productData.Categories.Select(nopImportContext.FindNew <Category>).ToList(), Tags = new HashSet <Tag>(productData.Tags.Select(nopImportContext.FindNew <Tag>).ToList()), PublishOn = productData.Published ? CurrentRequestData.Now.Date : (DateTime?)null }; SetSpecificationValues(nopImportContext, specificationValues.FindAll(data => data.ProductId == productData.Id), product); _importProductVariants.CreateProductVariants(nopImportContext, productData.ProductVariants, optionValues, product); session.Save(product); var pictureIds = productData.Pictures; foreach (var pictureId in pictureIds) { var mediaFile = nopImportContext.FindNew <MediaFile>(pictureId); if (mediaFile != null) { mediaFile.MediaCategory = product.Gallery; session.Update(mediaFile); } } } }); return(string.Format("{0} products processed.", productDatas.Count)); }
public Brand Get(string name, string logo = null) { var listing = _uniquePageService.GetUniquePage <BrandListing>(); return(new Brand { Name = name, UrlSegment = _webpageUrlService.Suggest(listing, new SuggestParams { DocumentType = typeof(Brand).FullName, PageName = name, UseHierarchy = true }), FeatureImage = logo, PublishOn = CurrentRequestData.Now, Published = true, Parent = listing, RevealInNavigation = false }); }
private DocumentImportDTO GetDocumentImportDataTransferObject(ExcelWorksheet worksheet, int rowId, string name, ref List <string> parseErrors) { DocumentImportDTO item = new DocumentImportDTO(); item.ParentUrl = worksheet.GetValue <string>(rowId, 2); if (worksheet.GetValue <string>(rowId, 3).HasValue()) { item.DocumentType = worksheet.GetValue <string>(rowId, 3); item.UrlSegment = worksheet.GetValue <string>(rowId, 1).HasValue() ? worksheet.GetValue <string>(rowId, 1) : _webpageUrlService.Suggest(null, new SuggestParams { PageName = name, DocumentType = item.DocumentType }); } else { parseErrors.Add("Document Type is required."); } if (worksheet.GetValue <string>(rowId, 4).HasValue()) { item.Name = worksheet.GetValue <string>(rowId, 4); } else { parseErrors.Add("Document Name is required."); } item.BodyContent = worksheet.GetValue <string>(rowId, 5); item.MetaTitle = worksheet.GetValue <string>(rowId, 6); item.MetaDescription = worksheet.GetValue <string>(rowId, 7); item.MetaKeywords = worksheet.GetValue <string>(rowId, 8); item.Tags = GetTags(worksheet, rowId, parseErrors); if (worksheet.GetValue <string>(rowId, 10).HasValue()) { if (!worksheet.GetValue <string>(rowId, 10).IsValidInput <bool>()) { parseErrors.Add("Reveal in Navigation is not a valid boolean value."); } else { item.RevealInNavigation = worksheet.GetValue <bool>(rowId, 10); } } else { item.RevealInNavigation = false; } if (worksheet.GetValue <string>(rowId, 11).HasValue()) { if (!worksheet.GetValue <string>(rowId, 11).IsValidInput <int>()) { parseErrors.Add("Display Order is not a valid number."); } else { item.DisplayOrder = worksheet.GetValue <int>(rowId, 11); } } else { item.DisplayOrder = 0; } if (worksheet.GetValue <string>(rowId, 12).HasValue()) { if (!worksheet.GetValue <string>(rowId, 12).IsValidInput <bool>()) { parseErrors.Add("Require SSL is not a valid boolean value."); } else { item.RequireSSL = worksheet.GetValue <bool>(rowId, 12); } } else { item.RequireSSL = false; } if (worksheet.GetValue <string>(rowId, 13).HasValue()) { if (!worksheet.GetValue <string>(rowId, 13).IsValidInputDateTime()) { parseErrors.Add("Publish Date is not a valid date."); } else { item.PublishDate = worksheet.GetValue <DateTime>(rowId, 13); } } item.UrlHistory = GetUrlHistory(worksheet, rowId, parseErrors); return(item); }
public string Suggest(Webpage parent, [IoCModelBinder(typeof(SuggestParamsModelBinder))] SuggestParams suggestParams) { return(_webpageUrlService.Suggest(parent, suggestParams)); }
protected override BatchJobExecutionResult OnExecute(ImportDocumentBatchJob batchJob) { using (EventContext.Instance.Disable <IOnTransientNotificationPublished>()) using (EventContext.Instance.Disable <IOnPersistentNotificationPublished>()) using (EventContext.Instance.Disable <UpdateIndicesListener>()) using (EventContext.Instance.Disable <UpdateUniversalSearch>()) using (EventContext.Instance.Disable <WebpageUpdatedNotification>()) using (EventContext.Instance.Disable <DocumentAddedNotification>()) using (EventContext.Instance.Disable <MediaCategoryUpdatedNotification>()) { var documentImportDto = batchJob.DocumentImportDto; var webpage = GetWebpageByUrl(documentImportDto.UrlSegment); var isNew = webpage == null; if (isNew) { webpage = (Webpage) Activator.CreateInstance(DocumentMetadataHelper.GetTypeByName(documentImportDto.DocumentType)); } if (!String.IsNullOrEmpty(documentImportDto.ParentUrl)) { var parent = GetWebpageByUrl(documentImportDto.ParentUrl); webpage.Parent = parent; } if (!string.IsNullOrWhiteSpace(documentImportDto.UrlSegment) && isNew) { webpage.UrlSegment = _webpageUrlService.Suggest(null, new SuggestParams { DocumentType = documentImportDto.DocumentType, PageName = documentImportDto.Name }); } webpage.Name = documentImportDto.Name; webpage.BodyContent = documentImportDto.BodyContent; webpage.MetaTitle = documentImportDto.MetaTitle; webpage.MetaDescription = documentImportDto.MetaDescription; webpage.MetaKeywords = documentImportDto.MetaKeywords; webpage.RevealInNavigation = documentImportDto.RevealInNavigation; webpage.RequiresSSL = documentImportDto.RequireSSL; webpage.DisplayOrder = documentImportDto.DisplayOrder; webpage.PublishOn = documentImportDto.PublishDate; _updateTagsService.SetTags(documentImportDto, webpage); _updateUrlHistoryService.SetUrlHistory(documentImportDto, webpage); _session.Transact(session => { if (isNew) { session.Save(webpage); } else { session.Update(webpage); } }); return(BatchJobExecutionResult.Success()); } }
/// <summary> /// Validate And Import Products With Variants /// </summary> /// <param name="spreadsheet"></param> /// <param name="parseErrors"></param> /// <returns></returns> public HashSet <ProductImportDataTransferObject> ValidateAndImportProductsWithVariants(ExcelPackage spreadsheet, ref Dictionary <string, List <string> > parseErrors) { var productsToImport = new HashSet <ProductImportDataTransferObject>(); if (!parseErrors.Any()) { if (spreadsheet != null) { if (spreadsheet.Workbook != null) { var worksheet = spreadsheet.Workbook.Worksheets.SingleOrDefault(x => x.Name == "Items"); if (worksheet != null) { var totalRows = worksheet.Dimension.End.Row; for (var rowId = 2; rowId <= totalRows; rowId++) { if (!worksheet.GetValue <string>(rowId, 1).HasValue() && !worksheet.GetValue <string>(rowId, 2).HasValue() && !worksheet.GetValue <string>(rowId, 3).HasValue()) { continue; } var product = new ProductImportDataTransferObject(); //Prepare handle name for storing and grouping errors string url = worksheet.GetValue <string>(rowId, 1), name = worksheet.GetValue <string>(rowId, 2); var handle = url.HasValue() ? url : SeoHelper.TidyUrl(name); if (!productsToImport.Any(x => x.Name == name || x.UrlSegment == url)) { if (parseErrors.All(x => x.Key != handle)) { parseErrors.Add(handle, new List <string>()); } product.UrlSegment = worksheet.GetValue <string>(rowId, 1).HasValue() ? worksheet.GetValue <string>(rowId, 1) : _urlService.Suggest(null, new SuggestParams { PageName = name, DocumentType = typeof(Product).FullName }); //skip duplicate url if (productsToImport.Any(x => x.UrlSegment == product.UrlSegment)) { continue; } GetBasicData(parseErrors, worksheet, rowId, product, handle); GetCategories(parseErrors, worksheet, rowId, product, handle); GetSpecifications(parseErrors, worksheet, rowId, handle, product); GetImages(worksheet, rowId, product); GetUrlHistory(parseErrors, worksheet, rowId, product, handle); productsToImport.Add(product); } else { product = !string.IsNullOrWhiteSpace(url) ? productsToImport.SingleOrDefault(x => x.Name == name && x.UrlSegment == url) : productsToImport.SingleOrDefault(x => x.Name == name); } //Variants if (product != null) { var productVariant = GetProductVariant(parseErrors, worksheet, rowId, handle); if (productVariant != null) { //Options GetProductVariantOptions(worksheet, rowId, productVariant); //Price Breaks GetPriceBreaks(parseErrors, worksheet, rowId, handle, productVariant); product.ProductVariants.Add(productVariant); } } } } } } //Remove handles with no errors parseErrors = parseErrors.Where(x => x.Value.Any()).ToDictionary(pair => pair.Key, pair => pair.Value); } var i = productsToImport.Where(x => x.ProductVariants.Count == 0).ToList(); return(productsToImport); }