예제 #1
0
        protected async Task <DataSourceResult> GetBestsellersBriefReportModel(int pageIndex,
                                                                               int pageSize, int orderBy)
        {
            //a vendor should have access only to his products
            string vendorId = "";

            if (_workContext.CurrentVendor != null && !_workContext.CurrentCustomer.IsStaff())
            {
                vendorId = _workContext.CurrentVendor.Id;
            }

            string storeId = "";

            if (_workContext.CurrentCustomer.IsStaff())
            {
                storeId = _workContext.CurrentCustomer.StaffStoreId;
            }

            var items = await _orderReportService.BestSellersReport(
                storeId : storeId,
                vendorId : vendorId,
                orderBy : orderBy,
                pageIndex : pageIndex,
                pageSize : pageSize,
                showHidden : true);

            var result = new List <BestsellersReportLineModel>();

            foreach (var x in items)
            {
                var m = new BestsellersReportLineModel
                {
                    ProductId     = x.ProductId,
                    TotalAmount   = _priceFormatter.FormatPrice(x.TotalAmount, true, false),
                    TotalQuantity = x.TotalQuantity,
                };
                var product = await _productService.GetProductById(x.ProductId);

                if (product != null)
                {
                    m.ProductName = product.Name;
                }
                result.Add(m);
            }

            var gridModel = new DataSourceResult
            {
                Data  = result,
                Total = items.TotalCount
            };

            return(gridModel);
        }
        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 => _productService.ProductIsAvailable(p)).ToList();

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

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

            return(View(model));
        }
        public ActionResult HomepageBestSellers(int?productThumbPictureSize)
        {
            if (!_catalogSettings.ShowBestsellersOnHomepage || _catalogSettings.NumberOfBestsellersOnHomepage == 0)
            {
                return(Content(""));
            }

            // Load report from cache
            var report = Services.Cache.Get(string.Format(ModelCacheEventConsumer.HOMEPAGE_BESTSELLERS_IDS_KEY, Services.StoreContext.CurrentStore.Id), () =>
            {
                return(_orderReportService.BestSellersReport(Services.StoreContext.CurrentStore.Id, null, null, null, null, null, 0, _catalogSettings.NumberOfBestsellersOnHomepage));
            });

            // 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();


            var viewMode = _catalogSettings.UseSmallProductBoxOnHomePage ? ProductSummaryViewMode.Mini : ProductSummaryViewMode.Grid;

            var settings = _helper.GetBestFitProductSummaryMappingSettings(viewMode, x =>
            {
                x.ThumbnailSize = productThumbPictureSize;
            });

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

            model.GridColumnSpan = GridColumnSpan.Max6Cols;

            return(PartialView(model));
        }
        protected virtual IPagedList <BestsellersReportLine> GetBestsellersReport(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 (_workContext.CurrentVendor != null)
            {
                searchModel.VendorId = _workContext.CurrentVendor.Id;
            }
            var startDateValue = !searchModel.StartDate.HasValue ? null
                : (DateTime?)_dateTimeHelper.ConvertToUtcTime(searchModel.StartDate.Value, _dateTimeHelper.CurrentTimeZone);
            var endDateValue = !searchModel.EndDate.HasValue ? null
                : (DateTime?)_dateTimeHelper.ConvertToUtcTime(searchModel.EndDate.Value, _dateTimeHelper.CurrentTimeZone).AddDays(1);

            //get bestsellers
            var bestsellers = _orderReportService.BestSellersReport(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);
        }
예제 #5
0
        public async Task <IViewComponentResult> InvokeAsync(int?productThumbPictureSize)
        {
            if (!_catalogSettings.ShowBestsellersOnHomepage || _catalogSettings.NumberOfBestsellersOnHomepage == 0)
            {
                return(Content(""));
            }

            //load and cache report
            var fromdate = DateTime.UtcNow.AddMonths(_catalogSettings.PeriodBestsellers > 0 ? -_catalogSettings.PeriodBestsellers : -12);
            var report   = await _cacheBase.GetAsync(string.Format(ModelCacheEventConst.HOMEPAGE_BESTSELLERS_IDS_KEY, _storeContext.CurrentStore.Id), async() =>
                                                     await _orderReportService.BestSellersReport(
                                                         createdFromUtc: fromdate,
                                                         ps: Domain.Payments.PaymentStatus.Paid,
                                                         storeId: _storeContext.CurrentStore.Id,
                                                         pageSize: _catalogSettings.NumberOfBestsellersOnHomepage));

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

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

            var model = await _mediator.Send(new GetProductOverview()
            {
                ProductThumbPictureSize = productThumbPictureSize,
                Products = products,
            });

            return(View(model));
        }
예제 #6
0
        public IViewComponentResult Invoke(string widgetZone, object additionalData)
        {
            // Loading the seting value
            var homePageSettings = _settingService.LoadSetting <HomePageNewProductsSettings>(_storeContext.CurrentStore.Id);
            int NumberOfProducts = homePageSettings.NumberOfProducts;


            //load and cache report
            var report = _cacheManager.Get(string.Format(ModelCacheEventConsumer.HOMEPAGE_BESTSELLERS_IDS_KEY, _storeContext.CurrentStore.Id),
                                           () => _orderReportService.BestSellersReport(
                                               storeId: _storeContext.CurrentStore.Id)
                                           .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();
            //Order by MarkAsNewStartDate Descending, in order to get the newest first
            // Then get the first NumberOfProducts Specified in the Settings
            // Getting the first ones guarantees that they are the Newest
            products = products.OrderByDescending(p => p.MarkAsNewStartDateTimeUtc).Take(NumberOfProducts).ToList();

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

            return(View("~/Plugins/Widgets.HomePageNewProducts/Views/PublicInfo.cshtml", model));
        }
예제 #7
0
        /// <summary>
        /// Prepare paged bestseller list model
        /// </summary>
        /// <param name="searchModel">Bestseller search model</param>
        /// <returns>Bestseller list model</returns>
        public virtual BestsellerListModel PrepareBestsellerListModel(BestsellerSearchModel searchModel)
        {
            if (searchModel == null)
            {
                throw new ArgumentNullException(nameof(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 (_workContext.CurrentVendor != null)
            {
                searchModel.VendorId = _workContext.CurrentVendor.Id;
            }
            var startDateValue = !searchModel.StartDate.HasValue ? null
                : (DateTime?)_dateTimeHelper.ConvertToUtcTime(searchModel.StartDate.Value, _dateTimeHelper.CurrentTimeZone);
            var endDateValue = !searchModel.EndDate.HasValue ? null
                : (DateTime?)_dateTimeHelper.ConvertToUtcTime(searchModel.EndDate.Value, _dateTimeHelper.CurrentTimeZone).AddDays(1);

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

            //prepare list model
            var model = new BestsellerListModel
            {
                Data = bestsellers.Select(bestseller =>
                {
                    //fill in model values from the entity
                    var bestsellerModel = new BestsellerModel
                    {
                        ProductId     = bestseller.ProductId,
                        TotalQuantity = bestseller.TotalQuantity
                    };

                    //fill in additional values (not existing in the entity)
                    bestsellerModel.ProductName = _productService.GetProductById(bestseller.ProductId)?.Name;
                    bestsellerModel.TotalAmount = _priceFormatter.FormatPrice(bestseller.TotalAmount, true, false);

                    return(bestsellerModel);
                }),
                Total = bestsellers.TotalCount
            };

            return(model);
        }
        protected DataSourceResult GetBestsellersBriefReportModel(int pageIndex,
                                                                  int pageSize, int orderBy)
        {
            //a vendor should have access only to his products
            string vendorId = "";

            if (_workContext.CurrentVendor != null)
            {
                vendorId = _workContext.CurrentVendor.Id;
            }

            var items = _orderReportService.BestSellersReport(
                vendorId: vendorId,
                orderBy: orderBy,
                pageIndex: pageIndex,
                pageSize: pageSize,
                showHidden: true);
            var gridModel = new DataSourceResult
            {
                Data = items.Select(x =>
                {
                    var m = new BestsellersReportLineModel
                    {
                        ProductId     = x.ProductId,
                        TotalAmount   = _priceFormatter.FormatPrice(x.TotalAmount, true, false),
                        TotalQuantity = x.TotalQuantity,
                    };
                    var product = _productService.GetProductById(x.ProductId);
                    if (product != null)
                    {
                        m.ProductName = product.Name;
                    }
                    return(m);
                }),
                Total = items.TotalCount
            };

            return(gridModel);
        }
예제 #9
0
        public IActionResult GetBestSellingProducts(ProductsParametersModel parameters)
        {
            if (!_catalogSettings.ShowBestsellersOnHomepage || _catalogSettings.NumberOfBestsellersOnHomepage == 0)
            {
                return(new RawJsonActionResult("{\"products\":[]}"));
            }

            //load report
            var report = _orderReportService.BestSellersReport(
                storeId: _storeContext.CurrentStore.Id,
                pageSize: _catalogSettings.NumberOfBestsellersOnHomepage)
                         .ToList();

            parameters.Ids = report.Select(x => x.ProductId).ToList();
            return(GetProducts(parameters));
        }
예제 #10
0
        public async Task <IViewComponentResult> InvokeAsync(int?productThumbPictureSize)
        {
            if (!_catalogSettings.ShowBestsellersOnHomepage || _catalogSettings.NumberOfBestsellersOnHomepage == 0)
            {
                return(Content(""));
            }

            var productIds = new List <string>();

            //load and cache report
            if (_catalogSettings.BestsellersFromReports)
            {
                var fromdate = DateTime.UtcNow.AddMonths(_catalogSettings.PeriodBestsellers > 0 ? -_catalogSettings.PeriodBestsellers : -12);
                var report   = await _cacheBase.GetAsync(string.Format(CacheKeyConst.HOMEPAGE_BESTSELLERS_IDS_KEY, _workContext.CurrentStore.Id), async() =>
                                                         await _orderReportService.BestSellersReport(
                                                             createdFromUtc: fromdate,
                                                             ps: Domain.Payments.PaymentStatus.Paid,
                                                             storeId: _workContext.CurrentStore.Id,
                                                             pageSize: _catalogSettings.NumberOfBestsellersOnHomepage));

                productIds = report.Select(x => x.ProductId).ToList();
            }
            else
            {
                productIds = await _cacheBase.GetAsync(CacheKeyConst.BESTSELLER_PRODUCTS_MODEL_KEY,
                                                       async() => (await _productService.GetAllProductsDisplayedOnBestSeller()).ToList());
            }
            //load products
            var products = await _productService.GetProductsByIds(productIds.ToArray());

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

            var model = await _mediator.Send(new GetProductOverview()
            {
                ProductThumbPictureSize = productThumbPictureSize,
                Products = products.Take(_catalogSettings.NumberOfBestsellersOnHomepage),
            });

            return(View(model));
        }