/// <summary>
        /// Build the product block view model
        /// </summary>
        /// <param name="blockModel">The current product block</param>
        /// <returns>Return the product block view model</returns>
        public virtual ProductBlockViewModel Build(BlockModel blockModel)
        {
            var data      = blockModel.MapTo <ProductBlockViewModelData>();
            var viewModel = new ProductBlockViewModel();
            var channel   = _requestModelAccessor.RequestModel.ChannelModel.Channel;

            if (data != null)
            {
                viewModel.FooterLinkText = data.LinkText;
                if (data.LinkToCategorySystemId != Guid.Empty)
                {
                    viewModel.FooterLinkUrl = data.LinkToCategorySystemId.MapTo <Category>().GetUrl(_requestModelAccessor.RequestModel.ChannelModel.SystemId, true);
                }
                else if (!string.IsNullOrEmpty(data.LinkToPage.Href))
                {
                    viewModel.FooterLinkUrl = data.LinkToPage.Href;
                }

                viewModel.Title = data.Title;

                var products = new List <ProductModel>();
                if (data.SectionProductsType == BlockProductsType.Products)
                {
                    products.AddRange(data.ProductSystemIds.Select(x => _productModelBuilder.BuildFromVariant(_variantService.Get(x)) ?? _productModelBuilder.BuildFromBaseProduct(_baseProductService.Get(x), channel)).Where(x => x != null));
                }
                else
                {
                    var searchQuery = new SearchQuery
                    {
                        PageSize = data.NumberOfProducts
                    };

                    switch (data.SectionProductsType)
                    {
                    case BlockProductsType.Category:
                        searchQuery.CategoryShowRecursively = true;
                        searchQuery.SortBy           = data.ProductSorting;
                        searchQuery.CategorySystemId = data.CategorySystemId;
                        break;

                    case BlockProductsType.ProductList:
                        searchQuery.ProductListSystemId = data.ProductListSystemId;
                        break;
                    }
                    var response = _productSearchService.Search(searchQuery);
                    if (response?.Hits != null)
                    {
                        products.AddRange(_productSearchService
                                          .Transform(searchQuery, response)
                                          .Items
                                          .Value
                                          .OfType <ProductSearchResult>()
                                          .Select(x => x.Item));
                    }
                }

                viewModel.Products = products.Select(x => _productItemViewModelBuilder.Build(x)).ToList();
            }
            return(viewModel);
        }
        /// <summary>
        /// Build the mixed block view model
        /// </summary>
        /// <param name="blockModel">The current mixed block</param>
        /// <returns>Return the mixed block view model</returns>
        public virtual ProductsAndBannerBlockViewModel Build(BlockModel blockModel)
        {
            var sectionBanners  = _bannersViewModelBuilder.Build(blockModel);
            var sectionProducts = _productViewModelBuilder.Build(blockModel);

            var mixedBlockViewModel = blockModel.MapTo <ProductsAndBannerBlockViewModel>();

            mixedBlockViewModel.Products = sectionProducts;
            mixedBlockViewModel.Banners  = sectionBanners;
            return(mixedBlockViewModel);
        }
Пример #3
0
        /// <summary>
        /// Build the mixed block view model
        /// </summary>
        /// <param name="blockModel">The current mixed block</param>
        /// <returns>Return the mixed block view model</returns>
        public virtual async Task <ProductsAndBannerBlockViewModel> BuildAsync(BlockModel blockModel)
        {
            var sectionBanners  = _bannersViewModelBuilder.Build(blockModel);
            var sectionProducts = await _productViewModelBuilder.BuildAsync(blockModel);

            var mixedBlockViewModel = blockModel.MapTo <ProductsAndBannerBlockViewModel>();

            mixedBlockViewModel.Products = sectionProducts;
            mixedBlockViewModel.Products.FooterLinkText = mixedBlockViewModel.ProductLinkText;

            mixedBlockViewModel.Banners = sectionBanners;
            return(mixedBlockViewModel);
        }
 /// <summary>
 /// Build the video block view model
 /// </summary>
 /// <param name="blockModel">The current block</param>
 /// <returns>Return the video block view model</returns>
 public virtual VideoBlockViewModel Build(BlockModel blockModel)
 {
     return(blockModel.MapTo <VideoBlockViewModel>());
 }
Пример #5
0
 /// <summary>
 /// Build the banner block view model
 /// </summary>
 /// <param name="blockModel">The current banner block banner</param>
 /// <returns>Return the banner block view model</returns>
 public virtual BannersBlockViewModel Build(BlockModel blockModel)
 {
     return(blockModel.MapTo <BannersBlockViewModel>());
 }
 /// <summary>
 /// Build the slideshow block view model
 /// </summary>
 /// <param name="blockModel">The current block</param>
 /// <returns>Return the slideshow block view model</returns>
 public virtual SliderBlockViewModel Build(BlockModel blockModel)
 {
     return(blockModel.MapTo <SliderBlockViewModel>());
 }