public ProductListResultModel GetProductList(
            IVisitorContext visitorContext,
            string currentItemId,
            string currentCatalogItemId,
            string searchKeyword,
            int?pageNumber,
            NameValueCollection facetValues,
            string sortField,
            int?pageSize,
            SortDirection?sortDirection)
        {
            Assert.ArgumentNotNull(visitorContext, nameof(visitorContext));

            var model = new ProductListResultModel();

            var specifiedCatalogItem = !string.IsNullOrEmpty(currentCatalogItemId)
                                           ? Context.Database.GetItem(currentCatalogItemId)
                                           : null;
            var currentCatalogItem = specifiedCatalogItem ?? this.storefrontContext.CurrentCatalogItem;

            model.CurrentCatalogItemId = currentCatalogItem.ID.Guid.ToString("D");

            // var currentItem = Sitecore.Context.Database.GetItem(currentItemId);

            // this.siteContext.CurrentCategoryItem = currentCatalogItem;
            // this.siteContext.CurrentItem = currentItem;
            var searchInformation = this.searchInformationProvider.GetCategorySearchInformation(currentCatalogItem);

            this.GetSortParameters(searchInformation, ref sortField, ref sortDirection);

            var itemsPerPage          = this.settingsProvider.GetDefaultItemsPerPage(pageSize, searchInformation);
            var commerceSearchOptions = new CommerceSearchOptions(itemsPerPage, pageNumber.GetValueOrDefault(0));

            this.UpdateOptionsWithFacets(searchInformation.RequiredFacets, facetValues, commerceSearchOptions);
            this.UpdateOptionsWithSorting(sortField, sortDirection, commerceSearchOptions);

            var childProducts     = this.GetChildProducts(searchKeyword, commerceSearchOptions, specifiedCatalogItem);
            var productEntityList = this.AdjustProductPriceAndStockStatus(visitorContext, childProducts, currentCatalogItem);

            model.Initialize(commerceSearchOptions, childProducts, productEntityList);
            this.ApplySortOptions(model, commerceSearchOptions, searchInformation);

            return(model);
        }
        protected void ApplySortOptions(
            ProductListResultModel model,
            CommerceSearchOptions commerceSearchOptions,
            CategorySearchInformation searchInformation)
        {
            Assert.ArgumentNotNull(model, nameof(model));
            Assert.ArgumentNotNull(commerceSearchOptions, nameof(commerceSearchOptions));
            Assert.ArgumentNotNull(searchInformation, nameof(searchInformation));

            if ((searchInformation.SortFields == null) || !searchInformation.SortFields.Any())
            {
                return;
            }

            var sortOptions = new List <SortOptionModel>();

            foreach (var sortField in searchInformation.SortFields)
            {
                var isSelected = sortField.Name.Equals(commerceSearchOptions.SortField);

                var sortOptionAsc = new SortOptionModel
                {
                    Name          = sortField.Name,
                    DisplayName   = sortField.DisplayName,
                    SortDirection = SortDirection.Asc,
                    IsSelected    = isSelected && (commerceSearchOptions.SortDirection == CommerceConstants.SortDirection.Asc)
                };

                sortOptions.Add(sortOptionAsc);

                var sortOptionDesc = new SortOptionModel
                {
                    Name          = sortField.Name,
                    DisplayName   = sortField.DisplayName,
                    SortDirection = SortDirection.Desc,
                    IsSelected    = isSelected && (commerceSearchOptions.SortDirection == CommerceConstants.SortDirection.Desc)
                };

                sortOptions.Add(sortOptionDesc);
            }

            model.SortOptions = sortOptions;
        }
        public override object DoGetList <TFilter>(TFilter model, Language language)
        {
            ProductListFilterModel      filterModel = (model as ProductListFilterModel);
            ProductListResultModel      result      = new ProductListResultModel();
            List <ProductListDataModel> data        = new List <ProductListDataModel>();

            try
            {
                data = DB.WBPRODUCT.Select(s => new ProductListDataModel()
                {
                    ID              = s.ID,
                    ProductName     = s.PRD_NM,
                    TypeID          = s.MAP_PRODUCT_TP_ID,
                    Sort            = s.SR_SQ,
                    Language        = s.LANG_CD,
                    DisplayForFront = (bool)s.DIS_FRONT_ST
                })
                       .ToList();
                ProductKindModule ProductTypeModule = new ProductKindModule();
                foreach (var d in data)
                {
                    d.ProductType = (ProductTypeModule.DoGetDetailsByID(d.TypeID) as ProductKindDetailsDataModel);
                }

                //語系搜尋
                if (!language.Equals(Language.NotSet))
                {
                    this.ListFilterLanguage(language, ref data);
                }

                //關鍵字搜尋
                if (!string.IsNullOrEmpty(filterModel.QueryString))
                {
                    this.ListFilter(filterModel.QueryString, ref data);
                }
                //日期搜尋
                //this.ListDateFilter(filterModel.BeginDate, filterModel.EndDate, ref data);

                //分類搜尋
                if (filterModel.TypeID.HasValue && filterModel.TypeID > 0)
                {
                    this.ListTypeFilter(filterModel.TypeID.ToString(), ref data);
                }

                //產品分類
                if (!string.IsNullOrEmpty(filterModel.Status))
                {
                    this.ListStatusFilter(filterModel.Status, ref data);
                }

                //前台顯示
                this.ListSort(filterModel.SortColumn, filterModel.Status, ref data);
                PaginationResult pagination;
                //分頁
                this.ListPageList(filterModel.CurrentPage, ref data, out pagination);
                result.Pagination = pagination;
                result.Data       = data;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(result);
        }