Example #1
0
        /// <returns>A task that represents the asynchronous operation</returns>
        public async Task <IViewComponentResult> InvokeAsync(int?productThumbPictureSize)
        {
            if (!_catalogSettings.ShowBestsellersOnHomepage || _catalogSettings.NumberOfBestsellersOnHomepage == 0)
            {
                return(Content(""));
            }

            //load and cache report
            var report = (await _staticCacheManager.GetAsync(_staticCacheManager.PrepareKeyForDefaultCache(NopModelCacheDefaults.HomepageBestsellersIdsKey, await _storeContext.GetCurrentStoreAsync()),
                                                             async() => await _orderReportService.BestSellersReportAsync(
                                                                 storeId: (await _storeContext.GetCurrentStoreAsync()).Id,
                                                                 pageSize: _catalogSettings.NumberOfBestsellersOnHomepage)))
                         .ToList();

            //load products
            var products = await(await _productService.GetProductsByIdsAsync(report.Select(x => x.ProductId).ToArray()))
                           //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 = (await _productModelFactory.PrepareProductOverviewModelsAsync(products, true, true, productThumbPictureSize)).ToList();

            return(View(model));
        }
Example #2
0
        protected virtual async Task <IPagedList <BestsellersReportLine> > GetBestsellersReportAsync(BestsellerSearchModel searchModel)
        {
            //get parameters to filter bestsellers
            var orderStatus   = searchModel.OrderStatusId > 0 ? (OrderStatus?)searchModel.OrderStatusId : null;
            var paymentStatus = searchModel.PaymentStatusId > 0 ? (PaymentStatus?)searchModel.PaymentStatusId : null;

            if (await _workContext.GetCurrentVendorAsync() != null)
            {
                searchModel.VendorId = (await _workContext.GetCurrentVendorAsync()).Id;
            }
            var startDateValue = !searchModel.StartDate.HasValue ? null
                : (DateTime?)_dateTimeHelper.ConvertToUtcTime(searchModel.StartDate.Value, await _dateTimeHelper.GetCurrentTimeZoneAsync());
            var endDateValue = !searchModel.EndDate.HasValue ? null
                : (DateTime?)_dateTimeHelper.ConvertToUtcTime(searchModel.EndDate.Value, await _dateTimeHelper.GetCurrentTimeZoneAsync()).AddDays(1);

            //get bestsellers
            var bestsellers = await _orderReportService.BestSellersReportAsync(showHidden : true,
                                                                               createdFromUtc : startDateValue,
                                                                               createdToUtc : endDateValue,
                                                                               os : orderStatus,
                                                                               ps : paymentStatus,
                                                                               billingCountryId : searchModel.BillingCountryId,
                                                                               orderBy : OrderByEnum.OrderByTotalAmount,
                                                                               vendorId : searchModel.VendorId,
                                                                               categoryId : searchModel.CategoryId,
                                                                               manufacturerId : searchModel.ManufacturerId,
                                                                               storeId : searchModel.StoreId,
                                                                               pageIndex : searchModel.Page - 1, pageSize : searchModel.PageSize);

            return(bestsellers);
        }