protected void CreateChildMenu(List<Category> breadCrumb, int rootCategoryId, Category currentCategory, int level)
        {
            int padding = level++ * 15;
            foreach (var category in this.CategoryService.GetAllCategoriesByParentCategoryId(rootCategoryId))
            {
                var link = new NopCommerceLi();
                phCategories.Controls.Add(link);

                string categoryURL = SEOHelper.GetCategoryUrl(category);
                if (currentCategory != null && currentCategory.CategoryId == category.CategoryId)
                    link.CssClass = "active";
                else
                    link.CssClass = "inactive";
                link.HyperLink.NavigateUrl = categoryURL;
                string catName = string.Empty;
                if (this.SettingManager.GetSettingValueBoolean("Display.Products.ShowCategoryProductNumber"))
                {
                    //display category name with assigned products number
                    int numberOfProducts = GetNumberOfProducts(category, this.SettingManager.GetSettingValueBoolean("Display.Products.ShowCategoryProductNumber.IncludeSubCategories"));
                    catName = string.Format("{0} ({1})", category.LocalizedName, numberOfProducts);
                }
                else
                {
                    //display only category name
                    catName = category.LocalizedName;
                }
                link.HyperLink.Text = Server.HtmlEncode(catName);
                if (padding > 0)
                    link.LiLeftMargin = padding.ToString();

                for (int i = 0; i <= breadCrumb.Count - 1; i++)
                    if (breadCrumb[i].CategoryId == category.CategoryId)
                        CreateChildMenu(breadCrumb, category.CategoryId, currentCategory, level);
            }
        }
Beispiel #2
0
        private void CreateChildControlsTree()
        {
            category = CategoryManager.GetCategoryById(this.CategoryId);
            if (category != null)
            {
                Control child = null;

                CategoryTemplate categoryTemplate = category.CategoryTemplate;
                if (categoryTemplate == null)
                    throw new NopException(string.Format("Category template path can not be empty. CategoryID={0}", category.CategoryId));

                child = base.LoadControl(categoryTemplate.TemplatePath);
                this.CategoryPlaceHolder.Controls.Add(child);
            }
        }
Beispiel #3
0
        protected string GetCategoryFullName(Category category)
        {
            string result = string.Empty;

            while (category != null && !category.Deleted)
            {
                if (String.IsNullOrEmpty(result))
                {
                    result = category.Name;
                }
                else
                {
                    result = category.Name + " >> " + result;
                }
                category = category.ParentCategory;
            }
            return result;
        }
        protected void CreateChildMenu(List<Category> breadCrumb, int rootCategoryId, Category currentCategory, int level)
        {
            int padding = level++ * 15;
            foreach (var category in CategoryManager.GetAllCategoriesByParentCategoryId(rootCategoryId))
            {
                var link = new NopCommerceLi();
                phCategories.Controls.Add(link);

                string categoryURL = SEOHelper.GetCategoryUrl(category);
                if (currentCategory != null && currentCategory.CategoryId == category.CategoryId)
                    link.CssClass = "active";
                else
                    link.CssClass = "inactive";
                link.HyperLink.NavigateUrl = categoryURL;
                link.HyperLink.Text = Server.HtmlEncode(category.LocalizedName);
                if (padding > 0)
                    link.LiLeftMargin = padding.ToString();

                for (int i = 0; i <= breadCrumb.Count - 1; i++)
                    if (breadCrumb[i].CategoryId == category.CategoryId)
                        CreateChildMenu(breadCrumb, category.CategoryId, currentCategory, level);
            }
        }
Beispiel #5
0
        /// <summary>
        /// Gets category URL
        /// </summary>
        /// <param name="category">Category</param>
        /// <returns>Category URL</returns>
        public static string GetCategoryUrl(Category category)
        {
            if (category == null)
                throw new ArgumentNullException("category");
            string seName = GetCategorySEName(category);

            string url2 = SEOHelper.EnableUrlRewriting ? IoC.Resolve<ISettingManager>().GetSettingValue("SEO.Category.UrlRewriteFormat") : "{0}Category.aspx?CategoryID={1}";
            string url = string.Format(url2, CommonHelper.GetStoreLocation(), category.CategoryId, seName);
            return url.ToLowerInvariant();
        }
Beispiel #6
0
 /// <summary>
 /// Gets category SE (search engine) name
 /// </summary>
 /// <param name="category">Category</param>
 /// <returns>Category SE (search engine) name</returns>
 public static string GetCategorySEName(Category category)
 {
     if (category == null)
         throw new ArgumentNullException("category");
     string seName = GetSEName(category.SEName);
     if (String.IsNullOrEmpty(seName))
     {
         seName = GetSEName(category.Name);
     }
     return seName;
 }
        protected void SaveLocalizableContent(Category category)
        {
            if (category == null)
                return;

            if (!this.HasLocalizableContent)
                return;

            foreach (RepeaterItem item in rptrLanguageDivs.Items)
            {
                if (item.ItemType == ListItemType.Item || item.ItemType == ListItemType.AlternatingItem)
                {
                    var txtLocalizedMetaKeywords = (TextBox)item.FindControl("txtLocalizedMetaKeywords");
                    var txtLocalizedMetaDescription = (TextBox)item.FindControl("txtLocalizedMetaDescription");
                    var txtLocalizedMetaTitle = (TextBox)item.FindControl("txtLocalizedMetaTitle");
                    var txtLocalizedSEName = (TextBox)item.FindControl("txtLocalizedSEName");
                    var lblLanguageId = (Label)item.FindControl("lblLanguageId");

                    int languageId = int.Parse(lblLanguageId.Text);
                    string metaKeywords = txtLocalizedMetaKeywords.Text;
                    string metaDescription = txtLocalizedMetaDescription.Text;
                    string metaTitle = txtLocalizedMetaTitle.Text;
                    string seName = txtLocalizedSEName.Text;

                    bool allFieldsAreEmpty = (string.IsNullOrEmpty(metaKeywords) &&
                        string.IsNullOrEmpty(metaDescription) &&
                        string.IsNullOrEmpty(metaTitle) &&
                        string.IsNullOrEmpty(seName));

                    var content = this.CategoryService.GetCategoryLocalizedByCategoryIdAndLanguageId(category.CategoryId, languageId);
                    if (content == null)
                    {
                        if (!allFieldsAreEmpty && languageId > 0)
                        {
                            //only insert if one of the fields are filled out (avoid too many empty records in db...)
                            content = new CategoryLocalized()
                            {
                                CategoryId = category.CategoryId,
                                LanguageId = languageId,
                                MetaKeywords = metaKeywords,
                                MetaDescription = metaDescription,
                                MetaTitle = metaTitle,
                                SEName = seName
                            };

                            this.CategoryService.InsertCategoryLocalized(content);
                        }
                    }
                    else
                    {
                        if (languageId > 0)
                        {
                            content.LanguageId = languageId;
                            content.MetaKeywords = metaKeywords;
                            content.MetaDescription = metaDescription;
                            content.MetaTitle = metaTitle;
                            content.SEName = seName;

                            this.CategoryService.UpdateCategoryLocalized(content);
                        }
                    }
                }
            }
        }
Beispiel #8
0
        protected void SaveLocalizableContent(Category category)
        {
            if (category == null)
                return;

            if (!this.HasLocalizableContent)
                return;

            foreach (RepeaterItem item in rptrLanguageDivs.Items)
            {
                if (item.ItemType == ListItemType.Item || item.ItemType == ListItemType.AlternatingItem)
                {
                    var txtLocalizedCategoryName = (TextBox)item.FindControl("txtLocalizedCategoryName");
                    var txtLocalizedDescription = (AjaxControlToolkit.HTMLEditor.Editor)item.FindControl("txtLocalizedDescription");
                    var lblLanguageId = (Label)item.FindControl("lblLanguageId");

                    int languageId = int.Parse(lblLanguageId.Text);
                    string name = txtLocalizedCategoryName.Text;
                    string description = txtLocalizedDescription.Content;

                    bool allFieldsAreEmpty = (string.IsNullOrEmpty(name) && string.IsNullOrEmpty(description));

                    var content = CategoryManager.GetCategoryLocalizedByCategoryIdAndLanguageId(category.CategoryId, languageId);
                    if (content == null)
                    {
                        if (!allFieldsAreEmpty && languageId > 0)
                        {
                            //only insert if one of the fields are filled out (avoid too many empty records in db...)
                            content = CategoryManager.InsertCategoryLocalized(category.CategoryId,
                                   languageId, name, description, string.Empty, string.Empty,
                                   string.Empty, string.Empty);
                        }
                    }
                    else
                    {
                        if (languageId > 0)
                        {
                            content = CategoryManager.UpdateCategoryLocalized(content.CategoryLocalizedId, content.CategoryId,
                                languageId, name, description,
                                content.MetaKeywords, content.MetaDescription,
                                content.MetaTitle, content.SEName);
                        }
                    }
                }
            }
        }
        public Category SaveInfo()
        {
            var category = this.CategoryService.GetCategoryById(this.CategoryId);

            if (category != null)
            {
                Picture categoryPicture = category.Picture;
                HttpPostedFile categoryPictureFile = fuCategoryPicture.PostedFile;
                if ((categoryPictureFile != null) && (!String.IsNullOrEmpty(categoryPictureFile.FileName)))
                {
                    byte[] categoryPictureBinary = categoryPictureFile.GetPictureBits();
                    if (categoryPicture != null)
                        categoryPicture = this.PictureService.UpdatePicture(categoryPicture.PictureId, categoryPictureBinary, categoryPictureFile.ContentType, true);
                    else
                        categoryPicture = this.PictureService.InsertPicture(categoryPictureBinary, categoryPictureFile.ContentType, true);
                }
                int categoryPictureId = 0;
                if (categoryPicture != null)
                    categoryPictureId = categoryPicture.PictureId;

                category.Name = txtName.Text.Trim();
                category.Description = txtDescription.Value;
                category.TemplateId = int.Parse(this.ddlTemplate.SelectedItem.Value);
                category.ParentCategoryId = ParentCategory.SelectedCategoryId;
                category.PictureId = categoryPictureId;
                category.PriceRanges = txtPriceRanges.Text;
                category. ShowOnHomePage= cbShowOnHomePage.Checked;
                category.Published = cbPublished.Checked;
                category.DisplayOrder = txtDisplayOrder.Value;
                category.UpdatedOn = DateTime.UtcNow;

                this.CategoryService.UpdateCategory(category);
            }
            else
            {
                Picture categoryPicture = null;
                HttpPostedFile categoryPictureFile = fuCategoryPicture.PostedFile;
                if ((categoryPictureFile != null) && (!String.IsNullOrEmpty(categoryPictureFile.FileName)))
                {
                    byte[] categoryPictureBinary = categoryPictureFile.GetPictureBits();
                    categoryPicture = this.PictureService.InsertPicture(categoryPictureBinary, categoryPictureFile.ContentType, true);
                }
                int categoryPictureId = 0;
                if (categoryPicture != null)
                    categoryPictureId = categoryPicture.PictureId;

                DateTime nowDT = DateTime.UtcNow;

                category = new Category()
                {
                    Name = txtName.Text.Trim(),
                    Description = txtDescription.Value,
                    TemplateId = int.Parse(this.ddlTemplate.SelectedItem.Value),
                    ParentCategoryId = ParentCategory.SelectedCategoryId,
                    PictureId = categoryPictureId,
                    PageSize = 10,
                    PriceRanges = txtPriceRanges.Text,
                    ShowOnHomePage = cbShowOnHomePage.Checked,
                    Published = cbPublished.Checked,
                    DisplayOrder = txtDisplayOrder.Value,
                    CreatedOn = nowDT,
                    UpdatedOn = nowDT
                };

                this.CategoryService.InsertCategory(category);
            }

            SaveLocalizableContent(category);

            return category;
        }
        protected void SaveLocalizableContent(Category category)
        {
            if (category == null)
                return;

            if (!this.HasLocalizableContent)
                return;

            foreach (RepeaterItem item in rptrLanguageDivs.Items)
            {
                if (item.ItemType == ListItemType.Item || item.ItemType == ListItemType.AlternatingItem)
                {
                    var txtLocalizedCategoryName = (TextBox)item.FindControl("txtLocalizedCategoryName");
                    var txtLocalizedDescription = (FCKeditor)item.FindControl("txtLocalizedDescription");
                    var lblLanguageId = (Label)item.FindControl("lblLanguageId");

                    int languageId = int.Parse(lblLanguageId.Text);
                    string name = txtLocalizedCategoryName.Text;
                    string description = txtLocalizedDescription.Value;

                    bool allFieldsAreEmpty = (string.IsNullOrEmpty(name) && string.IsNullOrEmpty(description));

                    var content = this.CategoryService.GetCategoryLocalizedByCategoryIdAndLanguageId(category.CategoryId, languageId);
                    if (content == null)
                    {
                        if (!allFieldsAreEmpty && languageId > 0)
                        {
                            //only insert if one of the fields are filled out (avoid too many empty records in db...)
                            content = new CategoryLocalized()
                            {
                                CategoryId = category.CategoryId,
                                LanguageId = languageId,
                                Name = name,
                                Description = description
                            };

                            this.CategoryService.InsertCategoryLocalized(content);
                        }
                    }
                    else
                    {
                        if (languageId > 0)
                        {
                            content.LanguageId = languageId;
                            content.Name = name;
                            content.Description = description;

                            this.CategoryService.UpdateCategoryLocalized(content);
                        }
                    }
                }
            }
        }
Beispiel #11
0
 /// <summary>
 /// Gets category URL
 /// </summary>
 /// <param name="category">Category</param>
 /// <returns>Category URL</returns>
 public static string GetCategoryURL(Category category)
 {
     if (category == null)
         throw new ArgumentNullException("category"); 
     string seName = GetSEName(category.SEName);
     if (String.IsNullOrEmpty(seName))
     {
         seName = GetSEName(category.Name);
     }
     string url = string.Format(SettingManager.GetSettingValue("SEO.Category.UrlRewriteFormat"), CommonHelper.GetStoreLocation(), category.CategoryID, seName);
     return url;
 }
 private string getProductId(Category category)
 {
     string productIdStrValue = "";
     var productCategoryCollention = category.ProductCategories;
     foreach (ProductCategory productCategory in productCategoryCollention)
     {
         productIdStrValue += productCategory.Product.ProductId;
         productIdStrValue += "|";
     }
     return productIdStrValue;
 }
        protected void CreateChildMenu(CategoryCollection breadCrumb, int rootCategoryID, Category currentCategory, int level)
        {
            if (level < 2)
            {
                int id = 1;
                CategoryCollection categoryCollection = CategoryManager.GetAllCategories(rootCategoryID);
                if(level == 0)
                {
                    rootCategories = categoryCollection;
                }

                foreach (Category category in categoryCollection)
                {
                    NopCommerceLi link = new NopCommerceLi();
                    phCategories.Controls.Add(link);

                    string categoryURL = SEOHelper.GetCategoryURL(category.CategoryID);

                    link.Id = id;
                    link.ParentId = parentId;
                    link.Level = level;
                    link.TotalMenuItems = categoryCollection.Count;
                    link.Title = Server.HtmlEncode(category.Name);
                    link.NavigateUrl = categoryURL;
                    link.Picture = category.Picture;
                    link.MaxCount = rootCategories.Count;
                    CategoryCollection subCategories = CategoryManager.GetAllCategories(category.CategoryID, false);
                    if(subCategories.Count > 0)
                    {
                        link.ChildCategoryUrl = SEOHelper.GetCategoryURL(subCategories[0].CategoryID);
                    }

                    CreateChildMenu(breadCrumb, category.CategoryID, currentCategory, level + 1);
                    id++;
                    if (level == 0)
                        parentId++;
                }
            }
        }
        protected int GetNumberOfProducts(Category category, bool includeSubCategories)
        {
            int numberOfProducts = 0;
            var products = this.ProductService.GetAllProducts(category.CategoryId,
                        0, 0, 0, null, null, null, string.Empty, false, 1, 0,
                        null, ProductSortingEnum.Position, out numberOfProducts);

            if (includeSubCategories)
            {
                var subCategories = this.CategoryService.GetAllCategoriesByParentCategoryId(category.CategoryId);
                foreach (var subCategory in subCategories)
                {
                    int tmp1 = GetNumberOfProducts(subCategory, includeSubCategories);
                    numberOfProducts += tmp1;
                }
            }
            return numberOfProducts;
        }