Example #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);
            }
        }
Example #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));
        }
        public void WebpageController_SuggestDocumentUrl_ShouldCallGetDocumentUrl()
        {
            var textPage = new TextPage();

            var suggestParams = new SuggestParams();

            _webpageUrlController.Suggest(textPage, suggestParams);

            A.CallTo(() => _webpageUrlService.Suggest(textPage, suggestParams)).MustHaveHappened();
        }
        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");
        }
Example #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;
        }
        public override object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
        {
            SuggestParams model = base.BindModel(controllerContext, bindingContext) as SuggestParams;

            if (model == null)
            {
                return(null);
            }

            string documentType = model.DocumentType;

            string[] parts = documentType.Split(new[] { "-" }, StringSplitOptions.RemoveEmptyEntries);
            if (parts.Count() == 1)
            {
                return(model);
            }
            model.DocumentType = parts[0];
            int id;

            model.Template = int.TryParse(parts[1], out id) ? id : (int?)null;
            return(model);
        }
Example #7
0
 public string Suggest(Webpage parent, [IoCModelBinder(typeof(SuggestParamsModelBinder))] SuggestParams suggestParams)
 {
     return(_webpageUrlService.Suggest(parent, suggestParams));
 }