Example #1
0
        protected void Page_Prerender(object sender, EventArgs e)
        {
            _paging.CurrentPageIndex = paging.CurrentPage != 0 ? paging.CurrentPage : 1;
            _paging.ItemsPerPage     = paging.CurrentPage != 0 ? SettingsCatalog.ProductsPerPage : int.MaxValue;
            var totalCount = _paging.TotalRowsCount;

            paging.TotalPages = _paging.PageCount(totalCount);

            if (totalCount != 0 && paging.TotalPages < paging.CurrentPage || paging.CurrentPage < 0)
            {
                Error404();
                return;
            }

            // if we get request from ajax filter
            if (Request["ajax"] == "1")
            {
                var prices =
                    _paging.GetCustomData(
                        "min(Price - Price * discount/100) as PriceFrom, max(Price - Price * discount/100) as PriceTo",
                        string.Empty,
                        reader => new
                {
                    From = SQLDataHelper.GetFloat(reader, "PriceFrom"),
                    To   = SQLDataHelper.GetFloat(reader, "PriceTo")
                }, false
                        ).First();
                Response.Clear();
                Response.ContentType = "application/json";

                var res = JsonConvert.SerializeObject(new
                {
                    ProductsCount     = totalCount,
                    AvaliblePriceFrom = Math.Floor(prices.From / CurrencyService.CurrentCurrency.Value),
                    AvaliblePriceTo   = Math.Ceiling(prices.To / CurrencyService.CurrentCurrency.Value),
                });
                Response.Write(res);
                Response.End();
                return;
            }

            if (!string.IsNullOrEmpty(Page.Request["name"]) && string.IsNullOrEmpty(Page.Request["ignorelog"]))
            {
                var url = Page.Request.Url.ToString();
                url = url.Substring(url.LastIndexOf("/"), url.Length - url.LastIndexOf("/"));
                StatisticService.AddSearchStatistic(
                    url,
                    Page.Request["name"],
                    string.Format(Resource.Client_Search_SearchIn,
                                  ddlCategory.SelectedItem.Text,
                                  filterPrice.CurValMin,
                                  string.IsNullOrEmpty(Request["priceto"]) ? "∞" : filterPrice.CurValMax.ToString()),
                    totalCount,
                    CustomerContext.CurrentCustomer.Id);
            }

            //filterPrice.Min = prices.Key / CurrencyService.CurrentCurrency.Value;
            //filterPrice.Max = prices.Value / CurrencyService.CurrentCurrency.Value;

            var data = _paging.PageItems;

            vProducts.DataSource = data;
            vProducts.ViewMode   = productViewChanger.SearchViewMode;
            vProducts.DataBind();

            int itemsCount = totalCount;

            lItemsCount.Text = string.Format("{0} {1}", itemsCount,
                                             Strings.Numerals(itemsCount, Resource.Client_Searsh_NoResults,
                                                              Resource.Client_Searsh_1Result,
                                                              Resource.Client_Searsh_2Results,
                                                              Resource.Client_Searsh_5Results));
            pnlSort.Visible = itemsCount > 0;

            if (GoogleTagManager.Enabled)
            {
                var tagManager = ((AdvantShopMasterPage)Master).TagManager;
                tagManager.PageType = GoogleTagManager.ePageType.searchresults;
                tagManager.ProdIds  = new List <string>();
                foreach (DataRow row in data.Rows)
                {
                    tagManager.ProdIds.Add((string)row["ArtNo"]);
                }
            }
        }