public async Task <IViewComponentResult> InvokeAsync(int?productThumbPictureSize, bool?preparePriceModel)
        {
            if (!_catalogSettings.RecentlyViewedProductsEnabled)
            {
                return(Content(""));
            }

            var preparePictureModel = productThumbPictureSize.HasValue;
            var products            = await(await _recentlyViewedProductsService.GetRecentlyViewedProductsAsync(_catalogSettings.RecentlyViewedProductsNumber))
                                      //ACL and store mapping
                                      .WhereAwait(async p => await _aclService.AuthorizeAsync(p) && await _storeMappingService.AuthorizeAsync(p))
                                      //availability dates
                                      .Where(p => _productService.ProductIsAvailable(p)).ToListAsync();

            if (!products.Any())
            {
                return(Content(""));
            }

            //prepare model
            var model = new List <ProductOverviewModel>();

            model.AddRange(await _productModelFactory.PrepareProductOverviewModelsAsync(products,
                                                                                        preparePriceModel.GetValueOrDefault(),
                                                                                        preparePictureModel,
                                                                                        productThumbPictureSize));

            return(View(model));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> RecentlyViewedProducts()
        {
            if (!_catalogSettings.RecentlyViewedProductsEnabled || _catalogSettings.RecentlyViewedProductsNumber <= 0)
            {
                return(View(ProductSummaryModel.Empty));
            }

            var products = await _recentlyViewedProductsService.GetRecentlyViewedProductsAsync(_catalogSettings.RecentlyViewedProductsNumber);

            var settings = _helper.GetBestFitProductSummaryMappingSettings(ProductSummaryViewMode.List);
            var model    = await _helper.MapProductSummaryModelAsync(products, settings);

            return(View(model));
        }
        /// <returns>A task that represents the asynchronous operation</returns>
        public virtual async Task <IActionResult> RecentlyViewedProducts()
        {
            if (!_catalogSettings.RecentlyViewedProductsEnabled)
            {
                return(Content(""));
            }

            var products = await _recentlyViewedProductsService.GetRecentlyViewedProductsAsync(_catalogSettings.RecentlyViewedProductsNumber);

            var model = new List <ProductOverviewModel>();

            model.AddRange(await _productModelFactory.PrepareProductOverviewModelsAsync(products));

            return(View(model));
        }
        public async Task <IViewComponentResult> InvokeAsync()
        {
            if (!_catalogSettings.RecentlyViewedProductsEnabled)
            {
                return(Empty());
            }

            var products = await _recentlyViewedProductsService.GetRecentlyViewedProductsAsync(_catalogSettings.RecentlyViewedProductsNumber);

            if (products.Count == 0)
            {
                return(Empty());
            }

            var settings = _catalogHelper.GetBestFitProductSummaryMappingSettings(ProductSummaryViewMode.Mini, x =>
            {
                x.MapManufacturers = _catalogSettings.ShowManufacturerInGridStyleLists;
            });

            var model = await _catalogHelper.MapProductSummaryModelAsync(products, settings);

            return(View(model));
        }