Ejemplo n.º 1
0
        public ActionResult ProductsAlsoPurchased(int productId, int?productThumbPictureSize)
        {
            if (!_catalogSettings.ProductsAlsoPurchasedEnabled)
            {
                return(Content(""));
            }

            // load and cache report
            var productIds = _services.Cache.Get(string.Format(ModelCacheEventConsumer.PRODUCTS_ALSO_PURCHASED_IDS_KEY, productId, _services.StoreContext.CurrentStore.Id), () =>
            {
                return(_orderReportService.GetAlsoPurchasedProductsIds(_services.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();

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

            // Prepare model
            var settings = _helper.GetBestFitProductSummaryMappingSettings(ProductSummaryViewMode.Mini, x =>
            {
                x.ThumbnailSize = productThumbPictureSize;
            });

            var model = _helper.MapProductSummaryModel(products, settings);

            return(PartialView("Product.AlsoPurchased", model));
        }
Ejemplo n.º 2
0
        public async Task <IViewComponentResult> InvokeAsync(string productId, int?productThumbPictureSize)
        {
            if (!_catalogSettings.ProductsAlsoPurchasedEnabled)
            {
                return(Content(""));
            }

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

            //load products
            var products = await _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 = await _productViewModelService.PrepareProductOverviewModels(products, true, true, productThumbPictureSize);

            return(View(model));
        }
Ejemplo n.º 3
0
        public IViewComponentResult Invoke(int productId, int?productThumbPictureSize)
        {
            if (!_catalogSettings.ProductsAlsoPurchasedEnabled)
            {
                return(Content(""));
            }

            //load and cache report
            var productIds = _cacheManager.Get(string.Format(NopModelCacheDefaults.ProductsAlsoPurchasedIdsKey, 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 => _productService.ProductIsAvailable(p)).ToList();

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

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

            return(View(model));
        }
Ejemplo n.º 4
0
        public ActionResult ProductsAlsoPurchased(int 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();

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

            //prepare model
            var model = _productModelFactory.PrepareProductOverviewModels(products).ToList();

            return(PartialView("QuickViewProductsAlsoPurchased", model));
        }