コード例 #1
0
        public void Update(Category category, List<ProductSortData> productSortData)
        {
            var categoryProductDisplayOrders =
                _session.QueryOver<CategoryProductDisplayOrder>()
                    .Where(order => order.Category.Id == category.Id)
                    .Cacheable()
                    .List();

            using (new NotificationDisabler())
            {
                _session.Transact(session =>
                {
                    foreach (var sortData in productSortData)
                    {
                        var displayOrder =
                            categoryProductDisplayOrders.FirstOrDefault(order => order.Product.Id == sortData.Id);
                        if (displayOrder != null)
                        {
                            displayOrder.DisplayOrder = sortData.DisplayOrder;
                            session.Update(displayOrder);
                            continue;
                        }
                        displayOrder = new CategoryProductDisplayOrder
                        {
                            Category = category,
                            Product = session.Get<Product>(sortData.Id),
                            DisplayOrder = sortData.DisplayOrder
                        };
                        session.Save(displayOrder);
                    }
                });
            }
        }
コード例 #2
0
ファイル: ImportCategories.cs プロジェクト: neozhu/Ecommerce
 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);
     }
 }
コード例 #3
0
        public List<ProductSortData> GetProductSortData(Category category)
        {
            if (category == null)
                return new List<ProductSortData>();
            var products = GetProducts(category);
            ProductSortData productSortDataAlias = null;
            Product productAlias = null;
            var orders =
                _session.QueryOver<CategoryProductDisplayOrder>().Where(order => order.Category.Id == category.Id)
                .JoinAlias(order => order.Product, () => productAlias)
                    .OrderBy(order => order.DisplayOrder).Asc.SelectList(builder =>
                        builder
                            .Select(order => order.DisplayOrder)
                            .WithAlias(() => productSortDataAlias.DisplayOrder)
                            .Select(order => productAlias.Id)
                            .WithAlias(() => productSortDataAlias.Id)
                            .Select(order => productAlias.Name)
                            .WithAlias(() => productSortDataAlias.Name))
                    .TransformUsing(Transformers.AliasToBean<ProductSortData>())
                    .List<ProductSortData>().ToHashSet();

            return products.Select(product => orders.FirstOrDefault(order => order.Id == product.Id)
                                              ??
                                              new ProductSortData
                                              {
                                                  Id = product.Id,
                                                  Name = product.Name,
                                                  DisplayOrder = products.Count
                                              }).OrderBy(data => data.DisplayOrder).ToList();
        }
コード例 #4
0
 public bool IsSorted(Category category)
 {
     return
         _session.QueryOver<CategoryProductDisplayOrder>()
             .Where(order => order.Category.Id == category.Id)
             .Cacheable()
             .Any();
 }
コード例 #5
0
        public void OptionService_GetCategoryOptions_ShouldReturnAtLeaseOneItem()
        {
            var category = new Category() {Name = "Cat"};
            Session.Transact(session => session.Save(category));

            var result = _optionService.GetCategoryOptions();

            result.Count.Should().BeGreaterThan(0);
        }
コード例 #6
0
        private List<Product> GetProducts(Category category)
        {
            var booleanQuery = new BooleanQuery
            {
                {
                    new TermQuery(new Term(FieldDefinition.GetFieldName<ProductSearchCategoriesDefinition>(),
                        category.Id.ToString())),
                    Occur.MUST
                }
            };

            return _productSearcher.Search(booleanQuery, 1, int.MaxValue).ToList();
        }
コード例 #7
0
        public void ImportProductsService_ImportProducts_ShouldSetCategoriesIfTheyExist()
        {
            var productDTO = new ProductImportDataTransferObject
            {
                UrlSegment = "test-url",
                Categories = new List<string> {"test-category"}
            };

            var category = new Category {Id = 1, Name = "Test Category"};
            A.CallTo(() => _documentService.GetDocument<Category>(1)).Returns(category);

            var product = new Product {Name = "Test Product"};
            A.CallTo(() => _documentService.GetDocumentByUrl<Product>(productDTO.UrlSegment)).Returns(product);

            Product importProduct = _importProductsService.ImportProduct(productDTO);

            importProduct.Categories.Should().HaveCount(1);
        }
コード例 #8
0
 public void ClearSorting(Category category)
 {
     using (new NotificationDisabler())
     {
         _session.Transact(session =>
         {
             var orders =
                 _session.QueryOver<CategoryProductDisplayOrder>()
                     .Where(order => order.Category.Id == category.Id)
                     .Cacheable()
                     .List();
             foreach (var order in orders)
             {
                 session.Delete(order);
             }
         });
     }
 }
コード例 #9
0
ファイル: CategoryService.cs プロジェクト: neozhu/Ecommerce
 public IList<Category> GetSubCategories(Category category)
 {
     return _session.QueryOver<Category>().Where(x => x.Parent.Id == category.Id && x.PublishOn <= CurrentRequestData.Now).Cacheable().List();
 }
コード例 #10
0
        public void ProductController_RemoveCategory_SetsViewDataForCategory()
        {
            var product = new Product {Id = 123};
            var category = new Category();
            A.CallTo(() => _documentService.GetDocument<Category>(1)).Returns(category);

            PartialViewResult result = _productController.RemoveCategory(product, 1);

            _productController.ViewData["category"].Should().Be(category);
        }