private void BuildPageSizeXml( XmlDocument doc, XmlElement root) { if (config.PageSizeOptions.Count > 1) { int pageSizeQueryString = WebUtils.ParseInt32FromQueryString("pagesize", 0); foreach (string option in config.PageSizeOptions) { XmlElement element = doc.CreateElement("PageSize"); root.AppendChild(element); if (pageSizeQueryString.ToString() == option || (pageSizeQueryString == 0 && config.PageSize.ToString() == option)) { XmlHelper.AddNode(doc, element, "IsActive", true.ToString().ToLower()); } else { XmlHelper.AddNode(doc, element, "IsActive", false.ToString().ToLower()); } XmlHelper.AddNode(doc, element, "Title", option); XmlHelper.AddNode(doc, element, "Url", ProductHelper.BuildFilterUrlLeaveOutPageNumber(Request.RawUrl, "pagesize", option)); } } }
public void BuildViewModeXml( XmlDocument doc, XmlElement root) { // table XmlElement element = doc.CreateElement("ViewAs"); root.AppendChild(element); string pageUrl = ProductHelper.BuildFilterUrlLeaveOutPageNumber(Request.RawUrl, ProductHelper.QueryStringViewModeParam, "grid"); XmlHelper.AddNode(doc, element, "Url", pageUrl); string viewMode = WebUtils.ParseStringFromQueryString(ProductHelper.QueryStringViewModeParam, string.Empty); if (viewMode.Length == 0 || viewMode.ToLower() == "grid") { XmlHelper.AddNode(doc, element, "IsActive", "true"); } // list XmlElement listXml = doc.CreateElement("ViewAs"); root.AppendChild(listXml); pageUrl = ProductHelper.BuildFilterUrlLeaveOutPageNumber(Request.RawUrl, ProductHelper.QueryStringViewModeParam, "list"); XmlHelper.AddNode(doc, listXml, "Url", pageUrl); if (viewMode.ToLower() == "list") { XmlHelper.AddNode(doc, listXml, "IsActive", "true"); } }
private void PopulateControls() { if (config.LoadFirstProduct || forceLoadDetail) { Control c = Page.LoadControl("~/Product/Controls/ProductViewControl.ascx"); if (c == null) { return; } if (c is ProductViewControl) { ProductViewControl productView = (ProductViewControl)c; productView.module = this.ModuleConfiguration; productView.Config = config; } placeHolder.Controls.Add(c); } else { Control c = Page.LoadControl("~/Product/Controls/ProductListControl.ascx"); if (c == null) { return; } if (c is ProductListControl) { ProductListControl productList = (ProductListControl)c; productList.ModuleId = ModuleId; productList.Config = config; productList.SiteRoot = SiteRoot; productList.ImageSiteRoot = ImageSiteRoot; productList.ModuleTitle = this.Title; } placeHolder.Controls.Add(c); if (!Page.IsPostBack) { CartHelper.LastContinueShoppingPage = ProductHelper.BuildFilterUrlLeaveOutPageNumber(Request.RawUrl); } } if (forceLoadDetail) { CmsBasePage basePage = Page as CmsBasePage; if (basePage != null) { basePage.LoadSideContent(config.ShowLeftContent, config.ShowRightContent, config.ShowHiddenContents); basePage.LoadAltContent(ProductConfiguration.ShowTopContent, ProductConfiguration.ShowBottomContent, config.ShowHiddenContents); } } }
public void BuildSortModeXml( XmlDocument doc, XmlElement root) { int sortMode = WebUtils.ParseInt32FromQueryString(ProductHelper.QueryStringSortModeParam, 0); XmlHelper.AddNode(doc, root, "CurrentSort", sortMode.ToString()); // 0 - position XmlElement element = doc.CreateElement("SortBy"); root.AppendChild(element); XmlHelper.AddNode(doc, element, "Title", ProductResources.SortByNewest); XmlHelper.AddNode(doc, element, "Value", "0"); XmlHelper.AddNode(doc, element, "Url", ProductHelper.BuildFilterUrlLeaveOutPageNumber(Request.RawUrl, ProductHelper.QueryStringSortModeParam, "0")); if (sortMode == 0) { XmlHelper.AddNode(doc, element, "IsActive", "true"); } // 10 - Price: Low to High element = doc.CreateElement("SortBy"); root.AppendChild(element); XmlHelper.AddNode(doc, element, "Title", ProductResources.SortByPriceLowToHigh); XmlHelper.AddNode(doc, element, "Value", "10"); XmlHelper.AddNode(doc, element, "Url", ProductHelper.BuildFilterUrlLeaveOutPageNumber(Request.RawUrl, ProductHelper.QueryStringSortModeParam, "10")); if (sortMode == 10) { XmlHelper.AddNode(doc, element, "IsActive", "true"); } // 11 - Price: High to Low element = doc.CreateElement("SortBy"); root.AppendChild(element); XmlHelper.AddNode(doc, element, "Title", ProductResources.SortByPriceHighToLow); XmlHelper.AddNode(doc, element, "Value", "11"); XmlHelper.AddNode(doc, element, "Url", ProductHelper.BuildFilterUrlLeaveOutPageNumber(Request.RawUrl, ProductHelper.QueryStringSortModeParam, "11")); if (sortMode == 11) { XmlHelper.AddNode(doc, element, "IsActive", "true"); } }
private void PopulateControls() { XmlDocument doc = new XmlDocument(); doc.LoadXml("<ProductFilter></ProductFilter>"); XmlElement root = doc.DocumentElement; string rawUrl = Request.RawUrl; XmlHelper.AddNode(doc, root, "ModuleTitle", this.Title); XmlHelper.AddNode(doc, root, "ZoneTitle", CurrentZone.Name); XmlHelper.AddNode(doc, root, "ClearAllUrl", WebUtils.GetUrlWithoutQueryString(rawUrl)); if (ModuleConfiguration.ResourceFileDef.Length > 0 && ModuleConfiguration.ResourceKeyDef.Length > 0) { List <string> lstResourceKeys = ModuleConfiguration.ResourceKeyDef.SplitOnCharAndTrim(';'); foreach (string item in lstResourceKeys) { XmlHelper.AddNode(doc, root, item, ResourceHelper.GetResourceString(ModuleConfiguration.ResourceFileDef, item)); } } string rawUrlLeaveOutPageNumber = SiteUtils.BuildUrlLeaveOutParam(rawUrl, ProductHelper.QueryStringPageNumberParam, false); rawUrlLeaveOutPageNumber = SiteUtils.BuildUrlLeaveOutParam(rawUrlLeaveOutPageNumber, "isajax", false); List <CustomField> lstCustomFields = CustomFieldHelper.GetCustomFieldsFromContext(siteSettings.SiteId, Product.FeatureGuid, CurrentZone.ZoneGuid, WorkingCulture.LanguageId); foreach (CustomField field in lstCustomFields) { if ( (field.DataType == (int)CustomFieldDataType.CheckBox || field.DataType == (int)CustomFieldDataType.SelectBox) && (field.FilterType == (int)CustomFieldFilterType.ByValue || field.FilterType == (int)CustomFieldFilterType.ByMultipleValues) ) { XmlElement productXml = doc.CreateElement("Group"); root.AppendChild(productXml); XmlHelper.AddNode(doc, productXml, "GroupId", field.CustomFieldId.ToString()); XmlHelper.AddNode(doc, productXml, "Title", field.Name); XmlHelper.AddNode(doc, productXml, "FilterType", field.FilterType.ToString()); string paramName = string.Empty; bool isCheckBox = true; if (field.FilterType == (int)CustomFieldFilterType.ByValue) { paramName = ProductHelper.QueryStringFilterSingleParam + field.CustomFieldId.ToString(); XmlHelper.AddNode(doc, productXml, "ClearUrl", SiteUtils.BuildUrlLeaveOutParam(rawUrlLeaveOutPageNumber, paramName)); isCheckBox = false; } else { paramName = ProductHelper.QueryStringFilterMultiParam + field.CustomFieldId.ToString(); XmlHelper.AddNode(doc, productXml, "ClearUrl", SiteUtils.BuildUrlLeaveOutParam(rawUrlLeaveOutPageNumber, paramName)); isCheckBox = true; } XmlHelper.AddNode(doc, productXml, "IsCheckBox", isCheckBox.ToString().ToLower()); List <CustomFieldOption> lstOptions = CustomFieldOption.GetByCustomField(field.CustomFieldId); foreach (CustomFieldOption option in lstOptions) { XmlElement optionXml = doc.CreateElement("Option"); productXml.AppendChild(optionXml); XmlHelper.AddNode(doc, optionXml, "GroupId", option.CustomFieldId.ToString()); XmlHelper.AddNode(doc, optionXml, "OptionId", option.CustomFieldOptionId.ToString()); XmlHelper.AddNode(doc, optionXml, "Title", option.Name); XmlHelper.AddNode(doc, optionXml, "ProductCount", "0"); XmlHelper.AddNode(doc, optionXml, "FilterType", field.FilterType.ToString()); XmlHelper.AddNode(doc, optionXml, "IsCheckBox", isCheckBox.ToString().ToLower()); XmlHelper.AddNode(doc, optionXml, "IsActive", IsActive(paramName, option.CustomFieldOptionId, field.FilterType).ToString().ToLower()); //XmlHelper.AddNode(doc, optionXml, "QueryString", ""); string queryString = string.Empty; string pageUrl = BuildFilterUrl(rawUrlLeaveOutPageNumber, paramName, option.CustomFieldOptionId, field.FilterType, out queryString); //string pageUrl = urlWithoutQueryString + BuildSpecFilterQueryString(queryString, paramName, option.CustomFieldOptionId, field.FilterType); XmlHelper.AddNode(doc, optionXml, "QueryString", queryString); XmlHelper.AddNode(doc, optionXml, "Url", pageUrl); XmlHelper.AddNode(doc, optionXml, "ClearUrl", SiteUtils.BuildUrlLeaveOutParam(rawUrlLeaveOutPageNumber, paramName)); } } } //XmlElement priceXml = doc.CreateElement("Price"); //root.AppendChild(priceXml); //XmlHelper.AddNode(doc, priceXml, "Title", string.Empty); //XmlHelper.AddNode(doc, priceXml, "Url", ProductHelper.BuildFilterUrlLeaveOutPageNumber(rawUrlLeaveOutPageNumber, ProductHelper.QueryStringPriceParam, string.Empty)); XmlHelper.AddNode(doc, root, "UrlWithPrice", ProductHelper.BuildFilterUrlLeaveOutPageNumber(rawUrlLeaveOutPageNumber, true)); XmlHelper.AddNode(doc, root, "UrlWithoutPrice", SiteUtils.BuildUrlLeaveOutParam(ProductHelper.BuildFilterUrlLeaveOutPageNumber(rawUrlLeaveOutPageNumber), ProductHelper.QueryStringPriceParam)); decimal?priceMin = null; decimal?priceMax = null; ProductHelper.GetPriceFromQueryString(out priceMin, out priceMax); if (priceMin.HasValue) { XmlHelper.AddNode(doc, root, "PriceMin", priceMin.Value.ToString()); } if (priceMax.HasValue) { XmlHelper.AddNode(doc, root, "PriceMax", priceMax.Value.ToString()); } if (ProductHelper.IsAjaxRequest(Request)) { Response.Write(XmlHelper.TransformXML(SiteUtils.GetXsltBasePath("product", ModuleConfiguration.XsltFileName), doc)); if (HttpContext.Current.Items["IsAjaxResponse"] != null) { Response.End(); } HttpContext.Current.Items["IsAjaxResponse"] = true; return; } XmlHelper.XMLTransform(xmlTransformer, SiteUtils.GetXsltBasePath("product", ModuleConfiguration.XsltFileName), doc); }
private XmlDocument GetPageXml(int zoneId, int pageNumber, int pageSize, out int totalPages) { XmlDocument doc = new XmlDocument(); doc.LoadXml("<ProductList></ProductList>"); XmlElement root = doc.DocumentElement; XmlHelper.AddNode(doc, root, "ModuleTitle", this.moduleTitle); XmlHelper.AddNode(doc, root, "ZoneTitle", basePage.CurrentZone.Name); XmlHelper.AddNode(doc, root, "ZoneDescription", basePage.CurrentZone.Description); XmlHelper.AddNode(doc, root, "ViewMore", ProductResources.ViewMoreLabel); XmlHelper.AddNode(doc, root, "SiteUrl", siteRoot); XmlHelper.AddNode(doc, root, "ZoneUrl", SiteUtils.GetCurrentZoneUrl()); if (module != null && module.ResourceFileDef.Length > 0 && module.ResourceKeyDef.Length > 0) { List <string> lstResourceKeys = module.ResourceKeyDef.SplitOnCharAndTrim(';'); foreach (string item in lstResourceKeys) { XmlHelper.AddNode(doc, root, item, ResourceHelper.GetResourceString(module.ResourceFileDef, item)); } } //Render view mode BuildViewModeXml(doc, root); //Render sort mode BuildSortModeXml(doc, root); int languageId = WorkingCulture.LanguageId; List <Product> lstProducts = new List <Product>(); string propertyCondition = string.Empty; string andClause = " "; int numberGroup = 0; List <CustomField> lstCustomFields = CustomFieldHelper.GetCustomFieldsFromContext(siteSettings.SiteId, Product.FeatureGuid, basePage.CurrentZone.ZoneGuid, languageId); foreach (CustomField field in lstCustomFields) { if ( field.DataType == (int)CustomFieldDataType.CheckBox || field.DataType == (int)CustomFieldDataType.SelectBox ) { if (field.FilterType == (int)CustomFieldFilterType.ByValue) { string paramName = ProductHelper.QueryStringFilterSingleParam + field.CustomFieldId.ToString(); int optionValue = WebUtils.ParseInt32FromQueryString(paramName, -1); if (optionValue > 0) { propertyCondition += andClause + "(CustomFieldID=" + field.CustomFieldId + " AND CustomFieldOptionID=" + optionValue.ToString() + ")"; andClause = " OR "; numberGroup += 1; } } else { string paramName = ProductHelper.QueryStringFilterMultiParam + field.CustomFieldId.ToString(); string optionValues = WebUtils.ParseStringFromQueryString(paramName, string.Empty); // Split and validate data List <int> lstValues = new List <int>(); optionValues.SplitOnCharAndTrim('/').ForEach(s => { int value = -1; if (int.TryParse(s, out value)) { lstValues.Add(value); } }); if (lstValues.Count > 0) { propertyCondition += andClause + "(CustomFieldID=" + field.CustomFieldId + " AND CustomFieldOptionID IN (" + string.Join(",", lstValues.ToArray()) + "))"; andClause = " OR "; numberGroup += 1; } } } } if (numberGroup > 0) { propertyCondition = "(SELECT COUNT(DISTINCT CustomFieldID) FROM gb_ProductProperties WHERE ProductID=p.ProductID AND (" + propertyCondition + ")) = " + numberGroup.ToString(); } string keyword = null; if (config.EnableKeywordFiltering) { keyword = WebUtils.ParseStringFromQueryString(ProductHelper.QueryStringKeywordParam, null); } int sort = WebUtils.ParseInt32FromQueryString(ProductHelper.QueryStringSortModeParam, 0); decimal?priceMin; decimal?priceMax; ProductHelper.GetPriceFromQueryString(out priceMin, out priceMax); int totalRows = 0; if (numberGroup > 0 || priceMin != null || priceMax != null || sort > 0 || !string.IsNullOrEmpty(keyword) ) { string rangeZoneIds = null; if (ProductConfiguration.FilterProductByTopLevelParentZones) { var topLevelNode = SiteUtils.GetTopLevelParentNode(SiteUtils.GetSiteMapNodeByZoneId(zoneId)); if (topLevelNode != null) { rangeZoneIds = ProductHelper.GetRangeZoneIdsToSemiColonSeparatedString(siteSettings.SiteId, topLevelNode.ZoneId); } } else { if (config.ZoneIds.Length == 0) { rangeZoneIds = ProductHelper.GetRangeZoneIdsToSemiColonSeparatedString(siteSettings.SiteId, zoneId); } else { rangeZoneIds = config.ZoneIds; } } totalRows = Product.GetCountBySearch(siteSettings.SiteId, rangeZoneIds, 1, languageId, -1, -1, priceMin, priceMax, -1, -1, propertyCondition, null, keyword); if (pageSize == -1) { pageSize = totalRows; } totalPages = CaculateTotalPages(pageSize, totalRows); lstProducts = Product.GetPageBySearch(pageNumber, pageSize, siteSettings.SiteId, rangeZoneIds, 1, languageId, -1, -1, priceMin, priceMax, -1, -1, propertyCondition, null, keyword, false, null, sort); } else { if (config.ZoneIds.Length == 0) { if (config.ShowAllProducts) { string rangeZoneIds = ProductHelper.GetRangeZoneIdsToSemiColonSeparatedString(siteSettings.SiteId, zoneId); totalRows = Product.GetCountByListZone(siteSettings.SiteId, rangeZoneIds, languageId, -1); if (pageSize == -1) { pageSize = totalRows; } totalPages = CaculateTotalPages(pageSize, totalRows); lstProducts = Product.GetPageByListZone(siteSettings.SiteId, rangeZoneIds, languageId, -1, pageNumber, pageSize); } else { totalRows = Product.GetCount(siteSettings.SiteId, zoneId, languageId, -1); if (pageSize == -1) { pageSize = totalRows; } totalPages = CaculateTotalPages(pageSize, totalRows); lstProducts = Product.GetPage(siteSettings.SiteId, zoneId, languageId, -1, pageNumber, pageSize); } } else { totalRows = Product.GetCountByListZone(siteSettings.SiteId, config.ZoneIds, languageId, -1); if (pageSize == -1) { pageSize = totalRows; } totalPages = CaculateTotalPages(pageSize, totalRows); lstProducts = Product.GetPageByListZone(siteSettings.SiteId, config.ZoneIds, languageId, -1, pageNumber, pageSize); } } XmlHelper.AddNode(doc, root, "TotalProducts", totalRows.ToString()); BuildPageSizeXml(doc, root); List <int> productIds = new List <int>(); if (ProductConfiguration.EnableComparing) { productIds = ProductHelper.GetCompareProductsIds(); XmlHelper.AddNode(doc, root, "CompareProductsCount", productIds.Count.ToString()); XmlHelper.AddNode(doc, root, "CompareListUrl", siteRoot + "/Product/Compare.aspx"); List <Product> compareProducts = ProductHelper.GetCompareProducts(); foreach (Product product in compareProducts) { XmlElement productXml = doc.CreateElement("Compared"); root.AppendChild(productXml); ProductHelper.BuildProductDataXml(doc, productXml, product, timeZone, timeOffset, ProductHelper.BuildEditLink(product, basePage, userCanUpdate, currentUser)); } } List <ProductProperty> productProperties = new List <ProductProperty>(); List <CustomField> customFields = new List <CustomField>(); if (config.ShowCustomFieldsInProductList) { List <int> lstProductIds = new List <int>(); foreach (Product product in lstProducts) { lstProductIds.Add(product.ProductId); } if (lstProductIds.Count > 0) { productProperties = ProductProperty.GetPropertiesByProducts(lstProductIds); } if (productProperties.Count > 0) { var customFieldIds = new List <int>(); foreach (var property in productProperties) { if (!customFieldIds.Contains(property.CustomFieldId)) { customFieldIds.Add(property.CustomFieldId); } } var tmp = CustomField.GetActiveByFields(basePage.SiteId, Product.FeatureGuid, customFieldIds, languageId); customFields = CustomField.GetByOption(tmp, CustomFieldOptions.ShowInCatalogPages); } } foreach (Product product in lstProducts) { XmlElement productXml = doc.CreateElement("Product"); root.AppendChild(productXml); ProductHelper.BuildProductDataXml(doc, productXml, product, timeZone, timeOffset, ProductHelper.BuildEditLink(product, basePage, userCanUpdate, currentUser), productIds); if (config.ShowCustomFieldsInProductList) { BuildCustomFieldsXml(doc, productXml, product.ProductId, customFields, productProperties); } } if (pageNumber < totalPages) { string pageUrl = ProductHelper.BuildFilterUrlLeaveOutPageNumber(Request.RawUrl); if (pageUrl.Contains("?")) { pageUrl += "&" + ProductHelper.QueryStringPageNumberParam + "=" + (pageNumber + 1).ToString(); } else { pageUrl += "?" + ProductHelper.QueryStringPageNumberParam + "=" + (pageNumber + 1).ToString(); } XmlHelper.AddNode(doc, root, "NextPageUrl", pageUrl); } return(doc); }