コード例 #1
0
        private void PopulateControls()
        {
            XmlDocument doc = new XmlDocument();

            doc.LoadXml("<ProductList></ProductList>");
            XmlElement root = doc.DocumentElement;

            XmlHelper.AddNode(doc, root, "ModuleTitle", this.Title);
            XmlHelper.AddNode(doc, root, "ZoneTitle", CurrentZone.Name);
            XmlHelper.AddNode(doc, root, "ViewMore", ProductResources.ViewMoreLabel);

            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));
                }
            }

            CmsBasePage basePage      = Page as CmsBasePage;
            bool        userCanUpdate = ProductPermission.CanUpdate;
            SiteUser    currentUser   = SiteUtils.GetCurrentSiteUser();

            List <Product> lstProducts = new List <Product>();

            if (ProductConfiguration.RecentlyViewedProductsEnabled && config.Position == 0)
            {
                lstProducts = ProductHelper.GetRecentlyViewedProducts(config.MaxProductsToGet);
            }
            else if (config.ZoneId > -1)
            {
                int zoneId = config.ZoneId;
                if (zoneId == 0)
                {
                    zoneId = CurrentZone.ZoneId;
                }

                string zoneRangeIds = ProductHelper.GetRangeZoneIdsToSemiColonSeparatedString(siteSettings.SiteId, zoneId);
                lstProducts = Product.GetPageBySearch(1, config.MaxProductsToGet, siteSettings.SiteId, zoneRangeIds, 1, WorkingCulture.LanguageId, -1, -1, null, null, config.Position);
            }
            else
            {
                lstProducts = Product.GetPage(SiteId, -1, WorkingCulture.LanguageId, config.Position, 1, config.MaxProductsToGet);
            }

            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));
            }

            XmlHelper.XMLTransform(xmlTransformer, SiteUtils.GetXsltBasePath("product", ModuleConfiguration.XsltFileName), doc);
        }
コード例 #2
0
        public void BuildProductRelatedXml(
            XmlDocument doc,
            XmlElement root, int languageId)
        {
            List <Product> lstProducts = Product.GetRelatedProducts(basePage.SiteId, product.ProductGuid, false,
                                                                    ProductConfiguration.RelatedProductsTwoWayRelationship);

            foreach (Product productRelated in lstProducts)
            {
                XmlElement productXml = doc.CreateElement("ProductRelated");
                root.AppendChild(productXml);

                ProductHelper.BuildProductDataXml(doc, productXml, productRelated, timeZone, timeOffset,
                                                  ProductHelper.BuildEditLink(productRelated, basePage, userCanUpdate, currentUser));
            }
        }
コード例 #3
0
ファイル: SuggestSearch.ashx.cs プロジェクト: sang-nm/mphc
        public void ProcessRequest(HttpContext context)
        {
            Encoding encoding = new UTF8Encoding();

            context.Response.ContentEncoding = encoding;

            string query = WebUtils.ParseStringFromQueryString("q", string.Empty);

            if (query.Length == 0)
            {
                return;
            }

            //https://weblearn.ox.ac.uk/portal/help/TOCDisplay/content.hlp?docId=howdoiperformanadvancedsearch
            if (WebConfigSettings.EscapingSpecialCharactersInKeyword) //Escaping Special Characters: + - && || ! ( ) { } [ ] ^ " ~ * ? : \
            {
                query = query.Replace("-", "\\-")
                        .Replace("+", "\\+")
                        .Replace("&&", "\\&&")
                        .Replace("||", "\\||")
                        .Replace("!", "\\!")
                        .Replace("(", "\\(")
                        .Replace(")", "\\)")
                        .Replace("{", "\\{")
                        .Replace("}", "\\}")
                        .Replace("[", "\\[")
                        .Replace("]", "\\]")
                        .Replace("^", "\\^")
                        .Replace("\"", "\\\"")
                        .Replace("~", "\\~")
                        .Replace("*", "\\*")
                        .Replace("?", "\\?")
                        .Replace(":", "\\:")
                        .Replace("\\", "\\\\")
                ;
            }

            query = query.Trim().Replace(" ", " + ") + "*";

            SiteSettings siteSettings       = CacheHelper.GetCurrentSiteSettings();
            int          pageSize           = 20;
            int          totalHits          = 1;
            bool         queryErrorOccurred = false;
            bool         isSiteEditor       = WebUser.IsAdminOrContentAdmin || (SiteUtils.UserIsSiteEditor());
            string       result             = string.Empty;

            CanhCam.SearchIndex.IndexItemCollection searchResults = CanhCam.SearchIndex.IndexHelper.Search(
                siteSettings.SiteId,
                isSiteEditor,
                GetUserRoles(context, siteSettings.SiteId),
                Product.FeatureGuid,
                WorkingCulture.DefaultName,
                DateTime.MinValue,
                DateTime.MaxValue,
                query,
                false,
                WebConfigSettings.SearchResultsFragmentSize,
                1,
                pageSize,
                WebConfigSettings.SearchMaxClauseCount,
                out totalHits,
                out queryErrorOccurred);

            if (searchResults.Count > 0)
            {
                string productGuids = string.Empty;
                string sepa         = string.Empty;
                foreach (IndexItem item in searchResults)
                {
                    if (!productGuids.ContainsCaseInsensitive(item.ItemGuid.ToString()))
                    {
                        productGuids += sepa + item.ItemGuid.ToString();
                        sepa          = ";";
                    }
                }

                if (productGuids.Length > 0)
                {
                    XmlDocument doc = new XmlDocument();
                    doc.LoadXml("<ProductList></ProductList>");
                    XmlElement root = doc.DocumentElement;

                    var timeOffset = SiteUtils.GetUserTimeOffset();
                    var timeZone   = SiteUtils.GetUserTimeZone();

                    List <Product> lstProducts = Product.GetByGuids(siteSettings.SiteId, productGuids, 1, WorkingCulture.LanguageId);
                    foreach (Product product in lstProducts)
                    {
                        XmlElement productXml = doc.CreateElement("Product");
                        root.AppendChild(productXml);

                        ProductHelper.BuildProductDataXml(doc, productXml, product, timeZone, timeOffset, string.Empty);
                    }

                    result = XmlHelper.TransformXML(SiteUtils.GetXsltBasePath("product", "ProductSuggestSearch.xslt"), doc);
                }
            }

            if (result.Length > 0)
            {
                context.Response.Write(result);
            }
            else
            {
                context.Response.Write(" ");
            }

            context.Response.End();
        }
コード例 #4
0
ファイル: PurchaseHistory.aspx.cs プロジェクト: sang-nm/mphc
        private void PopulateControls()
        {
            DateTime?startDate = null;

            if (txtDays.Text.Length > 0)
            {
                int days = -1;
                int.TryParse(txtDays.Text, out days);

                if (days > 0)
                {
                    DateTime localTime = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 0, 0, 0).AddDays(-days);

                    if (timeZone != null)
                    {
                        startDate = localTime.ToUtc(timeZone);
                    }
                    else
                    {
                        startDate = localTime.AddHours(-timeOffset);
                    }
                }
            }

            List <OrderItem> lstOrderItems = OrderItem.GetPageBySearch(siteSettings.SiteId, -1, -1, -1, -1, startDate, null, null, null,
                                                                       siteUser.UserGuid, null, pageNumber, pageSize);

            if (lstOrderItems.Count > 0)
            {
                string productGuids = string.Empty;
                string attribute    = string.Empty;
                foreach (OrderItem orderItem in lstOrderItems)
                {
                    productGuids += orderItem.ProductGuid.ToString() + ";";

                    string tmp = orderItem.AttributesXml;
                    if (tmp.Length > 0)
                    {
                        tmp += ";";
                    }

                    //if (orderItem.AttributeDescription.Length > 0)
                    //    tmp += orderItem.AttributeDescription + ";";

                    attribute += tmp;
                }

                if (attribute.Length > 0)
                {
                    lstOptions = CustomFieldOption.GetByOptionIds(siteSettings.SiteId, attribute);
                }

                List <Product> lstProducts = Product.GetByGuids(siteSettings.SiteId, productGuids, -1, WorkingCulture.LanguageId);

                XmlDocument doc = new XmlDocument();

                doc.LoadXml("<ProductList></ProductList>");
                XmlElement root = doc.DocumentElement;

                lstOrderItems.ForEach(orderItem => {
                    Product product = ProductHelper.GetProductFromList(lstProducts, orderItem.ProductId);

                    if (product != null)
                    {
                        XmlElement productXml = doc.CreateElement("Product");
                        root.AppendChild(productXml);

                        ProductHelper.BuildProductDataXml(doc, productXml, product, null);

                        // Order detail
                        XmlHelper.AddNode(doc, productXml, "OrderCode", orderItem.Order.OrderCode);
                        XmlHelper.AddNode(doc, productXml, "OrderDate", FormatDate(orderItem.Order.CreatedUtc, "dd/MM/yyyy"));
                        XmlHelper.AddNode(doc, productXml, "OrderStatus", ProductHelper.GetOrderStatus(orderItem.Order.OrderStatus));
                        XmlHelper.AddNode(doc, productXml, "OrderTotal",
                                          ProductHelper.FormatPrice(orderItem.Quantity * orderItem.Price - orderItem.DiscountAmount, true));
                    }
                });

                XmlHelper.XMLTransform(xmlTransformer, SiteUtils.GetXsltBasePath("Product", "PurchaseHistory.xslt"), doc);
            }
        }
コード例 #5
0
        private void RenderNode(XmlDocument doc, XmlElement xmlElement, gbSiteMapNode gbNode)
        {
            if (!ShouldRender(gbNode))
            {
                return;
            }

            XmlElement item = doc.CreateElement("Zone");

            xmlElement.AppendChild(item);

            XmlHelper.AddNode(doc, item, "ZoneId", gbNode.ZoneId.ToInvariantString());
            XmlHelper.AddNode(doc, item, "Depth", gbNode.Depth.ToInvariantString());
            XmlHelper.AddNode(doc, item, "ChildCount", gbNode.ChildNodes.Count.ToInvariantString());
            XmlHelper.AddNode(doc, item, "IsClickable", gbNode.IsClickable.ToString().ToLower());
            XmlHelper.AddNode(doc, item, "Url", FormatUrl(gbNode));
            XmlHelper.AddNode(doc, item, "Target", (gbNode.OpenInNewWindow == true ? "_blank" : "_self"));
            XmlHelper.AddNode(doc, item, "Title", GetZoneTitle(gbNode));
            XmlHelper.AddNode(doc, item, "Description", GetDescription(gbNode));
            XmlHelper.AddNode(doc, item, "ImageUrl", gbNode.PrimaryImage);

            List <Product> lstProducts = new List <Product>();

            if (config.ShowAllProducts)
            {
                string zoneIds = ProductHelper.GetRangeZoneIdsToSemiColonSeparatedString(siteSettings.SiteId, gbNode.ZoneId);
                if (config.MaxItemsToGet == 0)
                {
                    int iCount = Product.GetCountByListZone(siteSettings.SiteId, zoneIds, languageId, config.ProductPosition);
                    XmlHelper.AddNode(doc, item, "ProductCount", iCount.ToString());
                }
                else if (config.MaxItemsToGet > 0)
                {
                    lstProducts = Product.GetPageByListZone(siteSettings.SiteId, zoneIds, languageId, config.ProductPosition, 1, config.MaxItemsToGet);
                }
                else
                {
                    int iCount = Product.GetCountByListZone(siteSettings.SiteId, zoneIds, languageId, config.ProductPosition);
                    XmlHelper.AddNode(doc, item, "ProductCount", iCount.ToString());

                    lstProducts = Product.GetPageByListZone(siteSettings.SiteId, zoneIds, languageId, config.ProductPosition, 1, Math.Abs(config.MaxItemsToGet));
                }
            }
            else
            {
                if (config.MaxItemsToGet == 0)
                {
                    int iCount = Product.GetCount(siteSettings.SiteId, gbNode.ZoneId, languageId, config.ProductPosition);
                    XmlHelper.AddNode(doc, item, "ProductCount", iCount.ToString());
                }
                else if (config.MaxItemsToGet > 0)
                {
                    lstProducts = Product.GetPage(siteSettings.SiteId, gbNode.ZoneId, languageId, config.ProductPosition, 1, config.MaxItemsToGet);
                }
                else
                {
                    int iCount = Product.GetCount(siteSettings.SiteId, gbNode.ZoneId, languageId, config.ProductPosition);
                    XmlHelper.AddNode(doc, item, "ProductCount", iCount.ToString());

                    lstProducts = Product.GetPage(siteSettings.SiteId, gbNode.ZoneId, languageId, config.ProductPosition, 1, Math.Abs(config.MaxItemsToGet));
                }
            }

            foreach (Product product in lstProducts)
            {
                XmlElement productXml = doc.CreateElement("Product");
                item.AppendChild(productXml);

                ProductHelper.BuildProductDataXml(doc, productXml, product, timeZone, timeOffset, ProductHelper.BuildEditLink(product, basePage, userCanUpdate, currentUser));
            }

            if ((currentNode != null) &&
                (currentNode.ZoneGuid == gbNode.ZoneGuid)    // Selected
                )
            {
                XmlHelper.AddNode(doc, item, "IsActive", "true");
            }
            else
            {
                XmlHelper.AddNode(doc, item, "IsActive", "false");
            }

            if (gbNode.ChildNodes.Count > 0)
            {
                foreach (SiteMapNode childNode in gbNode.ChildNodes)
                {
                    gbSiteMapNode gbChildNode = childNode as gbSiteMapNode;
                    if (gbChildNode == null)
                    {
                        continue;
                    }

                    RenderNode(doc, item, gbChildNode);
                }
            }
        }
コード例 #6
0
ファイル: SearchResults.aspx.cs プロジェクト: sang-nm/mphc
        private void DoSearch()
        {
            if (Page.IsPostBack)
            {
                return;
            }

            if (Request.QueryString.Get("q") == null)
            {
                return;
            }

            query = Request.QueryString.Get("q");

            if (this.query.Length == 0)
            {
                return;
            }

            //txtSearchInput.Text = Server.HtmlEncode(query).Replace("&quot;", "\"") ;
            txtSearchInput.Text = SecurityHelper.SanitizeHtml(query);

            //https://weblearn.ox.ac.uk/portal/help/TOCDisplay/content.hlp?docId=howdoiperformanadvancedsearch
            string queryToSearch = query;

            if (WebConfigSettings.EscapingSpecialCharactersInKeyword) //Escaping Special Characters: + - && || ! ( ) { } [ ] ^ " ~ * ? : \
            {
                queryToSearch = queryToSearch.Replace("-", "\\-")
                                .Replace("+", "\\+")
                                .Replace("&&", "\\&&")
                                .Replace("||", "\\||")
                                .Replace("!", "\\!")
                                .Replace("(", "\\(")
                                .Replace(")", "\\)")
                                .Replace("{", "\\{")
                                .Replace("}", "\\}")
                                .Replace("[", "\\[")
                                .Replace("]", "\\]")
                                .Replace("^", "\\^")
                                .Replace("\"", "\\\"")
                                .Replace("~", "\\~")
                                .Replace("*", "\\*")
                                .Replace("?", "\\?")
                                .Replace(":", "\\:")
                                .Replace("\\", "\\\\")
                ;
            }

            if (ConfigHelper.GetBoolProperty("Product:AppendWildcardToEndKeyword", false) && query.Length > 1)
            {
                queryToSearch = queryToSearch + "*";
            }

            queryErrorOccurred = false;

            CanhCam.SearchIndex.IndexItemCollection searchResults = CanhCam.SearchIndex.IndexHelper.Search(
                siteSettings.SiteId,
                isSiteEditor,
                GetUserRoles(),
                Product.FeatureGuid,
                CultureInfo.CurrentUICulture.Name,
                DateTime.MinValue,
                DateTime.MaxValue,
                queryToSearch,
                WebConfigSettings.EnableSearchResultsHighlighting,
                WebConfigSettings.SearchResultsFragmentSize,
                pageNumber,
                pageSize,
                WebConfigSettings.SearchMaxClauseCount,
                out totalHits,
                out queryErrorOccurred);

            XmlDocument doc = new XmlDocument();

            doc.LoadXml("<ProductList></ProductList>");
            XmlElement root = doc.DocumentElement;

            XmlHelper.AddNode(doc, root, "SiteRoot", SiteRoot);
            XmlHelper.AddNode(doc, root, "TotalProducts", totalHits.ToString());
            XmlHelper.AddNode(doc, root, "Keyword", Server.HtmlEncode(query));
            XmlHelper.AddNode(doc, root, "ProductText", ResourceHelper.GetResourceString("ProductResources", "ProductFeatureName"));
            XmlHelper.AddNode(doc, root, "NewsText", ResourceHelper.GetResourceString("ProductResources", "NewsFeatureName"));

            if (searchResults.Count == 0)
            {
                if (InitIndexIfNeeded())
                {
                    return;
                }

                if (txtSearchInput.Text.Length > 0)
                {
                    string noResults = Resources.ProductResources.SearchResultsNotFound;
                    if (queryErrorOccurred)
                    {
                        noResults = ResourceHelper.GetResourceString("Resource", "SearchQueryInvalid");
                    }

                    XmlHelper.AddNode(doc, root, "NoResults", noResults);
                }
            }
            else
            {
                float  duration     = searchResults.ExecutionTime * 0.0000001F;
                string searchSumary = string.Format(Resources.ProductResources.SearchResultsFormat, totalHits.ToString(CultureInfo.InvariantCulture), Server.HtmlEncode(query), duration.ToString());

                XmlHelper.AddNode(doc, root, "SearchSumary", searchSumary);
                XmlHelper.AddNode(doc, root, "Duration", duration.ToString());

                totalPages = 1;

                if (pageSize > 0)
                {
                    totalPages = totalHits / pageSize;
                }

                if (totalHits <= pageSize)
                {
                    totalPages = 1;
                }
                else
                {
                    int remainder;
                    Math.DivRem(totalHits, pageSize, out remainder);
                    if (remainder > 0)
                    {
                        totalPages += 1;
                    }
                }

                string searchUrl = SiteRoot
                                   + "/Product/SearchResults.aspx?q=" + Server.UrlEncode(query)
                                   + "&amp;p={0}";

                pgrTop.PageURLFormat = searchUrl;
                pgrTop.ShowFirstLast = true;
                pgrTop.CurrentIndex  = pageNumber;
                pgrTop.PageSize      = pageSize;
                pgrTop.PageCount     = totalPages;
                pgrTop.Visible       = (totalPages > 1);

                pgrBottom.PageURLFormat = searchUrl;
                pgrBottom.ShowFirstLast = true;
                pgrBottom.CurrentIndex  = pageNumber;
                pgrBottom.PageSize      = pageSize;
                pgrBottom.PageCount     = totalPages;
                pgrBottom.Visible       = (totalPages > 1);

                string productGuids = string.Empty;
                string sepa         = string.Empty;
                foreach (IndexItem item in searchResults)
                {
                    if (!productGuids.ContainsCaseInsensitive(item.ItemGuid.ToString()))
                    {
                        productGuids += sepa + item.ItemGuid.ToString();
                        sepa          = ";";
                    }
                }

                if (productGuids.Length > 0)
                {
                    List <Product> lstProducts = Product.GetByGuids(siteSettings.SiteId, productGuids, 1, WorkingCulture.LanguageId);
                    foreach (Product product in lstProducts)
                    {
                        XmlElement productXml = doc.CreateElement("Product");
                        root.AppendChild(productXml);

                        ProductHelper.BuildProductDataXml(doc, productXml, product, timeZone, timeOffset, string.Empty);

                        if (WebConfigSettings.EnableSearchResultsHighlighting)
                        {
                            foreach (IndexItem item in searchResults)
                            {
                                if (item.ItemGuid == product.ProductGuid)
                                {
                                    XmlHelper.AddNode(doc, productXml, "HighlightContent", item.Intro);

                                    break;
                                }
                            }
                        }
                    }
                }
            }

            XmlHelper.XMLTransform(xmlTransformer, SiteUtils.GetXsltBasePath("product", "ProductSearchResults.xslt"), doc);
        }
コード例 #7
0
        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);
        }
コード例 #8
0
        public void BuildProductOtherXml(
            XmlDocument doc,
            XmlElement root,
            int zoneId,
            int pageNumber,
            int pageSize,
            out int totalPages)
        {
            XmlHelper.AddNode(doc, root, "ProductOtherText", ProductResources.OtherProductLabel);

            int siteId = CacheHelper.GetCurrentSiteSettings().SiteId;

            List <Product> lstProducts = new List <Product>();

            if (pageSize < 0)
            {
                pageSize   = -pageSize;
                totalPages = 1;
                int totalRows = Product.GetCount(basePage.SiteId, zoneId, languageId, -1);

                if (pageSize > 0)
                {
                    totalPages = totalRows / pageSize;
                }

                if (totalRows <= pageSize)
                {
                    totalPages = 1;
                }
                else if (pageSize > 0)
                {
                    int remainder;
                    Math.DivRem(totalRows, pageSize, out remainder);
                    if (remainder > 0)
                    {
                        totalPages += 1;
                    }
                }

                lstProducts = Product.GetPage(siteId, zoneId, languageId, -1, pageNumber, pageSize);
            }
            else
            {
                lstProducts = Product.GetPageProductOther(zoneId, product.ProductId, languageId, pageNumber, pageSize, out totalPages);
            }

            foreach (Product productOther in lstProducts)
            {
                XmlElement productXml = doc.CreateElement("ProductOther");
                root.AppendChild(productXml);

                ProductHelper.BuildProductDataXml(doc, productXml, productOther, timeZone, timeOffset,
                                                  ProductHelper.BuildEditLink(productOther, basePage, userCanUpdate, currentUser));

                if (productOther.ProductId == productId)
                {
                    XmlHelper.AddNode(doc, productXml, "IsActive", "true");
                }
                else
                {
                    XmlHelper.AddNode(doc, productXml, "IsActive", "false");
                }
            }

            if (pageNumber < totalPages)
            {
                string pageUrl = ProductHelper.FormatProductUrl(product.Url, product.ProductId, product.ZoneId);

                if (config.LoadFirstProduct)
                {
                    pageUrl = SiteUtils.GetCurrentZoneUrl();
                }

                if (pageUrl.Contains("?"))
                {
                    pageUrl += "&pagenumber=" + (pageNumber + 1).ToString();
                }
                else
                {
                    pageUrl += "?pagenumber=" + (pageNumber + 1).ToString();
                }

                XmlHelper.AddNode(doc, root, "NextPageUrl", pageUrl);
            }
        }