private void LoadCategoryProducts() { int pageIndex = WA.Parser.ToInt(Request.QueryString["pg"]).GetValueOrDefault(1) - 1; int pageSize = WA.Parser.ToInt(StoreContext.CurrentStore.GetSetting(StoreSettingNames.CatalogMaxResultsPerPage)).GetValueOrDefault(100); string defaultSortName = StoreContext.CurrentStore.GetSetting(StoreSettingNames.CatalogDefaultSortOrder) ?? ""; ProductSortByField defaultSortField = sortByFields.Find(f => f.DisplayName == defaultSortName); sortByField = ProductSortByField.FromString(Request.QueryString["sb"]) ?? defaultSortField ?? sortByFields[0]; List <Product> products = category.GetProducts(sortByField); if (products.Count > 0) { productList = new PagedList <Product>(products, pageIndex, pageSize); rptCategoryProducts.DataSource = productList; rptCategoryProducts.DataBind(); if (products.Count > pageSize) { RenderPaginationLinks(productList); } } else { pnlCategoryProductResults.Visible = false; } pnlNoResults.Visible = !pnlCategoryProductResults.Visible; }
private void LoadFeaturedProducts() { var sortField = ProductSortByField.FromString(Convert.ToString(Settings[FeaturedSettings.SortBy])) ?? new ProductSortByField() { Field = "Name", SortDirection = SortDirection.ASC }; var categoryIds = Convert.ToString(Settings[FeaturedSettings.CategoryFilterCategoryIds]).Split(',').Select(x => WA.Parser.ToInt(x).GetValueOrDefault(-1)).ToList(); bool matchAll = Convert.ToString(Settings[FeaturedSettings.CategoryFilterMethod]).ToLower() == "all"; var products = ProductCollection.FindProductsByCategories(categoryIds, sortField, matchAll); int maxProducts = WA.Parser.ToInt(Settings[FeaturedSettings.MaxNumProducts]).GetValueOrDefault(25); if (products.Count > maxProducts) { products = products.Take(maxProducts).ToList(); } string tplHeader = Settings[FeaturedSettings.TemplateHeader].ToString(); string tplProduct = Settings[FeaturedSettings.TemplateProduct].ToString(); string tplFooter = Settings[FeaturedSettings.TemplateFooter].ToString(); string tplNoResults = Settings[FeaturedSettings.TemplateNoResults].ToString(); if (products.Count == 0) { litTemplateOutput.Text = tplHeader + tplNoResults + tplFooter; } else { var productTokenizer = new ProductTokenValueProvider(StoreContext); var templateProcessor = new TemplateProcessor(productTokenizer); StringBuilder productsHtml = new StringBuilder(products.Count); foreach (var p in products) { productTokenizer.Product = p; productsHtml.Append(templateProcessor.ProcessTemplate(tplProduct)); } litTemplateOutput.Text = tplHeader + productsHtml.ToString() + tplFooter; } }