Exemple #1
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));
            }
        }
Exemple #2
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);
        }
Exemple #3
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);
                }
            }
        }
        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);
        }
Exemple #5
0
        protected void PopulateControls()
        {
            if (parametersAreInvalid)
            {
                pnlInnerWrap.Visible = false;
                return;
            }

            if (product.IsDeleted)
            {
                if (WebConfigSettings.Custom404Page.Length > 0)
                {
                    Server.Transfer(WebConfigSettings.Custom404Page);
                }
                else
                {
                    Server.Transfer("~/PageNotFound.aspx");
                }

                return;
            }

            if (product.IsPublished && product.EndDate < DateTime.UtcNow)
            {
                expired.Visible = true;
                //http://support.google.com/webmasters/bin/answer.py?hl=en&answer=40132
                // 410 means the resource is gone but once existed
                // google treats it as more permanent than a 404
                // and it should result in de-indexing the content
                Response.StatusCode        = 410;
                Response.StatusDescription = "Content Expired";
                if (
                    !ProductPermission.CanUpdate ||
                    !basePage.UserCanAuthorizeZone(product.ZoneId)
                    )
                {
                    pnlInnerWrap.Visible = false;
                    return;
                }
            }

            // if not published only the editor can see it
            if ((!product.IsPublished) || (product.StartDate > DateTime.UtcNow))
            {
                bool stopRedirect = false;
                if (
                    (currentUser != null && currentUser.UserGuid == product.UserGuid) ||
                    ((ProductPermission.CanViewList || ProductPermission.CanUpdate) && basePage.UserCanAuthorizeZone(product.ZoneId))
                    )
                {
                    stopRedirect = true;
                }

                if (!stopRedirect)
                {
                    pnlInnerWrap.Visible = false;
                    WebUtils.SetupRedirect(this, SiteUtils.GetCurrentZoneUrl());
                    return;
                }
            }

            SetupMetaTags();

            XmlDocument doc = new XmlDocument();

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

            XmlHelper.AddNode(doc, root, "ZoneTitle", basePage.CurrentZone.Name);
            XmlHelper.AddNode(doc, root, "Title", product.Title);
            XmlHelper.AddNode(doc, root, "SubTitle", product.SubTitle);
            XmlHelper.AddNode(doc, root, "ZoneUrl", SiteUtils.GetCurrentZoneUrl());

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

            XmlHelper.AddNode(doc, root, "EditLink", ProductHelper.BuildEditLink(product, basePage, userCanUpdate, currentUser));

            XmlHelper.AddNode(doc, root, "ProductId", product.ProductId.ToString());
            XmlHelper.AddNode(doc, root, "ShowOption", product.ShowOption.ToString());
            XmlHelper.AddNode(doc, root, "ProductType", product.ProductType.ToString());

            XmlHelper.AddNode(doc, root, "Code", product.Code);
            if (product.Price > 0)
            {
                XmlHelper.AddNode(doc, root, "Price", ProductHelper.FormatPrice(product.Price, true));
            }
            if (product.OldPrice > 0)
            {
                XmlHelper.AddNode(doc, root, "OldPrice", ProductHelper.FormatPrice(product.OldPrice, true));
            }

            XmlHelper.AddNode(doc, root, "CreatedDate", ProductHelper.FormatDate(product.StartDate, timeZone, timeOffset,
                                                                                 ProductResources.ProductDateFormat));
            XmlHelper.AddNode(doc, root, "CreatedTime", ProductHelper.FormatDate(product.StartDate, timeZone, timeOffset,
                                                                                 ProductResources.ProductTimeFormat));
            XmlHelper.AddNode(doc, root, "CreatedDD", ProductHelper.FormatDate(product.StartDate, timeZone, timeOffset, "dd"));
            XmlHelper.AddNode(doc, root, "CreatedYY", ProductHelper.FormatDate(product.StartDate, timeZone, timeOffset, "yy"));
            XmlHelper.AddNode(doc, root, "CreatedYYYY", ProductHelper.FormatDate(product.StartDate, timeZone, timeOffset, "yyyy"));
            XmlHelper.AddNode(doc, root, "CreatedMM", ProductHelper.FormatDate(product.StartDate, timeZone, timeOffset, "MM"));
            if (WorkingCulture.DefaultName.ToLower() == "vi-vn")
            {
                string monthVI = "Tháng " + ProductHelper.FormatDate(product.StartDate, timeZone, timeOffset, "MM");
                XmlHelper.AddNode(doc, root, "CreatedMMM", monthVI);
                XmlHelper.AddNode(doc, root, "CreatedMMMM", monthVI);
            }
            else
            {
                XmlHelper.AddNode(doc, root, "CreatedMMM", ProductHelper.FormatDate(product.StartDate, timeZone, timeOffset, "MMM"));
                XmlHelper.AddNode(doc, root, "CreatedMMMM", ProductHelper.FormatDate(product.StartDate, timeZone, timeOffset, "MMMM"));
            }

            XmlHelper.AddNode(doc, root, "Code", product.Code);
            XmlHelper.AddNode(doc, root, "BriefContent", product.BriefContent);
            XmlHelper.AddNode(doc, root, "FullContent", product.FullContent);
            XmlHelper.AddNode(doc, root, "ViewCount", product.ViewCount.ToString());
            XmlHelper.AddNode(doc, root, "FileUrl", product.FileAttachment);

            if (
                displaySettings.ShowNextPreviousLink &&
                !config.LoadFirstProduct
                )
            {
                BuildNextPreviousXml(doc, root);
            }

            string pageUrl = ProductHelper.FormatProductUrl(product.Url, product.ProductId, product.ZoneId);

            XmlHelper.AddNode(doc, root, "FacebookLike", RenderFacebookLike());
            XmlHelper.AddNode(doc, root, "PlusOne", RenderPlusOne());
            XmlHelper.AddNode(doc, root, "TweetThis", RenderTweetThis());
            XmlHelper.AddNode(doc, root, "Print", RenderPrinter());
            //XmlHelper.AddNode(doc, root, "Email", RenderEmailSubject());
            XmlHelper.AddNode(doc, root, "FullUrl", pageUrl);

            BuildProductRelatedXml(doc, root, languageId);

            if (ProductConfiguration.EnableComparing)
            {
                XmlHelper.AddNode(doc, root, "CompareListUrl", siteRoot + "/Product/Compare.aspx");
            }

            if (displaySettings.ShowAttribute)
            {
                BuildProductAttributesXml(doc, root, languageId);
            }

            BuildProductPropertiesXml(doc, root, languageId);
            BuildProductMediaXml(doc, root);
            BuildProductOtherXml(doc, root, zoneId, pageNumber, config.OtherProductsPerPage, out totalPages);

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

            if (pageUrl.Contains("?"))
            {
                pageUrl += "&amp;pagenumber={0}";
            }
            else
            {
                pageUrl += "?pagenumber={0}";
            }

            pgr.PageURLFormat = pageUrl;
            pgr.ShowFirstLast = true;
            pgr.PageSize      = config.OtherProductsPerPage;
            pgr.PageCount     = totalPages;
            pgr.CurrentIndex  = pageNumber;
            divPager.Visible  = (totalPages > 1);

            XmlHelper.XMLTransform(xmlTransformer, SiteUtils.GetXsltBasePath("product", config.XsltFileNameDetailPage), doc);

            if (Page.Header == null)
            {
                return;
            }

            string canonicalUrl = ProductHelper.FormatProductUrl(product.Url, product.ProductId, product.ZoneId);

            if (SiteUtils.IsSecureRequest() && (!basePage.CurrentPage.RequireSsl) && (!basePage.SiteInfo.UseSslOnAllPages))
            {
                if (WebConfigSettings.ForceHttpForCanonicalUrlsThatDontRequireSsl)
                {
                    canonicalUrl = canonicalUrl.Replace("https:", "http:");
                }
            }

            //LoadWorkflow();

            //Literal link = new Literal();
            //link.ID = "newsurl";
            //link.Text = "\n<link rel='canonical' href='" + canonicalUrl + "' />";

            //Page.Header.Controls.Add(link);

            Product.IncrementViewCount(product.ProductId);
        }
Exemple #6
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);
            }
        }