Created
November 23, 2015 02:12
-
-
Save RyanABailey/57fdf3fdd3a73220d36a to your computer and use it in GitHub Desktop.
uCommerce API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /// <summary> | |
| /// Gets all categories | |
| /// </summary> | |
| /// <returns>All categories</returns> | |
| public static List<Category> GetCategories() | |
| { | |
| return Catalog.Categories.ToList(); | |
| } | |
| /// <summary> | |
| /// Add a cataegory | |
| /// </summary> | |
| /// <param name="categoryName">Name of the catagory</param> | |
| /// <returns>The new category</returns> | |
| public static Category AddCategory(string categoryName) | |
| { | |
| if (Catalog == null) | |
| { | |
| return null; | |
| } | |
| var category = new Category | |
| { | |
| DisplayOnSite = true, | |
| Name = categoryName, | |
| ProductCatalog = Catalog, | |
| Definition = Definition.FirstOrDefault(x => x.Guid == DefaultCategoryDefinitionGuid) | |
| }; | |
| category.AddCategoryDescription(new CategoryDescription() | |
| { | |
| DisplayName = categoryName | |
| }); | |
| try | |
| { | |
| category.Save(); | |
| } | |
| catch (Exception ex) | |
| { | |
| return null; | |
| } | |
| return category; | |
| } | |
| /// <summary> | |
| /// Get a category | |
| /// </summary> | |
| /// <param name="categoryName">Name of a category</param> | |
| /// <returns>catagory</returns> | |
| public static Category GetCategory(string categoryName) | |
| { | |
| return Catalog.Categories.ToList().FirstOrDefault(x => x.Name == categoryName); | |
| } | |
| /// <summary> | |
| /// Hides a category | |
| /// </summary> | |
| /// <param name="categoryName">Name of a category</param> | |
| /// <returns>Action result</returns> | |
| public static bool HideCategory(string categoryName) | |
| { | |
| var category = Catalog.Categories.ToList().FirstOrDefault(x => x.Name == categoryName); | |
| if (category != null) | |
| { | |
| if (category.DisplayOnSite) | |
| { | |
| category.DisplayOnSite = false; | |
| category.Save(); | |
| } | |
| } | |
| else | |
| { | |
| return false; | |
| } | |
| return true; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment