protected void BindSubCategories()
        {
            IList <Category>       allCategories       = CategoryDataSource.LoadForParent(this._categoryId, true);
            List <SubCategoryData> populatedCategories = new List <SubCategoryData>();

            foreach (Category category in allCategories)
            {
                // SEARCH ALL CATEGORIES
                int totalProducts = ProductDataSource.AdvancedSearchCount(_keywords, category.Id, _manufacturerId, true, true, true, 0, 0, false, PageHelper.GetShopByChoices());
                if (totalProducts > 0)
                {
                    populatedCategories.Add(new SubCategoryData(category.Id, category.Name, category.NavigateUrl, totalProducts));
                }
            }
            if (populatedCategories.Count > 0)
            {
                SubCategoryPanel.Visible       = true;
                SubCategoryRepeater.DataSource = populatedCategories;
                SubCategoryRepeater.DataBind();
            }
            else
            {
                SubCategoryPanel.Visible = false;
            }
        }
예제 #2
0
 private void InitializePagingVars(bool forceRefresh)
 {
     Trace.Write("Initialize Paging Vars");
     if (!_PagingVarsInitialized || forceRefresh)
     {
         _hiddenPageIndex       = AlwaysConvert.ToInt(HiddenPageIndex.Value);
         _searchResultCount     = ProductDataSource.AdvancedSearchCount(_keywords, _categoryId, _manufacturerId, true, true, true, 0, 0, false, PageHelper.GetShopByChoices());
         _LastPageIndex         = ((int)Math.Ceiling(((double)_searchResultCount / (double)_pageSize))) - 1;
         _PagingVarsInitialized = true;
     }
 }
        protected void Page_PreRender(object sender, System.EventArgs e)
        {
            Trace.Write(this.GetType().ToString(), "Load Begin");
            _pageSize = AlwaysConvert.ToInt(PageSizeOptions.SelectedValue);
            if (_pageSize == 0)
            {
                _pageSize = ProductDataSource.AdvancedSearchCount(_keywords, this._categoryId, _manufacturerId, true, true, true, 0, 0, false, PageHelper.GetShopByChoices());
            }
            ProductList.RepeatColumns = Cols;
            _keywords = Server.UrlDecode(Request.QueryString["k"]);
            if (!string.IsNullOrEmpty(_keywords))
            {
                _keywords = StringHelper.StripHtml(_keywords).Trim();
            }
            _category = CategoryDataSource.Load(this._categoryId);

            //EXIT PROCESSING IF CATEGORY IS INVALID OR MARKED PRIVATE
            if (!IsValidCategory())
            {
                SearchResultsPanel.Visible = false;
            }
            else
            {
                if (_category != null)
                {
                    //REGISTER THE PAGEVISIT
                    AbleCommerce.Code.PageVisitHelper.RegisterPageVisit(_category.Id, CatalogNodeType.Category, _category.Name);
                }
                if (!Page.IsPostBack)
                {
                    //INITIALIZE SEARCH CRITERIA ON FIRST VISIT
                    HiddenPageIndex.Value = Request.QueryString["p"];
                    string tempSort = Request.QueryString["s"];
                    if (!string.IsNullOrEmpty(tempSort))
                    {
                        ListItem item = SortResults.Items.OfType <ListItem>().SingleOrDefault(x => string.Compare(x.Value, tempSort, StringComparison.InvariantCultureIgnoreCase) == 0);
                        if (item != null)
                        {
                            item.Selected = true;
                        }
                    }
                }

                SetPagerIndex();
            }

            if (IsValidCategory())
            {
                //BIND PAGE
                BindPage();
            }
        }
        protected void BindProductList()
        {
            IList <Product> products = ProductDataSource.AdvancedSearch(_keywords, this._categoryId, _manufacturerId, true, true, true, 0, 0, PageHelper.GetShopByChoices(), _pageSize, (_hiddenPageIndex * _pageSize), SortResults.SelectedValue);

            // DELAYED QUERIES TO EAGER LOAD RELATED DATA FOR PERFORMANCE BOOST
            if (products.Count < 415)
            {
                List <int> ids = products.Select(p => p.Id).ToList <int>();

                var futureQuery = NHibernateHelper.QueryOver <Product>()
                                  .AndRestrictionOn(p => p.Id).IsIn(ids)
                                  .Fetch(p => p.Specials).Eager
                                  .Future <Product>();

                NHibernateHelper.QueryOver <Product>()
                .AndRestrictionOn(p => p.Id).IsIn(ids)
                .Fetch(p => p.ProductOptions).Eager
                .Future <Product>();

                NHibernateHelper.QueryOver <Product>()
                .AndRestrictionOn(p => p.Id).IsIn(ids)
                .Fetch(p => p.ProductKitComponents).Eager
                .Future <Product>();

                NHibernateHelper.QueryOver <Product>()
                .AndRestrictionOn(p => p.Id).IsIn(ids)
                .Fetch(p => p.ProductTemplates).Eager
                .Future <Product>();

                NHibernateHelper.QueryOver <Product>()
                .AndRestrictionOn(p => p.Id).IsIn(ids)
                .Fetch(p => p.Reviews).Eager
                .Future <Product>();

                futureQuery.ToList();
            }

            ProductList.DataSource = products;
            ProductList.DataBind();
            NoSearchResults.Visible = (_searchResultCount == 0);

            if (_pageSize == 0)
            {
                _pageSize = products.Count;
            }

            int minimumPageSize = AlwaysConvert.ToInt(PageSizeOptions.Items[0].Value);
            int totalResults    = ProductDataSource.AdvancedSearchCount(_keywords, this._categoryId, _manufacturerId, true, true, true, 0, 0, false, PageHelper.GetShopByChoices());

            PageSizePanel.Visible = totalResults > minimumPageSize;
        }
예제 #5
0
 private void InitializePagingVars(bool forceRefresh)
 {
     Trace.Write(this.GetType().ToString(), "Begin InitializePagingVars");
     if (!_pagingVarsInitialized || forceRefresh)
     {
         _hiddenPageIndex   = AlwaysConvert.ToInt(HiddenPageIndex.Value);
         _searchResultCount = ProductDataSource.AdvancedSearchCount(_keywords, _categoryId, _manufacturerId, true, true, true, 0, 0, SortResults.SelectedValue.StartsWith("IsFeatured"), PageHelper.GetShopByChoices());
         _lastPageIndex     = ((int)Math.Ceiling(((double)_searchResultCount / (double)_pageSize))) - 1;
         if (_lastPageIndex < 0)
         {
             _lastPageIndex = 0;
         }
         if (_hiddenPageIndex > _lastPageIndex)
         {
             _hiddenPageIndex = _lastPageIndex;
         }
         _pagingVarsInitialized = true;
     }
     Trace.Write(this.GetType().ToString(), "End InitializePagingVars");
 }
        protected void BindNarrowByCategoryPanel()
        {
            Trace.Write(this.GetType().ToString(), "Begin BindNarrowByCategoryPanel");
            Trace.Write(this.GetType().ToString(), "Load All Child Categories");
            IList <Category>            allCategories       = CategoryDataSource.LoadForParent(this._categoryId, true);
            List <NarrowByCategoryData> populatedCategories = new List <NarrowByCategoryData>();

            foreach (Category category in allCategories)
            {
                Trace.Write(this.GetType().ToString(), "Count Items in " + category.Name);
                if (ShowProductCount)
                {
                    int totalProducts = ProductDataSource.AdvancedSearchCount(this._keyword, category.Id, this._manufacturerId, true, true, true, 0, 0, false, PageHelper.GetShopByChoices());
                    if (totalProducts > 0)
                    {
                        populatedCategories.Add(new NarrowByCategoryData(category.Id, category.Name, totalProducts));
                    }
                }
                else
                {
                    populatedCategories.Add(new NarrowByCategoryData(category.Id, category.Name, 0));
                }
            }
            Trace.Write(this.GetType().ToString(), "CheckBox Populated Categories");
            if (populatedCategories.Count > 0)
            {
                NarrowByCategoryPanel.Visible    = true;
                NarrowByCategoryLinks.DataSource = populatedCategories;
                NarrowByCategoryLinks.DataBind();
            }
            else
            {
                NarrowByCategoryPanel.Visible = false;
            }
            Trace.Write(this.GetType().ToString(), "End BindNarrowByCategoryPanel");
        }
예제 #7
0
        protected void Page_Load(object sender, System.EventArgs e)
        {
            Trace.Write(this.GetType().ToString(), "Load Begin");

            _categoryId     = AbleCommerce.Code.PageHelper.GetCategoryId();
            _manufacturerId = AlwaysConvert.ToInt(Request.QueryString["m"]);
            _keywords       = Server.UrlDecode(Request.QueryString["k"]);
            _shopBy         = StringHelper.StripHtml(Server.UrlDecode(Request.QueryString["shopby"]));
            if (!string.IsNullOrEmpty(_shopBy))
            {
                _shopBy = StringHelper.StripHtml(_shopBy).Trim();
            }

            string eventTarget = Request["__EVENTTARGET"];

            if (string.IsNullOrEmpty(eventTarget) || !eventTarget.EndsWith("PageSizeOptions"))
            {
                string pageSizeOption = Request.QueryString["ps"];
                if (!string.IsNullOrEmpty(pageSizeOption))
                {
                    PageSizeOptions.ClearSelection();
                    ListItem item = PageSizeOptions.Items.FindByValue(pageSizeOption);
                    if (item != null)
                    {
                        item.Selected = true;
                    }
                }
            }
            else
            if (eventTarget.EndsWith("PageSizeOptions"))
            {
                string url = Request.RawUrl;
                if (url.Contains("?"))
                {
                    url = Request.RawUrl.Substring(0, Request.RawUrl.IndexOf("?"));
                }
                url += "?s=" + SortResults.SelectedValue;
                url += "&ps=" + PageSizeOptions.SelectedValue;
                if (_categoryId != 0)
                {
                    url += "&c=" + _categoryId.ToString();
                }
                if (_manufacturerId != 0)
                {
                    url += "&m=" + _manufacturerId.ToString();
                }
                if (!string.IsNullOrEmpty(_shopBy))
                {
                    url += "&shopby=" + _shopBy;
                }
                Response.Redirect(url);
            }

            _pageSize = AlwaysConvert.ToInt(PageSizeOptions.SelectedValue);
            ProductList.RepeatColumns = Cols;
            if (!string.IsNullOrEmpty(_keywords))
            {
                _keywords = StringHelper.StripHtml(_keywords).Trim();
            }
            _category = CategoryDataSource.Load(this._categoryId);
            if (_pageSize == 0)
            {
                _pageSize = ProductDataSource.AdvancedSearchCount(_keywords, _categoryId, _manufacturerId, true, true, true, 0, 0, false, PageHelper.GetShopByChoices());
            }
            //EXIT PROCESSING IF CATEGORY IS INVALID OR MARKED PRIVATE
            if (!IsValidCategory())
            {
                SearchResultsAjaxPanel.Visible = false;
            }
            else
            {
                if (_category != null)
                {
                    //REGISTER THE PAGEVISIT
                    AbleCommerce.Code.PageVisitHelper.RegisterPageVisit(_category.Id, CatalogNodeType.Category, _category.Name);
                }
                if (!Page.IsPostBack)
                {
                    //INITIALIZE SEARCH CRITERIA ON FIRST VISIT
                    HiddenPageIndex.Value = Request.QueryString["p"];
                    string tempSort = Request.QueryString["s"];
                    if (!string.IsNullOrEmpty(tempSort))
                    {
                        ListItem item = SortResults.Items.OfType <ListItem>().SingleOrDefault(x => string.Compare(x.Value, tempSort, StringComparison.InvariantCultureIgnoreCase) == 0);
                        if (item != null)
                        {
                            item.Selected = true;
                        }
                    }
                }
            }

            // NEED TO BIND THE PAGE
            // BUT IF THE MULTIPLE ADD TO BASKET BUTTON CLICKED THEN THE BINDING SHOULD TAKE PLACE AT PRE_RENDER
            // THAT IS AFTER ADD TO CART
            if (IsValidCategory() && Request.Form["__EVENTTARGET"] != MultipleAddToBasketButton.UniqueID)
            {
                BindPage();
                MultipleAddToBasketButton.Visible = _quantityVisible;
            }

            int manufecturerCount = ManufacturerDataSource.CountAll();

            foreach (ListItem li in SortResults.Items)
            {
                if (li.Value.StartsWith("Manufacturer"))
                {
                    li.Enabled = manufecturerCount > 0;
                }
            }
        }
예제 #8
0
        protected void Page_Load(object sender, System.EventArgs e)
        {
            string kwords = KeywordField.Text;

            if (string.IsNullOrEmpty(kwords))
            {
                kwords = HiddenSearchKeywords.Value;
            }
            if (Page.IsPostBack && !string.IsNullOrEmpty(kwords))
            {
                _keywords = StringHelper.StripHtml(kwords).Trim();
                HiddenSearchKeywords.Value = _keywords;
            }
            else
            {
                _keywords = Server.UrlDecode(Request.QueryString["k"]);
                if (!string.IsNullOrEmpty(_keywords))
                {
                    _keywords = StringHelper.StripHtml(_keywords).Trim();
                }
            }

            if (HasSearchCriteria())
            {
                //has something to search
                ResultsPanel.Visible          = true;
                NoSearchCriteriaPanel.Visible = false;
                ResultTermMessage.Visible     = true;

                if (!Page.IsPostBack)
                {
                    //initialize search sorting and paging criteria based on query string parameters
                    HiddenPageIndex.Value = AlwaysConvert.ToInt(Request.QueryString["p"]).ToString();
                    string tempSort = Request.QueryString["s"];
                    if (!string.IsNullOrEmpty(tempSort))
                    {
                        ListItem item = SortResults.Items.FindByValue(tempSort);
                        if (item != null)
                        {
                            item.Selected = true;
                        }
                    }
                }

                //initialize paging vars
                _hiddenPageIndex   = AlwaysConvert.ToInt(HiddenPageIndex.Value);
                _searchResultCount = ProductDataSource.AdvancedSearchCount(_keywords, _categoryId, _manufacturerId, true, true, true, 0, 0);
                _lastPageIndex     = ((int)Math.Ceiling(((double)_searchResultCount / (double)_pageSize))) - 1;
                if (_hiddenPageIndex > _lastPageIndex)
                {
                    _hiddenPageIndex = _lastPageIndex;
                }
                if (_pageSize == 0)
                {
                    _pageSize = _searchResultCount;
                }

                //update the header search criteria message
                StringBuilder sb = new StringBuilder();
                if (!string.IsNullOrEmpty(_keywords))
                {
                    sb.Append(string.Format(" for '{0}'", _keywords));
                }
                Category category = CategoryDataSource.Load(_categoryId);
                if (category != null)
                {
                    sb.Append(string.Format(" in '{0}'", category.Name));
                }
                Manufacturer manufacturer = ManufacturerDataSource.Load(_manufacturerId);
                if (manufacturer != null)
                {
                    sb.Append(string.Format(" in '{0}'", manufacturer.Name));
                }
                ResultTermMessage.Text = string.Format(ResultTermMessage.Text, sb.ToString());

                //bind search results
                int startIndex = (_hiddenPageIndex * _pageSize);
                if (startIndex < 0)
                {
                    startIndex = 0;
                }
                var products = ProductDataSource.AdvancedSearch(_keywords, _categoryId, _manufacturerId, true, true, true, 0, 0, _pageSize, startIndex, SortResults.SelectedValue);

                // DELAYED QUERIES TO EAGER LOAD RELATED DATA FOR PERFORMANCE BOOST
                if (products.Count < 415)
                {
                    List <int> ids = products.Select(p => p.Id).ToList <int>();

                    var futureQuery = NHibernateHelper.QueryOver <Product>()
                                      .AndRestrictionOn(p => p.Id).IsIn(ids)
                                      .Fetch(p => p.Specials).Eager
                                      .Future <Product>();

                    NHibernateHelper.QueryOver <Product>()
                    .AndRestrictionOn(p => p.Id).IsIn(ids)
                    .Fetch(p => p.ProductOptions).Eager
                    .Future <Product>();

                    NHibernateHelper.QueryOver <Product>()
                    .AndRestrictionOn(p => p.Id).IsIn(ids)
                    .Fetch(p => p.ProductKitComponents).Eager
                    .Future <Product>();

                    NHibernateHelper.QueryOver <Product>()
                    .AndRestrictionOn(p => p.Id).IsIn(ids)
                    .Fetch(p => p.ProductTemplates).Eager
                    .Future <Product>();

                    futureQuery.ToList();
                }

                ProductList.DataSource = products;
                ProductList.DataBind();

                NoResultsPanel.Visible = _searchResultCount == 0;
                SortPanel.Visible      = _searchResultCount > 1;

                //bind paging
                int totalPages;
                if (_pageSize <= 0)
                {
                    totalPages = 1;
                }
                else
                {
                    totalPages = (int)Math.Ceiling((double)_searchResultCount / _pageSize);
                }

                if (_lastPageIndex > 0)
                {
                    PagerPanel.Visible    = true;
                    PagerPanelTop.Visible = true;
                    List <PagerLinkData> pagerLinkData = GetPagingLinkData(totalPages);
                    PagerControls.DataSource = pagerLinkData;
                    PagerControls.DataBind();
                    PagerControlsTop.DataSource = pagerLinkData;
                    PagerControlsTop.DataBind();

                    PagerMessageTop.Text    = string.Format("Page {0} of {1}", (_hiddenPageIndex + 1), totalPages);
                    PagerMessageBottom.Text = string.Format("Page {0} of {1}", (_hiddenPageIndex + 1), totalPages);
                }
                else
                {
                    PagerPanel.Visible    = false;
                    PagerPanelTop.Visible = false;
                }
            }
            else
            {
                //no search criteria
                ResultsPanel.Visible          = false;
                NoSearchCriteriaPanel.Visible = true;
                ResultTermMessage.Visible     = false;
            }
        }
예제 #9
0
        protected void Page_Load(object sender, System.EventArgs e)
        {
            _categoryId     = AlwaysConvert.ToInt(Request.QueryString["c"]);
            _manufacturerId = AlwaysConvert.ToInt(Request.QueryString["m"]);
            _keywords       = StringHelper.StripHtml(Server.UrlDecode(Request.QueryString["k"]));
            if (!string.IsNullOrEmpty(_keywords))
            {
                _keywords = StringHelper.StripHtml(_keywords).Trim();
            }

            _shopBy = StringHelper.StripHtml(Server.UrlDecode(Request.QueryString["shopby"]));
            if (!string.IsNullOrEmpty(_shopBy))
            {
                _shopBy = StringHelper.StripHtml(_shopBy).Trim();
            }

            string eventTarget = Request["__EVENTTARGET"];

            if (string.IsNullOrEmpty(eventTarget) || !eventTarget.EndsWith("PageSizeOptions"))
            {
                string pageSizeOption = Request.QueryString["ps"];
                if (!string.IsNullOrEmpty(pageSizeOption))
                {
                    PageSizeOptions.ClearSelection();
                    ListItem item = PageSizeOptions.Items.FindByValue(pageSizeOption);
                    if (item != null)
                    {
                        item.Selected = true;
                    }
                }
            }
            else
            if (eventTarget.EndsWith("PageSizeOptions"))
            {
                string url = Request.RawUrl;
                if (url.Contains("?"))
                {
                    url = Request.RawUrl.Substring(0, Request.RawUrl.IndexOf("?"));
                }
                url += "?s=" + SortResults.SelectedValue;
                url += "&ps=" + PageSizeOptions.SelectedValue;
                if (_categoryId != 0)
                {
                    url += "&c=" + _categoryId.ToString();
                }
                if (_manufacturerId != 0)
                {
                    url += "&m=" + _manufacturerId.ToString();
                }
                if (!string.IsNullOrEmpty(_keywords))
                {
                    url += "&k=" + _keywords;
                }
                if (!string.IsNullOrEmpty(_shopBy))
                {
                    url += "&shopby=" + _shopBy;
                }
                Response.Redirect(url);
            }

            _pageSize = AlwaysConvert.ToInt(PageSizeOptions.SelectedValue);
            ProductList.RepeatColumns = Cols;
            if (_pageSize == 0)
            {
                _pageSize = ProductDataSource.AdvancedSearchCount(_keywords, _categoryId, _manufacturerId, true, true, true, 0, 0, false, PageHelper.GetShopByChoices());
            }

            if (!Page.IsPostBack)
            {
                if (ApplicationSettings.Instance.SearchProvider == "LuceneSearchProvider" || ApplicationSettings.Instance.SearchProvider == "SqlFtsSearchProvider")
                {
                    bool sortByRelevance = true;
                    if (!string.IsNullOrEmpty(_keywords))
                    {
                        ISearchProvider      provider = SearchProviderLocator.Locate();
                        LuceneSearchProvider lucene   = provider as LuceneSearchProvider;
                        if (lucene != null)
                        {
                            sortByRelevance = !lucene.UseSQLSearch(_keywords);
                        }
                        SqlFtsSearchProvider sqlFTS = provider as SqlFtsSearchProvider;
                        if (sqlFTS != null)
                        {
                            sortByRelevance = !sqlFTS.UseSQLSearch(_keywords);
                        }
                    }

                    if (sortByRelevance)
                    {
                        SortResults.Items.Insert(0, new ListItem("By Relevance", "FTS.RANK DESC"));
                    }
                }

                //INITIALIZE SEARCH CRITERIA ON FIRST VISIT
                HiddenPageIndex.Value = AlwaysConvert.ToInt(Request.QueryString["p"]).ToString();
                string tempSort = Request.QueryString["s"];
                if (!string.IsNullOrEmpty(tempSort))
                {
                    ListItem item = SortResults.Items.FindByValue(tempSort);
                    if (item != null)
                    {
                        item.Selected = true;
                    }
                }
            }

            int  manufecturerCount      = ManufacturerDataSource.CountAll();
            bool showSortByManufacturer = false;

            if (manufecturerCount > 0 && _manufacturerId == 0)
            {
                IList <ManufacturerProductCount> mCounts = ProductDataSource.AdvancedSearchCountByManufacturer(_keywords, _categoryId, true, true, true, 0, 0, PageHelper.GetShopByChoices());
                showSortByManufacturer = mCounts != null && mCounts.Count > 0;
            }

            foreach (ListItem li in SortResults.Items)
            {
                if (li.Value.StartsWith("Manufacturer"))
                {
                    li.Enabled = showSortByManufacturer;
                }
            }

            BindSearchResultsPanel();
        }