public IViewComponentResult Invoke(string productId, int?productThumbPictureSize)
        {
            if (!_catalogSettings.ProductsAlsoPurchasedEnabled)
            {
                return(Content(""));
            }

            //load and cache report
            var productIds = _cacheManager.Get(string.Format(ModelCacheEventConsumer.PRODUCTS_ALSO_PURCHASED_IDS_KEY, productId, _storeContext.CurrentStore.Id),
                                               () =>
                                               _orderReportService
                                               .GetAlsoPurchasedProductsIds(_storeContext.CurrentStore.Id, productId, _catalogSettings.ProductsAlsoPurchasedNumber)
                                               );

            //load products
            var products = _productService.GetProductsByIds(productIds);

            //ACL and store mapping
            products = products.Where(p => _aclService.Authorize(p) && _storeMappingService.Authorize(p)).ToList();
            //availability dates
            products = products.Where(p => p.IsAvailable()).ToList();

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

            //prepare model
            var model = _productViewModelService.PrepareProductOverviewModels(products, true, true, productThumbPictureSize).ToList();

            return(View(model));
        }
Esempio n. 2
0
        public IViewComponentResult Invoke(int?productThumbPictureSize)
        {
            if (!_catalogSettings.ShowBestsellersOnHomepage || _catalogSettings.NumberOfBestsellersOnHomepage == 0)
            {
                return(Content(""));
            }

            //load and cache report
            var report = _cacheManager.Get(string.Format(ModelCacheEventConsumer.HOMEPAGE_BESTSELLERS_IDS_KEY, _storeContext.CurrentStore.Id),
                                           () => _orderReportService.BestSellersReport(
                                               storeId: _storeContext.CurrentStore.Id,
                                               pageSize: _catalogSettings.NumberOfBestsellersOnHomepage)
                                           .ToList());


            //load products
            var products = _productService.GetProductsByIds(report.Select(x => x.ProductId).ToArray());

            //ACL and store mapping
            products = products.Where(p => _aclService.Authorize(p) && _storeMappingService.Authorize(p)).ToList();
            //availability dates
            products = products.Where(p => p.IsAvailable()).ToList();

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

            //prepare model
            var model = _productViewModelService.PrepareProductOverviewModels(products, true, true, productThumbPictureSize).ToList();

            return(View(model));
        }
        public IViewComponentResult Invoke(int?productThumbPictureSize)
        {
            if (!_catalogSettings.RecommendedProductsEnabled)
            {
                return(Content(""));
            }

            var products = _productService.GetRecommendedProducts(_workContext.CurrentCustomer.GetCustomerRoleIds());

            //ACL and store mapping
            products = products.Where(p => _aclService.Authorize(p) && _storeMappingService.Authorize(p)).ToList();

            //availability dates
            products = products.Where(p => p.IsAvailable()).ToList();

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

            //prepare model
            var model = _productViewModelService.PrepareProductOverviewModels(products, true, true, productThumbPictureSize).ToList();

            return(View(model));
        }
Esempio n. 4
0
        public IViewComponentResult Invoke(int?productThumbPictureSize)
        {
            var cart = _workContext.CurrentCustomer.ShoppingCartItems
                       .Where(sci => sci.ShoppingCartType == ShoppingCartType.ShoppingCart)
                       .LimitPerStore(_storeContext.CurrentStore.Id)
                       .ToList();

            var products = _productService.GetCrosssellProductsByShoppingCart(cart, _shoppingCartSettings.CrossSellsNumber);

            //ACL and store mapping
            products = products.Where(p => _aclService.Authorize(p) && _storeMappingService.Authorize(p)).ToList();
            //availability dates
            products = products.Where(p => p.IsAvailable()).ToList();

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

            var model = _productViewModelService.PrepareProductOverviewModels(products,
                                                                              productThumbPictureSize: productThumbPictureSize, forceRedirectionAfterAddingToCart: true)
                        .ToList();

            return(View(model));
        }
Esempio n. 5
0
        public IViewComponentResult Invoke(string productId, int?productThumbPictureSize)
        {
            //load and cache report
            var productIds = _cacheManager.Get(string.Format(ModelCacheEventConsumer.PRODUCTS_RELATED_IDS_KEY, productId, _storeContext.CurrentStore.Id),
                                               () =>
                                               _productService.GetProductById(productId).RelatedProducts.Select(x => x.ProductId2).ToArray()
                                               );

            //load products
            var products = _productService.GetProductsByIds(productIds);

            //ACL and store mapping
            products = products.Where(p => _aclService.Authorize(p) && _storeMappingService.Authorize(p)).ToList();
            //availability dates
            products = products.Where(p => p.IsAvailable()).ToList();

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

            var model = _productViewModelService.PrepareProductOverviewModels(products, true, true, productThumbPictureSize).ToList();

            return(View(model));
        }
Esempio n. 6
0
        public IViewComponentResult Invoke(int?productThumbPictureSize)
        {
            var products = _productService.GetAllProductsDisplayedOnHomePage();

            //ACL and store mapping
            products = products.Where(p => _aclService.Authorize(p) && _storeMappingService.Authorize(p)).ToList();
            //availability dates
            products = products.Where(p => p.IsAvailable()).ToList();

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

            var model = _productViewModelService.PrepareProductOverviewModels(products, true, true, productThumbPictureSize).ToList();

            return(View(model));
        }