Exemple #1
0
        private IList <BreadCrumbItem> GetChildItems(BreadCrumbItem item)
        {
            List <BreadCrumbItem> childItems = new List <BreadCrumbItem>();

            if (item.Title == "Catalog")
            {
                childItems.Add(new BreadCrumbItem("Categories", this.Page.ResolveUrl("~/admin/catalog/browse.aspx"), "root"));
                Category category = CategoryDataSource.Load(AbleCommerce.Code.PageHelper.GetCategoryId());
                if (category != null)
                {
                    string editUrl = this.Page.ResolveUrl("~/admin/catalog/browse.aspx?CategoryId=");
                    IList <CatalogPathNode> path = CatalogDataSource.GetPath(category.Id, false);
                    foreach (CatalogPathNode pathNode in path)
                    {
                        childItems.Add(new BreadCrumbItem(pathNode.Name, editUrl + pathNode.CatalogNodeId, "parent"));
                    }
                }

                /*
                 * Product product = ProductDataSource.Load(AbleCommerce.Code.PageHelper.GetProductId());
                 * if (product != null)
                 * {
                 *  string editUrl = "~/admin/products/editproduct.aspx?";
                 *  if (category != null) editUrl += "CategoryId=" + category.Id + "&";
                 *  editUrl += "ProductId=" + product.Id;
                 *  editUrl = this.Page.ResolveUrl(editUrl);
                 *  childItems.Add(new BreadCrumbItem(product.Name, editUrl, "parent"));
                 * }
                 */
            }
            return(childItems);
        }
        protected string GetCatalogItemName(Object dataItem)
        {
            CustomUrl    customUrl = (CustomUrl)dataItem;
            ICatalogable node      = CatalogDataSource.Load(customUrl.CatalogNodeId, customUrl.CatalogNodeType);

            return(node.Name);
        }
Exemple #3
0
        protected void Page_Load(object sender, EventArgs e)
        {
            _CategoryId = AlwaysConvert.ToInt(Request.QueryString["CategoryId"]);
            InitializeCatalogItems();

            // INITIALIZE ICON PATH
            _IconPath = AbleCommerce.Code.PageHelper.GetAdminThemeIconPath(this.Page);

            CGrid.DataSource = _CatalogItems;
            CGrid.DataBind();

            if (!Page.IsPostBack)
            {
                //Caption.Text = string.Format(Caption.Text, CatalogNode.Name);

                //SET THE CURRENT PATH
                IList <CatalogPathNode> currentPath = CatalogDataSource.GetPath(_CategoryId, false);
                CurrentPath.DataSource = currentPath;
                CurrentPath.DataBind();

                //INITIALIZE THE TREE
                InitializeCategoryTree();
            }

            if (_Categories != null && _Categories.Count > 0 && MoveOptions.Items.Count > 2)
            {
                MoveOptions.Items.RemoveAt(2);
            }
        }
 protected void Page_Load(object sender, EventArgs e)
 {
     _CategoryId   = AbleCommerce.Code.PageHelper.GetCategoryId();
     _Category     = CategoryDataSource.Load(_CategoryId);
     _CatalogNodes = CatalogDataSource.LoadForCategory(_CategoryId, false);
     if (_CatalogNodes != null && _CatalogNodes.Count > 0)
     {
         if (_Category == null)
         {
             Caption.Text += " Sort Items in Root Category";
         }
         else
         {
             Caption.Text += " Sort Items in " + _Category.Name;
         }
         if (!Page.IsPostBack)
         {
             BindCatalogNodesList();
         }
     }
     else
     {
         Response.Redirect("Browse.aspx");
     }
 }
Exemple #5
0
        public void Given_FilePath_Null_Then_ExportToCsv_Returns_False()
        {
            string            filePath          = null;
            CatalogDataSource catalogDataSource = new CatalogDataSource();
            bool isSuccess = catalogDataSource.ExportToCsv(filePath);

            Assert.IsFalse(isSuccess);
        }
 protected void Page_PreRender(object sender, System.EventArgs e)
 {
     if (!initialized)
     {
         this.CategoryId = AbleCommerce.Code.PageHelper.GetCategoryId();
     }
     if (this.CategoryId != 0)
     {
         IList <CatalogPathNode> path = CatalogDataSource.GetPath(this.CategoryId, false);
         Repeater1.DataSource = path;
         Repeater1.DataBind();
     }
 }
 /// <summary>
 /// Gets the merchant category for a product
 /// </summary>
 /// <param name="product">The product</param>
 /// <returns>The merchant category for the product</returns>
 private static string GetProductType(Product product)
 {
     if (product.Categories.Count > 0)
     {
         IList <CatalogPathNode> pathNodes     = CatalogDataSource.GetPath(product.Categories[0], false);
         List <string>           categoryNames = new List <string>();
         foreach (CatalogPathNode node in pathNodes)
         {
             categoryNames.Add(node.Name);
         }
         return(string.Join(" > ", categoryNames.ToArray()));
     }
     return(string.Empty);
 }
        private IList <Category> GetSubcategories(int categoryId)
        {
            // GET ALL NODES IN THE CATEGORY
            IList <CatalogNode> allNodes = CatalogDataSource.LoadForCategory(categoryId, true, "OrderBy");

            // EXTRACT THE CATEGORY NODES
            IList <Category> categoryNodes = new List <Category>();

            foreach (CatalogNode node in allNodes)
            {
                if (node.CatalogNodeType == CatalogNodeType.Category && node.ChildObject != null)
                {
                    categoryNodes.Add((Category)node.ChildObject);
                }
            }
            return(categoryNodes);
        }
Exemple #9
0
        protected string GetCategories(Object dataItem)
        {
            Webpage       webpage       = (Webpage)dataItem;
            List <string> categoryPaths = new List <string>();

            foreach (int categoryId in webpage.Categories)
            {
                IList <CatalogPathNode> pathNodes     = CatalogDataSource.GetPath(categoryId, false);
                List <string>           pathNodeNames = new List <string>();
                foreach (CatalogPathNode pathNode in pathNodes)
                {
                    pathNodeNames.Add(pathNode.Name);
                }
                categoryPaths.Add(string.Format("<a href='{0}'>{1}</a>", Page.ResolveUrl("~/Admin/Catalog/EditCategory.aspx?CategoryId=" + categoryId), String.Join(" > ", pathNodeNames.ToArray())));
            }
            return(String.Join(", ", categoryPaths.ToArray()));
        }
        private void UpdateChildNodes(int categoryId, CatalogVisibility visibility)
        {
            IList <CatalogNode>     children = CatalogDataSource.LoadForCategory(categoryId, false);
            IDatabaseSessionManager database = AbleContext.Current.Database;

            database.BeginTransaction();
            foreach (CatalogNode child in children)
            {
                child.Visibility             = visibility;
                child.ChildObject.Visibility = visibility;
                child.Save(true);
                if (child.CatalogNodeType == CatalogNodeType.Category)
                {
                    UpdateChildNodes(child.CatalogNodeId, visibility);
                }
            }
            database.CommitTransaction();
        }
Exemple #11
0
 protected void Page_PreRender(object sender, System.EventArgs e)
 {
     HomeLink.NavigateUrl = AbleCommerce.Code.NavigationHelper.GetHomeUrl();
     if (this.CategoryId != 0)
     {
         IList <CatalogPathNode> path = CatalogDataSource.GetPath(CategoryId, false);
         BreadCrumbsRepeater.DataSource = path;
         BreadCrumbsRepeater.DataBind();
         if ((HideLastNode) && (BreadCrumbsRepeater.Controls.Count > 0))
         {
             BreadCrumbsRepeater.Controls[(BreadCrumbsRepeater.Controls.Count - 1)].Visible = false;
         }
     }
     else
     {
         BreadCrumbsRepeater.Visible = false;
     }
 }
        protected void ProductsGrid_RowCommand(object sender, System.Web.UI.WebControls.GridViewCommandEventArgs e)
        {
            if (e.CommandName.StartsWith("Do_"))
            {
                int     productId = AlwaysConvert.ToInt(e.CommandArgument);
                Product product   = ProductDataSource.Load(productId);
                switch (e.CommandName)
                {
                case "Do_Copy":
                    int newProductId = CatalogDataSource.Copy(productId, CatalogNodeType.Product, 0);
                    Response.Redirect(string.Format("EditProduct.aspx?ProductId={0}", newProductId));
                    break;

                case "Do_Delete":
                    if (product != null)
                    {
                        product.Delete();
                    }
                    break;

                case "Do_Pub":
                    // TOGGLE VISIBILITY
                    switch (product.Visibility)
                    {
                    case CatalogVisibility.Public:
                        product.Visibility = CatalogVisibility.Hidden;
                        break;

                    case CatalogVisibility.Hidden:
                        product.Visibility = CatalogVisibility.Private;
                        break;

                    default:
                        product.Visibility = CatalogVisibility.Public;
                        break;
                    }
                    product.Save();
                    break;
                }
                PG.DataBind();
            }
        }
        public string DoCustomRewrite(string serverPath, CustomUrl customUrl, string query)
        {
            StringBuilder dynamicUrl  = new StringBuilder();
            string        displayPage = string.Empty;

            switch (customUrl.CatalogNodeType)
            {
            case CatalogNodeType.Category:
                displayPage = CatalogDataSource.GetDisplayPage(customUrl.CatalogNodeId, CatalogNodeType.Category);
                dynamicUrl.Append(serverPath);
                dynamicUrl.Append(displayPage);
                dynamicUrl.Append("?CategoryId=" + customUrl.CatalogNodeId);
                break;

            case CatalogNodeType.Product:
                displayPage = CatalogDataSource.GetDisplayPage(AlwaysConvert.ToInt(customUrl.CatalogNodeId), CatalogNodeType.Product);
                dynamicUrl.Append(serverPath);
                dynamicUrl.Append(displayPage);
                dynamicUrl.Append("?ProductId=" + customUrl.CatalogNodeId);
                break;

            case CatalogNodeType.Webpage:
                displayPage = CatalogDataSource.GetDisplayPage(customUrl.CatalogNodeId, CatalogNodeType.Webpage);
                dynamicUrl.Append(serverPath);
                dynamicUrl.Append(displayPage);
                dynamicUrl.Append("?WebpageId=" + customUrl.CatalogNodeId);
                break;

            case CatalogNodeType.Link:
                displayPage = CatalogDataSource.GetDisplayPage(customUrl.CatalogNodeId, CatalogNodeType.Link);
                dynamicUrl.Append(serverPath);
                dynamicUrl.Append(displayPage);
                dynamicUrl.Append("?LinkId=" + customUrl.CatalogNodeId);
                break;
            }
            //PRESERVE QUERY STRING
            if (!string.IsNullOrEmpty(query))
            {
                dynamicUrl.Append("&" + query);
            }
            return(dynamicUrl.ToString());
        }
        /// <summary>
        /// Gets the children for a given category.
        /// </summary>
        /// <param name="categoryId">Category to get children for</param>
        /// <param name="level">Level of the specified category</param>
        /// <param name="exclude">ID of the category to exclude from the collection; 0 if none.</param>
        /// <param name="publicOnly">If true, only include public categories in result set.</param>
        /// <returns></returns>
        private static CategoryLevelNodeCollection GetCategoryLevels(int categoryId, int level, int exclude, bool publicOnly)
        {
            CategoryLevelNodeCollection results      = new CategoryLevelNodeCollection();
            CatalogNodeCollection       catalogNodes = CatalogDataSource.Search(categoryId, string.Empty, true, publicOnly, false, CatalogNodeTypeFlags.Category);

            foreach (CatalogNode node in catalogNodes)
            {
                if (node.CatalogNodeId != exclude)
                {
                    CategoryLevelNode levelNode = new CategoryLevelNode();
                    levelNode.CategoryId    = node.CatalogNodeId;
                    levelNode.CategoryLevel = level;
                    levelNode.Name          = node.Name;
                    levelNode.ParentId      = categoryId;
                    results.Add(levelNode);
                    results.AddRange(GetCategoryLevels(levelNode.CategoryId, level + 1, exclude, publicOnly));
                }
            }
            return(results);
        }
        /// <summary>
        /// Determines the category context for the current request.
        /// </summary>
        /// <returns>The category context for the current request.</returns>
        private static int GetCategoryId()
        {
            HttpRequest request    = HttpContext.Current.Request;
            int         categoryId = AlwaysConvert.ToInt(request.QueryString["CategoryId"]);

            if (categoryId != 0)
            {
                return(categoryId);
            }
            int productId = GetProductId();

            if (productId != 0)
            {
                categoryId = CatalogDataSource.GetCategoryId(productId, CatalogNodeType.Product);
                if (categoryId != 0)
                {
                    return(categoryId);
                }
            }
            int webpageId = GetWebpageId();

            if (webpageId != 0)
            {
                categoryId = CatalogDataSource.GetCategoryId(webpageId, CatalogNodeType.Webpage);
                if (categoryId != 0)
                {
                    return(categoryId);
                }
            }
            int linkId = GetLinkId();

            if (linkId != 0)
            {
                categoryId = CatalogDataSource.GetCategoryId(linkId, CatalogNodeType.Link);
                if (categoryId != 0)
                {
                    return(categoryId);
                }
            }
            return(0);
        }
        protected void CGrid_RowCommand(object sender, System.Web.UI.WebControls.GridViewCommandEventArgs e)
        {
            if (e.CommandName.StartsWith("Do_"))
            {
                string[]        args            = e.CommandArgument.ToString().Split("|".ToCharArray());
                CatalogNodeType catalogNodeType = (CatalogNodeType)AlwaysConvert.ToInt(args[0]);
                int             catalogNodeId   = AlwaysConvert.ToInt(args[1]);
                int             index;
                switch (e.CommandName)
                {
                case "Do_Copy":
                    CatalogDataSource.Copy(catalogNodeId, catalogNodeType, CurrentCategory.Id);
                    break;

                case "Do_Delete":
                    DoDelete(catalogNodeType, catalogNodeId);
                    break;

                case "Do_Up":
                    index = CurrentCategory.CatalogNodes.IndexOf(CurrentCategory.Id, catalogNodeId, (byte)catalogNodeType);
                    if (index > 0)
                    {
                        CatalogNode tempNode = CurrentCategory.CatalogNodes[index - 1];
                        CurrentCategory.CatalogNodes[index - 1] = CurrentCategory.CatalogNodes[index];
                        CurrentCategory.CatalogNodes[index]     = tempNode;
                        short newOrderBy = 0;
                        foreach (CatalogNode node in CurrentCategory.CatalogNodes)
                        {
                            node.OrderBy = newOrderBy;
                            node.Save();
                            newOrderBy++;
                        }

                        // recalculate orderby for impacted child products
                        RecalculateOrderBy(CurrentCategory.CatalogNodes[index - 1]);
                        RecalculateOrderBy(CurrentCategory.CatalogNodes[index]);
                    }
                    break;

                case "Do_Down":
                    index = CurrentCategory.CatalogNodes.IndexOf(CurrentCategory.Id, catalogNodeId, (byte)catalogNodeType);
                    if (index < CurrentCategory.CatalogNodes.Count - 1)
                    {
                        CatalogNode tempNode = CurrentCategory.CatalogNodes[index + 1];
                        CurrentCategory.CatalogNodes[index + 1] = CurrentCategory.CatalogNodes[index];
                        CurrentCategory.CatalogNodes[index]     = tempNode;
                        short newOrderBy = 0;
                        foreach (CatalogNode node in CurrentCategory.CatalogNodes)
                        {
                            node.OrderBy = newOrderBy;
                            node.Save();
                            newOrderBy++;
                        }

                        // recalculate orderby for impacted child products
                        RecalculateOrderBy(CurrentCategory.CatalogNodes[index + 1]);
                        RecalculateOrderBy(CurrentCategory.CatalogNodes[index]);
                    }
                    break;

                case "Do_Pub":
                    index = CurrentCategory.CatalogNodes.IndexOf(CurrentCategory.Id, catalogNodeId, (byte)catalogNodeType);
                    if (index > -1)
                    {
                        CatalogNode node = CurrentCategory.CatalogNodes[index];
                        //FOR CATEGORIES, WE MUST FIND OUT MORE INFORMATION
                        if (node.CatalogNodeType == CatalogNodeType.Category)
                        {
                            Response.Redirect("ChangeVisibility.aspx?CategoryId=" + CurrentCategory.Id.ToString() + String.Format("&Objects={0}:{1}", node.CatalogNodeId, (byte)node.CatalogNodeType));
                        }
                        //FOR OTHER OBJECTS, WE CAN ADJUST
                        switch (node.Visibility)
                        {
                        case CatalogVisibility.Public:
                            node.Visibility = CatalogVisibility.Hidden;
                            break;

                        case CatalogVisibility.Hidden:
                            node.Visibility = CatalogVisibility.Private;
                            break;

                        default:
                            node.Visibility = CatalogVisibility.Public;
                            break;
                        }
                        node.ChildObject.Visibility = node.Visibility;
                        node.Save(true);
                    }
                    break;
                }
            }
        }
Exemple #17
0
        protected void CGrid_RowCommand(object sender, System.Web.UI.WebControls.GridViewCommandEventArgs e)
        {
            if (e.CommandName.StartsWith("Do_"))
            {
                string[]        args            = e.CommandArgument.ToString().Split("|".ToCharArray());
                CatalogNodeType catalogNodeType = (CatalogNodeType)AlwaysConvert.ToInt(args[0]);
                int             catalogNodeId   = AlwaysConvert.ToInt(args[1]);
                switch (e.CommandName)
                {
                case "Do_Open":
                    //IF CATEGORY, REBIND CURRENT PAGE,
                    //OTHERWISE REDIRECT TO CORRECT EDIT PAGE
                    switch (catalogNodeType)
                    {
                    case CatalogNodeType.Category:
                        //REBIND CURRENT CATEGORY
                        CurrentCategoryId = catalogNodeId;
                        //RESET PAGE INDEX
                        CGrid.PageIndex = 0;
                        break;

                    case CatalogNodeType.Product:
                        Response.Redirect("~/Admin/Products/EditProduct.aspx?CategoryId=" + CurrentCategoryId.ToString() + "&ProductId=" + catalogNodeId.ToString());
                        break;

                    case CatalogNodeType.Webpage:
                        Response.Redirect("~/Admin/Catalog/EditWebpage.aspx?CategoryId=" + CurrentCategoryId.ToString() + "&WebpageId=" + catalogNodeId.ToString());
                        break;

                    case CatalogNodeType.Link:
                        Response.Redirect("~/Admin/Catalog/EditLink.aspx?CategoryId=" + CurrentCategoryId.ToString() + "&LinkId=" + catalogNodeId.ToString());
                        break;
                    }
                    break;

                case "Do_Copy":
                    // THIS WILL COPY THE PRODUCTS WITH THE ORIGNAL CATEGORY INFORMATION PRESERVED
                    CatalogDataSource.Copy(catalogNodeId, catalogNodeType, 0);
                    break;

                case "Do_Delete":
                    DoDelete(catalogNodeType, catalogNodeId);
                    break;

                case "Do_Pub":
                    ICatalogable pubNode = CatalogDataSource.Load(catalogNodeId, catalogNodeType);
                    if (pubNode != null)
                    {
                        //FOR CATEGORIES, WE MUST FIND OUT MORE INFORMATION
                        if (pubNode is Category)
                        {
                            Response.Redirect("ChangeVisibility.aspx?CategoryId=" + ((Category)pubNode).ParentId.ToString() + String.Format("&Objects={0}:{1}", ((Category)pubNode).Id, (byte)(CatalogNodeType.Category)));
                        }
                        //FOR OTHER OBJECTS, WE CAN ADJUST
                        switch (pubNode.Visibility)
                        {
                        case CatalogVisibility.Public:
                            pubNode.Visibility = CatalogVisibility.Hidden;
                            break;

                        case CatalogVisibility.Hidden:
                            pubNode.Visibility = CatalogVisibility.Private;
                            break;

                        default:
                            pubNode.Visibility = CatalogVisibility.Public;
                            break;
                        }
                        if (pubNode is Product)
                        {
                            ((Product)pubNode).Save();
                        }
                        else if (pubNode is Webpage)
                        {
                            ((Webpage)pubNode).Save();
                        }
                        else if (pubNode is Link)
                        {
                            ((Link)pubNode).Save();
                        }
                    }
                    break;
                }
            }
            CGrid.DataBind();
        }
        public override SiteMapNode FindSiteMapNode(string rawUrl)
        {
            //FIRST CHECK WHETHER THIS PAGE IS SPECIFICALLY KEYED IN THE CONFIG FILE
            SiteMapNode baseNode = base.FindSiteMapNode(rawUrl);

            if (baseNode != null)
            {
                if (_EnableHiding)
                {
                    return(FindVisibleNode(baseNode));
                }
                return(baseNode);
            }

            //PAGE NOT FOUND, CHECK WHETHER THIS URL MATCHES KNOWN CMS PAGES
            int categoryId = -1;

            WebTrace.Write(this.GetType().ToString(), "FindSiteMapNode: " + rawUrl + ", Check For CategoryId");
            Match urlMatch = Regex.Match(rawUrl, "(?<baseUrl>.*)\\?(?:.*&)?CategoryId=(?<categoryId>[^&]*)", (RegexOptions.ExplicitCapture | RegexOptions.IgnoreCase));

            if (urlMatch.Success)
            {
                //CATEGORYID PROVIDED IN URL
                categoryId = AlwaysConvert.ToInt(urlMatch.Groups[2].Value);
            }
            else
            {
                WebTrace.Write(this.GetType().ToString(), "FindSiteMapNode: " + rawUrl + ", Check For Catalog Object Id");
                urlMatch = Regex.Match(rawUrl, "(?<baseUrl>.*)\\?(?:.*&)?(?<nodeType>ProductId|WebpageId|LinkId)=(?<catalogId>[^&]*)", (RegexOptions.ExplicitCapture | RegexOptions.IgnoreCase));
                if (urlMatch.Success)
                {
                    string objectType = urlMatch.Groups[2].Value;
                    switch (objectType)
                    {
                    case "ProductId":
                        categoryId = CatalogDataSource.GetCategoryId(AlwaysConvert.ToInt(urlMatch.Groups[3].Value), CatalogNodeType.Product);
                        break;

                    case "WebpageId":
                        categoryId = CatalogDataSource.GetCategoryId(AlwaysConvert.ToInt(urlMatch.Groups[3].Value), CatalogNodeType.Webpage);
                        break;

                    default:
                        categoryId = CatalogDataSource.GetCategoryId(AlwaysConvert.ToInt(urlMatch.Groups[3].Value), CatalogNodeType.Link);
                        break;
                    }
                    WebTrace.Write("Found catalogobjectid, type: " + objectType + ", id: " + categoryId.ToString());
                }
            }

            if (categoryId > -1)
            {
                //FIND BASE NODE
                WebTrace.Write(this.GetType().ToString(), "CategoryId Detected, Find Base Node");
                baseNode = base.FindSiteMapNode(urlMatch.Groups[1].Value);
                if (baseNode != null)
                {
                    WebTrace.Write(this.GetType().ToString(), "Base Node Found, Inject Catalog Path");
                    List <SiteMapNode> pathNodes = this.GetSiteMapPathNodes(baseNode);
                    WebTrace.Write("default pathnodes count: " + pathNodes.Count.ToString());
                    int catalogNodeIndex = this.GetCatalogNodeIndex(pathNodes);
                    //IF CATALOG NODE IS NOT FOUND, RETURN THE BASE NODE FOUND BY PROVIDER
                    if (catalogNodeIndex < 0)
                    {
                        return(baseNode);
                    }
                    WebTrace.Write(this.GetType().ToString(), "Catalog Node Obtained, Building Dynamic Path");
                    //APPEND CMS PATH TO THE
                    List <SiteMapNode> dynamicNodes      = new List <SiteMapNode>();
                    List <CmsPathNode> activeCatalogPath = CmsPath.GetCmsPath(0, categoryId, CatalogNodeType.Category);
                    //IF THERE ARE IS NO PATH INFORMATION BEYOND THE ROOT NODE, RETURN THE BASE NODE FOUND BY PROVIDER
                    if ((activeCatalogPath == null) || (activeCatalogPath.Count < 1))
                    {
                        return(baseNode);
                    }
                    WebTrace.Write("ActivePathCount: " + activeCatalogPath.Count.ToString());
                    for (int i = 0; i < activeCatalogPath.Count; i++)
                    {
                        SiteMapNode newDynamicNode = new SiteMapNode(baseNode.Provider, activeCatalogPath[i].NodeId.ToString(), activeCatalogPath[i].Url, activeCatalogPath[i].Title, activeCatalogPath[i].Description);
                        if (dynamicNodes.Count > 0)
                        {
                            newDynamicNode.ParentNode = dynamicNodes[dynamicNodes.Count - 1];
                        }
                        dynamicNodes.Add(newDynamicNode);
                    }
                    dynamicNodes[0].ParentNode = pathNodes[catalogNodeIndex];
                    if (catalogNodeIndex == pathNodes.Count - 1)
                    {
                        //THERE ARE NO PATH NODES FOLLOWING CATALOG, RETURN LAST DYNAMIC NODE
                        WebTrace.Write("return last dynamic node");
                        return(dynamicNodes[dynamicNodes.Count - 1]);
                    }
                    else
                    {
                        //THERE WERE PATH NODES FOLLOWING CATALOG, UPDATE PARENT TO LAST DYNAMIC NODE
                        WebTrace.Write("append nodes following catalog");
                        //GET NODE THAT SHOULD BE LINKED FROM LAST DYNAMIC PATH NODE
                        //CLONE THE NODE TO PREVENT CACHING, THEN SET PARENT TO DYNAMIC NODE
                        SiteMapNode dynamicNextPathNode = pathNodes[catalogNodeIndex + 1].Clone(false);
                        pathNodes[catalogNodeIndex + 1] = dynamicNextPathNode;
                        dynamicNextPathNode.ReadOnly    = false;
                        dynamicNextPathNode.ParentNode  = dynamicNodes[dynamicNodes.Count - 1];
                        //LOOP THROUGH REMAINING PATH NODES, CLONE THEM AND SET PARENT TO PREVIOUS DYNAMIC NODE
                        for (int i = catalogNodeIndex + 2; i < pathNodes.Count; i++)
                        {
                            dynamicNextPathNode            = pathNodes[i].Clone(false);
                            pathNodes[i]                   = dynamicNextPathNode;
                            dynamicNextPathNode.ReadOnly   = false;
                            dynamicNextPathNode.ParentNode = pathNodes[i - 1];
                        }
                        //NOW RETURN LAST PATH NODE
                        return(pathNodes[pathNodes.Count - 1]);
                    }
                }
            }

            //THIS PATH TO THIS PAGE CANNOT BE DETERMINED
            return(null);
        }
Exemple #19
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (IsValidCategory())
            {
                string eventTarget = Request["__EVENTTARGET"];
                if (string.IsNullOrEmpty(eventTarget) || !eventTarget.EndsWith("PageSizeOptions"))
                {
                    string pageSizeOption = Request.QueryString["ps"];
                    if (!string.IsNullOrEmpty(pageSizeOption))
                    {
                        PageSizeOptions.ClearSelection();
                        ListItem item = PageSizeOptions.Items.FindByValue(pageSizeOption);
                        if (item != null)
                        {
                            item.Selected = true;
                        }
                    }
                }

                if (string.IsNullOrEmpty(eventTarget) || !eventTarget.EndsWith("SortResults"))
                {
                    string sortOption = Request.QueryString["s"];
                    if (!string.IsNullOrEmpty(sortOption))
                    {
                        SortResults.ClearSelection();
                        ListItem item = SortResults.Items.OfType <ListItem>().SingleOrDefault(x => string.Compare(x.Value, sortOption, StringComparison.InvariantCultureIgnoreCase) == 0);
                        if (item != null)
                        {
                            item.Selected = true;
                        }
                    }
                }

                if (!string.IsNullOrEmpty(eventTarget))
                {
                    if (eventTarget.EndsWith("PageSizeOptions") || eventTarget.EndsWith("SortResults"))
                    {
                        string url = Request.RawUrl;
                        if (url.Contains("?"))
                        {
                            url = Request.RawUrl.Substring(0, Request.RawUrl.IndexOf("?"));
                        }
                        url += "?s=" + SortResults.SelectedValue;
                        url += "&ps=" + PageSizeOptions.SelectedValue;
                        Response.Redirect(url);
                    }
                }

                if (_Category != null)
                {
                    CategoryBreadCrumbs1.CategoryId = this.CategoryId;
                    Caption.Text = _Category.Name;

                    if (!string.IsNullOrEmpty(_Category.Summary) && ShowSummary)
                    {
                        CategorySummary.Text = _Category.Summary;
                    }

                    if (!string.IsNullOrEmpty(_Category.Description) && ShowDescription)
                    {
                        CategoryDescriptionPanel.Visible = true;
                        CategoryDescription.Text         = _Category.Description;
                    }
                    else
                    {
                        CategoryDescriptionPanel.Visible = false;
                    }
                }
                else
                {
                    // IT IS ROOT CATEGORY
                    CategoryBreadCrumbs1.CategoryId = this.CategoryId;
                    Caption.Text = DefaultCaption;
                    if (ShowSummary)
                    {
                        CategorySummary.Text = DefaultCategorySummary;
                    }
                }

                if (_Category != null)
                {
                    int count = CatalogDataSource.CountForCategory(_Category.Id, true, true);
                    if (count > 0)
                    {
                        _currentPageIndex = AlwaysConvert.ToInt(Request.QueryString["p"]);
                        _pageSize         = AlwaysConvert.ToInt(PageSizeOptions.SelectedValue);
                        _lastPageIndex    = ((int)Math.Ceiling(((double)count / (double)_pageSize))) - 1;

                        CatalogNodeList.DataSource = CatalogDataSource.LoadForCategory(_Category.Id, true, true, _pageSize, (_currentPageIndex * _pageSize), SortResults.SelectedValue);
                        CatalogNodeList.DataBind();
                        int startRowIndex = (_pageSize * _currentPageIndex);
                        int endRowIndex   = startRowIndex + _pageSize;
                        if (endRowIndex > count)
                        {
                            endRowIndex = count;
                        }
                        if (count == 0)
                        {
                            startRowIndex = -1;
                        }
                        ResultIndexMessage.Text = string.Format(ResultIndexMessage.Text, (startRowIndex + 1), endRowIndex, count);
                        ResultIndexMessage.Text = string.Format(ResultIndexMessage.Text, (startRowIndex + 1), endRowIndex, count);
                        BindPagingControls();
                    }
                    else
                    {
                        phEmptyCategory.Visible = true;
                    }

                    AbleCommerce.Code.PageVisitHelper.RegisterPageVisit(_Category.Id, CatalogNodeType.Category, _Category.Name);
                }
            }
        }
Exemple #20
0
        /// <summary>
        /// Generates the feed data for given products
        /// </summary>
        /// <param name="products">The products to generate feed for</param>
        /// <returns>Feed data generated</returns>
        protected override string GetFeedData(ProductCollection products)
        {
            //write header row
            StringWriter  feedWriter = new StringWriter();
            StringBuilder feedLine;

            string storeUrl = Token.Instance.Store.StoreUrl;

            storeUrl = storeUrl + (storeUrl.EndsWith("/") ? "" : "/");

            string url, name, desc, price, imgurl, category, mpn, upc, manufacturer, stock, stockdesc, shiprate;

            foreach (Product product in products)
            {
                url = product.NavigateUrl;
                if (url.StartsWith("~/"))
                {
                    url = url.Substring(2);
                }
                url = storeUrl + url;

                name = CleanupText(product.Name);
                desc = CleanupText(product.Summary);
                if (desc.Length > 1024)
                {
                    desc = desc.Substring(0, 1024);
                }

                price = string.Format("{0:F2}", product.Price);

                imgurl = product.ImageUrl;
                if (!string.IsNullOrEmpty(imgurl) && !IsAbsoluteURL(imgurl))
                {
                    if (imgurl.StartsWith("~/"))
                    {
                        imgurl = imgurl.Substring(2);
                    }
                    imgurl = storeUrl + imgurl;
                }

                if (product.Categories.Count > 0)
                {
                    List <CatalogPathNode> path = CatalogDataSource.GetPath(product.Categories[0], false);
                    category = "";
                    foreach (CatalogPathNode item in path)
                    {
                        if (item == null)
                        {
                            continue;
                        }
                        if (category.Length > 0)
                        {
                            category = category + "->" + CleanupText(item.Name);
                        }
                        else
                        {
                            category = CleanupText(item.Name);
                        }
                    }
                }
                else
                {
                    category = "None";
                }

                manufacturer = "";
                if (product.Manufacturer != null)
                {
                    manufacturer = CleanupText(product.Manufacturer.Name);
                }

                mpn = product.ModelNumber;

                if (product.InventoryMode == InventoryMode.Product)
                {
                    stock = product.InStock > 0 ? "Y" : "N";
                }

                // IF INVENTORY IS DISABLED OR INVENTORY MODE IS TRACK VARIANTS, ASSUME INVENTORY IS AVAILABLE
                else
                {
                    stock = "Y";
                }

                //TODO
                stockdesc = "New";

                upc      = this.IsUpcCode(product.Sku) ? product.Sku : string.Empty;
                shiprate = "";

                feedLine = new StringBuilder();
                feedLine.Append(mpn + "," + upc + ",\"" + manufacturer
                                + "\",\"" + name + "\",\"" + desc + "\"," + price
                                + "," + stock + "," + stockdesc + "," + url
                                + "," + imgurl + ",\"" + category + "\"," + shiprate);
                feedWriter.WriteLine(feedLine.ToString());
            }

            string returnData = feedWriter.ToString();

            feedWriter.Close();

            return(returnData);
        }
        public string DoDefaultRewrite(string sourceUrl)
        {
            // CHECK FOR URL FITTING AC PATTERN
            Match urlMatch;

            urlMatch = Regex.Match(sourceUrl, REWRITE_PATTERN, (RegexOptions.IgnoreCase & RegexOptions.Compiled));
            if (urlMatch.Success)
            {
                // URL FOUND, PARSE AND REWRITE
                string serverPath  = (urlMatch.Groups[1].ToString() + "/");
                string objectType  = urlMatch.Groups[2].ToString();
                string objectId    = urlMatch.Groups[3].ToString();
                string categoryId  = urlMatch.Groups[4].ToString();
                string urlParams   = urlMatch.Groups[5].ToString();
                string displayPage = string.Empty;
                // DISPLAY PAGE NOT PRESENT, LOOK UP FROM TABLE
                // TODO:LOOKUP DISPLAY PAGE FROM RULES
                // Dim displayPage As String = RewriteUrlLookupEngine.GetDisplayPage(app, objectType, objectId)
                StringBuilder dynamicUrl = new StringBuilder();
                switch (objectType)
                {
                case "C":
                case "c":
                    displayPage = CatalogDataSource.GetDisplayPage(AlwaysConvert.ToInt(objectId), CatalogNodeType.Category);
                    dynamicUrl.Append((serverPath
                                       + (displayPage + ("?CategoryId=" + objectId))));
                    break;

                case "P":
                case "p":
                    displayPage = CatalogDataSource.GetDisplayPage(AlwaysConvert.ToInt(objectId), CatalogNodeType.Product);
                    dynamicUrl.Append((serverPath
                                       + (displayPage + ("?ProductId=" + objectId))));
                    if ((categoryId.Length > 0))
                    {
                        dynamicUrl.Append(("&CategoryId=" + categoryId));
                    }
                    break;

                case "W":
                case "w":
                    displayPage = CatalogDataSource.GetDisplayPage(AlwaysConvert.ToInt(objectId), CatalogNodeType.Webpage);
                    dynamicUrl.Append((serverPath
                                       + (displayPage + ("?WebpageId=" + objectId))));
                    if ((categoryId.Length > 0))
                    {
                        dynamicUrl.Append(("&CategoryId=" + categoryId));
                    }
                    break;

                case "L":
                case "l":
                    displayPage = CatalogDataSource.GetDisplayPage(AlwaysConvert.ToInt(objectId), CatalogNodeType.Link);
                    dynamicUrl.Append((serverPath
                                       + (displayPage + ("?LinkId=" + objectId))));
                    if ((categoryId.Length > 0))
                    {
                        dynamicUrl.Append(("&CategoryId=" + categoryId));
                    }
                    break;
                }
                if ((urlParams.Length > 0))
                {
                    dynamicUrl.Append(("&" + urlParams));
                }
                return(dynamicUrl.ToString());
            }
            return(sourceUrl);
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            string eventTarget = Request["__EVENTTARGET"];

            if (string.IsNullOrEmpty(eventTarget) || !eventTarget.EndsWith("PageSizeOptions"))
            {
                string pageSizeOption = Request.QueryString["ps"];
                if (!string.IsNullOrEmpty(pageSizeOption))
                {
                    PageSizeOptions.ClearSelection();
                    ListItem item = PageSizeOptions.Items.FindByValue(pageSizeOption);
                    if (item != null)
                    {
                        item.Selected = true;
                    }
                }
            }
            else
            if (eventTarget.EndsWith("PageSizeOptions"))
            {
                string url = Request.RawUrl;
                if (url.Contains("?"))
                {
                    url = Request.RawUrl.Substring(0, Request.RawUrl.IndexOf("?"));
                }
                url += "?s=" + SortResults.SelectedValue;
                url += "&ps=" + PageSizeOptions.SelectedValue;
                Response.Redirect(url);
            }

            _pageSize = AlwaysConvert.ToInt(PageSizeOptions.SelectedValue);
            CatalogNodeList.RepeatColumns = Cols;
            if (IsValidCategory())
            {
                // INITIALIZE THE CONTENT NODES
                _contentNodes = new List <CatalogNode>();
                IList <CatalogNode> visibleNodes;
                if (_category != null)
                {
                    visibleNodes = CatalogDataSource.LoadForCategory(_category.Id, true, true, 0, 0, string.Empty);
                }
                else
                {
                    visibleNodes = CatalogDataSource.LoadForCategory(0, true, true, 0, 0, string.Empty);
                }

                if (visibleNodes.Count > 0)
                {
                    // FETCH THE ASSOCIATED CATALOG ITEMS INTO ORM OBJECT GRAPH AND DISCARD RESULTS
                    // THIS IS ESSENTIALLY FOR PERFORMANCE BOOST BY MINIMIZING NUMBER OF QUERIES
                    var productIds = visibleNodes.Where(n => n.CatalogNodeType == CatalogNodeType.Product)
                                     .Select(n => n.CatalogNodeId)
                                     .ToList <int>();

                    if (productIds.Count > 0 && productIds.Count < 415)
                    {
                        var futureQuery = NHibernateHelper.QueryOver <Product>()
                                          .AndRestrictionOn(p => p.Id).IsIn(productIds)
                                          .Fetch(p => p.Specials).Eager
                                          .Future <Product>();

                        NHibernateHelper.QueryOver <Product>()
                        .AndRestrictionOn(p => p.Id).IsIn(productIds)
                        .Fetch(p => p.ProductOptions).Eager
                        .Future <Product>();

                        NHibernateHelper.QueryOver <Product>()
                        .AndRestrictionOn(p => p.Id).IsIn(productIds)
                        .Fetch(p => p.ProductKitComponents).Eager
                        .Future <Product>();

                        NHibernateHelper.QueryOver <Product>()
                        .AndRestrictionOn(p => p.Id).IsIn(productIds)
                        .Fetch(p => p.ProductTemplates).Eager
                        .Future <Product>();

                        NHibernateHelper.QueryOver <Product>()
                        .AndRestrictionOn(p => p.Id).IsIn(productIds)
                        .Fetch(p => p.Reviews).Eager
                        .Future <Product>();

                        futureQuery.ToList();
                    }

                    var categoryIds = visibleNodes.Where(n => n.CatalogNodeType == CatalogNodeType.Category)
                                      .Select(n => n.CatalogNodeId)
                                      .ToList <int>();

                    if (categoryIds.Count > 0 && categoryIds.Count < 2000)
                    {
                        NHibernateHelper.QueryOver <Category>()
                        .AndRestrictionOn(c => c.Id).IsIn(categoryIds)
                        .List <Category>();
                    }

                    var webpageIds = visibleNodes.Where(n => n.CatalogNodeType == CatalogNodeType.Webpage)
                                     .Select(n => n.CatalogNodeId)
                                     .ToList <int>();

                    if (webpageIds.Count > 0 && webpageIds.Count < 2000)
                    {
                        NHibernateHelper.QueryOver <Webpage>()
                        .AndRestrictionOn(w => w.Id).IsIn(webpageIds)
                        .List <Webpage>();
                    }

                    var linkIds = visibleNodes.Where(n => n.CatalogNodeType == CatalogNodeType.Link)
                                  .Select(n => n.CatalogNodeId)
                                  .ToList <int>();

                    if (linkIds.Count > 0 && linkIds.Count < 2000)
                    {
                        NHibernateHelper.QueryOver <Link>()
                        .AndRestrictionOn(l => l.Id).IsIn(linkIds)
                        .List <Link>();
                    }
                }

                foreach (CatalogNode node in visibleNodes)
                {
                    if (node.CatalogNodeType == CatalogNodeType.Category)
                    {
                        // only add categories that have publicly visible content
                        int visibleCount = CatalogDataSource.CountForCategory(node.CatalogNodeId, true, true);
                        if (visibleCount > 0)
                        {
                            _contentNodes.Add(node);
                        }
                    }
                    else
                    {
                        _contentNodes.Add(node);
                    }
                }

                if (_pageSize == 0)
                {
                    _pageSize = _contentNodes.Count;
                }
                int minimumPageSize = AlwaysConvert.ToInt(PageSizeOptions.Items[0].Value);
                PageSizePanel.Visible = _contentNodes.Count > minimumPageSize;

                // BIND PAGE
                BindPage();
            }

            int manufecturerCount = ManufacturerDataSource.CountAll();

            foreach (ListItem li in SortResults.Items)
            {
                if (li.Value.StartsWith("Manufacturer"))
                {
                    li.Enabled = manufecturerCount > 0;
                }
            }
        }
        protected void BindExpandResultPanel()
        {
            Trace.Write(this.GetType().ToString(), "Begin BindExpandResultPanel");

            //START WITH THE PANEL VISIBLE
            ExpandResultPanel.Visible = true;

            //BIND THE EXPAND CATEGORY LINKS
            IList <CatalogPathNode> currentPath = CatalogDataSource.GetPath(this._categoryId, false);

            if (_isCategoryPage && currentPath.Count > 0 && currentPath[0].CatalogNodeType == CatalogNodeType.Category)
            {
                currentPath.RemoveAt(0);
            }

            if (currentPath.Count > 0)
            {
                ExpandCategoryLinks.Visible    = true;
                ExpandCategoryLinks.DataSource = currentPath;
                ExpandCategoryLinks.DataBind();
            }
            else
            {
                ExpandCategoryLinks.Visible = false;
            }

            //BIND THE EXPAND MANUFACTURER LINK
            Manufacturer m = ManufacturerDataSource.Load(this._manufacturerId);

            if (m != null)
            {
                ExpandManufacturerLink.Text        = string.Format("{0} (X)", m.Name);
                ExpandManufacturerLink.NavigateUrl = RemoveQueryStringParameter("m");
                ExpandManufacturerListItem.Visible = true;
            }
            else
            {
                ExpandManufacturerListItem.Visible = false;
                ExpandManufacturerLink.NavigateUrl = "#";
            }

            //BIND THE EXPAND KEYWORD LINK
            if (!string.IsNullOrEmpty(this._keyword))
            {
                ExpandKeywordLink.Text        = string.Format("Remove Keyword: {0}", Server.HtmlEncode(this._keyword));
                ExpandKeywordLink.NavigateUrl = RemoveQueryStringParameter("k");
                ExpandKeywordListItem.Visible = true;
            }
            else
            {
                ExpandKeywordListItem.Visible = false;
            }

            IList <ShopByChoice> choices = PageHelper.GetShopByChoices();

            if (choices != null && choices.Count > 0)
            {
                ExpandShopByLinks.DataSource = choices;
                ExpandShopByLinks.DataBind();
                ExpandShopByLinks.Visible = true;
            }
            else
            {
                ExpandShopByLinks.Visible = false;
            }


            //SET VISIBILITY OF EXPAND PANEL BASED ON CHILD CONTROLS VISIBILITY
            ExpandResultPanel.Visible = (ExpandCategoryLinks.Visible || ExpandManufacturerListItem.Visible || ExpandKeywordListItem.Visible) || ExpandShopByLinks.Visible;
            Trace.Write(this.GetType().ToString(), "End BindExpandResultPanel");
        }