예제 #1
0
 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);
     }
 }
예제 #2
0
        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);
        }
예제 #3
0
        public void WebpageController_SuggestDocumentUrl_ShouldCallGetDocumentUrl()
        {
            var textPage = new TextPage();

            var suggestParams = new SuggestParams();
            _webpageUrlController.Suggest(textPage, suggestParams);

            A.CallTo(() => _webpageUrlService.Suggest(textPage,suggestParams)).MustHaveHappened();
        }
예제 #4
0
        public void WebpageController_SuggestDocumentUrl_ShouldReturnTheResultOfGetDocumentUrl()
        {
            var textPage = new TextPage();
            var suggestParams = new SuggestParams();
            A.CallTo(() => _webpageUrlService.Suggest(textPage, suggestParams)).Returns("test/result");

            string url = _webpageUrlController.Suggest(textPage, suggestParams);

            url.Should().BeEquivalentTo("test/result");
        }
예제 #5
0
        public string Suggest(Webpage parent,SuggestParams suggestParams)
        {
            IWebpageUrlGenerator generator = GetGenerator(suggestParams.DocumentType, suggestParams.Template);

            string url = generator.GetUrl(suggestParams.PageName, parent, suggestParams.UseHierarchy);

            //make sure the URL is unique

            if (!_urlValidationService.UrlIsValidForWebpage(url, null))
            {
                int counter = 1;

                while (!_urlValidationService.UrlIsValidForWebpage(string.Format("{0}-{1}", url, counter), null))
                    counter++;

                url = string.Format("{0}-{1}", url, counter);
            }
            return url;
        }