Esempio n. 1
0
        // TODO Number of items to config
        public IViewComponentResult Invoke(long?productId, int itemCount = 5)
        {
            var user = _workContext.GetCurrentUser().Result;
            IQueryable <Product> query = _productRepository.GetRecentlyViewedProduct(user.Id)
                                         .Include(x => x.ThumbnailImage);

            if (productId.HasValue)
            {
                query = query.Where(x => x.Id != productId.Value);
            }

            var model = query.Take(itemCount)
                        .Select(x => ProductThumbnail.FromProduct(x)).ToList();

            foreach (var product in model)
            {
                product.ThumbnailUrl           = _mediaService.GetThumbnailUrl(product.ThumbnailImage);
                product.CalculatedProductPrice = _productPricingService.CalculateProductPrice(product);
            }

            return(View(this.GetViewPath(), model));
        }
Esempio n. 2
0
        // TODO Number of items to config
        public IViewComponentResult Invoke(long?productId)
        {
            var user = _workContext.GetCurrentUser().Result;
            IQueryable <Product> query = _productRepository.GetRecentlyViewedProduct(user.Id)
                                         .Include(x => x.ThumbnailImage);

            if (productId.HasValue)
            {
                query = query.Where(x => x.Id != productId.Value);
            }

            var model = query.Take(5)
                        .Select(x => ProductThumbnail.FromProduct(x)).ToList();

            foreach (var product in model)
            {
                product.ThumbnailUrl           = _mediaService.GetThumbnailUrl(product.ThumbnailImage);
                product.CalculatedProductPrice = _productPricingService.CalculateProductPrice(product);
            }

            return(View("/Modules/SimplCommerce.Module.ProductRecentlyViewed/Views/Components/ProductRecentlyViewed.cshtml", model));
        }
        // TODO Number of items to config
        public async Task <IViewComponentResult> InvokeAsync(long?productId, int itemCount = 4)
        {
            var user = await _workContext.GetCurrentUser();

            IQueryable <Product> query = _productRepository.GetRecentlyViewedProduct(user.Id)
                                         .Include(x => x.ThumbnailImage);

            if (productId.HasValue)
            {
                query = query.Where(x => x.Id != productId.Value);
            }

            var model = query.Take(itemCount)
                        .Select(x => ProductThumbnail.FromProduct(x)).ToList();

            foreach (var product in model)
            {
                product.Name                   = _contentLocalizationService.GetLocalizedProperty(nameof(Product), product.Id, nameof(product.Name), product.Name);
                product.ThumbnailUrl           = _mediaService.GetThumbnailUrl(product.ThumbnailImage);
                product.CalculatedProductPrice = _productPricingService.CalculateProductPrice(product);
            }

            return(View(this.GetViewPath(), model));
        }