public ActionResult EditPost(string id, Category posted)
        {
            Category c = EditorSetup(id);

            bool success = this.Save(c, posted, Request.Form);
            if (!success)
            {
                this.FlashFailure("Error during update. Please check event log.");
                
            }
            else
            {
                this.FlashSuccess("Category Updated Successfully at " + DateTime.Now.ToLongTimeString());
                c = EditorSetup(id);

                if (Request.Form["SaveButton"] != null || Request.Form["SaveButton.x"] != null)
                {
                    string destination = Url.Content("~/bvadmin/catalog/categories.aspx");
                    return Redirect(destination);
                }                
            }
            
            BreadCrumbs(c);
            return View(c);
        }
Esempio n. 2
0
        public void CanStoreAndRecoverCategoryWithPageVersion()
        {
            Category target = new Category();
            target.Name = "Test Category";
            target.ParentId = "0";
            target.StoreId = 0;
            target.SourceType = CategorySourceType.FlexPage;

            CategoryRepository repo = CategoryRepository.InstantiateForMemory(new RequestContext());

            Assert.IsTrue(repo.Create(target), "Create should be true");

            string categoryId = target.Bvin;
            Assert.AreNotEqual(string.Empty, categoryId, "Category Bvin should not be empty.");

            Category found = repo.Find(categoryId);
            Assert.IsNotNull(found, "Found category should not be null");
            Assert.AreEqual(found.Name, target.Name, "Names should match");

            Assert.AreEqual(1, found.Versions.Count, "Versions count should be one.");

            CategoryPageVersion foundVersion = found.Versions[0];
            Assert.IsNotNull(foundVersion, "Found page version should not be null.");
            Assert.IsTrue(foundVersion.Id > 0, "Found version should have Id > 0 assigned.");

        }
        public ActionResult Index(string slug)
        {
            ViewBag.BodyClass = "store-category-page";

            Category cat = MTApp.CatalogServices.Categories.FindBySlugForStore(slug,
                                        MTApp.CurrentRequestContext.CurrentStore.Id);
            if (cat == null) cat = new Category();
            ViewBag.Title = cat.MetaTitle;
            if (String.IsNullOrEmpty(ViewBag.Title)) { ViewBag.Title = cat.Name; }
            ViewBag.MetaKeywords = cat.MetaKeywords;
            ViewBag.MetaDescription = cat.MetaDescription;
                                                  
            // Record Category View
            MerchantTribe.Commerce.SessionManager.CategoryLastId = cat.Bvin;            
            MTApp.CurrentRequestContext.CurrentCategory = cat;            
            
            string viewName = cat.TemplateName.Trim();
            viewName = viewName.Replace(' ', '-');
            viewName = viewName.ToLowerInvariant();
            
            ThemeManager tm = MTApp.ThemeManager();
            string templateName = "category-" + viewName + ".html";              
            string template = tm.GetTemplateFromCurrentTheme(true, templateName, "category-grid.html");
            ITagProvider tagProvider = new TagProvider();
            Processor proc = new Processor(this.MTApp, this.ViewBag, template, tagProvider);                               
            StringBuilder output = new StringBuilder();
            proc.RenderForDisplay(output);
            return Content(output.ToString());
            
        }
        private Category EditorSetup(string id)
        {
            Category result = MTApp.CatalogServices.Categories.Find(id);
            if (result == null) result = new Category();

            // Fill with data from category, making sure legacy description is used if no area data
            CategoryPageVersion version = result.GetCurrentVersion();
            if (version.Id == 0)
            {
                // Create Initial Version
                version.PublishedStatus = PublishStatus.Draft;
                version.PageId = result.Bvin;
                result.Versions.Add(version);
                MTApp.CatalogServices.Categories.Update(result);
                version = result.GetCurrentVersion();
            }            
            if (!version.Areas.HasArea("main"))
            {
                version.Areas.SetAreaContent("main", result.PreTransformDescription);
                MTApp.CatalogServices.Categories.Update(result);
            }
            string areaMain = version.Areas.GetAreaContent("main");
            if (areaMain == string.Empty && result.PreTransformDescription != string.Empty)
            {
                result.GetCurrentVersion().Areas.SetAreaContent("main", result.PreTransformDescription);
            }


            ViewData["ViewInStoreUrl"] = UrlRewriter.BuildUrlForCategory(new CategorySnapshot(result), MTApp.CurrentRequestContext.RoutingContext);
            LoadTemplates();
            ViewData["OtherUrls"] = LoadUrls(result);
            return result;
        }
Esempio n. 5
0
        public void Process(List<ITemplateAction> actions, MerchantTribe.Commerce.MerchantTribeApplication app, ITagProvider tagProvider, ParsedTag tag, string innerContents)
        {
            this.App = app;
            this.Url = new System.Web.Mvc.UrlHelper(app.CurrentRequestContext.RoutingContext);
            CurrentCategory = app.CurrentRequestContext.CurrentCategory;
            if (CurrentCategory == null)
            {
                CurrentCategory = new Category();
                CurrentCategory.Bvin = "0";
            }

            StringBuilder sb = new StringBuilder();

            sb.Append("<div class=\"categorymenu\">");
            sb.Append("<div class=\"decoratedblock\">");

            string title = tag.GetSafeAttribute("title");
            if (title.Trim().Length > 0)
            {
                sb.Append("<h4>" + title + "</h4>");
            }

            sb.Append("<ul>");

            int maxDepth = 5;

            string mode = tag.GetSafeAttribute("mode");
            switch (mode.Trim().ToUpperInvariant())
            {
                case "ROOT":
                case "ROOTS":
                    // Root Categories Only
                    LoadRoots(sb);
                    break;
                case "ALL":
                    // All Categories
                    LoadAllCategories(sb, maxDepth);
                    break;
                case "":
                case "PEERS":
                    // Peers, Children and Parents
                    LoadPeersAndChildren(sb);
                    break;
                case "ROOTPLUS":
                    // Show root and expanded children
                    LoadRootPlusExpandedChildren(sb);
                    break;
                default:
                    // All Categories
                    LoadPeersAndChildren(sb);
                    break;
            }

            sb.Append("</ul>");

            sb.Append("</div>");
            sb.Append("</div>");

            actions.Add(new Actions.LiteralText(sb.ToString()));
        }
Esempio n. 6
0
        public void CanAddPageVersionToCategory()
        {
            Category target = new Category();
            Assert.AreEqual(0, target.Versions.Count, "Should be No Page Versions Yet");

            string newPageName = "Unit Test Version";
            CategoryPageVersion v = new CategoryPageVersion() { AdminName = newPageName };
            target.Versions.Add(v);
            Assert.IsNotNull(target.Versions[0], "Page Version should not be null");
            Assert.AreEqual(newPageName, target.Versions[0].AdminName, "Admin name should match");
        }
        //
        // GET: /CustomPage/
        public ActionResult Index(string slug)
        {
            ViewBag.BodyClass = "store-category-page";

            Category cat = MTApp.CatalogServices.Categories.FindBySlugForStore(slug, 
                                        MTApp.CurrentRequestContext.CurrentStore.Id);
            if (cat == null) cat = new Category();
            MTApp.CurrentRequestContext.CurrentCategory = cat;

            ViewBag.Title = cat.MetaTitle;
            if (String.IsNullOrEmpty(ViewBag.Title)) { ViewBag.Title = cat.Name; }
            ViewBag.MetaKeywords = cat.MetaKeywords;
            ViewBag.MetaDescription = cat.MetaDescription;

            // Record View for Analytics
            RecordCategoryView(cat.Bvin);
            
            // Get page.html Template
            ThemeManager tm = MTApp.ThemeManager();
            if (cat.TemplateName == string.Empty) { cat.TemplateName = "default.html"; }
            string template = tm.GetTemplateFromCurrentTheme(true, cat.TemplateName, "default.html"); // Try default in theme before system

            // Fill with data from category, making sure legacy description is used if no area data
            CategoryPageVersion version = cat.GetCurrentVersion();
            if (version.Id == 0)
            {
                // Create Initial Version
                version.PublishedStatus = PublishStatus.Draft;
                version.PageId = cat.Bvin;
                cat.Versions.Add(version);
                MTApp.CatalogServices.Categories.Update(cat);
                version = cat.GetCurrentVersion();
            }
            if (!version.Areas.HasArea("main"))
            {
                version.Areas.SetAreaContent("main", cat.PreTransformDescription);
            }

            ITagProvider tagProvider = new TagProvider();
            Processor proc = new Processor(this.MTApp, this.ViewBag, template, tagProvider);

            // Render Bread Crumbs
            var breadRender = new code.TemplateEngine.TagHandlers.BreadCrumbs();
            ViewBag.BreadCrumbsFinal = breadRender.RenderCategory(MTApp, new List<BreadCrumbItem>(), cat);

            var columnRenderer = new code.TemplateEngine.TagHandlers.ContentColumn();
            ViewBag.SideColumn = columnRenderer.RenderColumnToString("4", MTApp, ViewBag);

            StringBuilder output = new StringBuilder();
            proc.RenderForDisplay(output);
            return Content(output.ToString());            
        }
 private Category CreateCategory()
 {
     Category c = MTApp.CatalogServices.Categories.Find(this.BvinField.Value);
     if (c == null) c = new Category();
     c.Name = "NEW Web Site Page";
     c.ParentId = this.ParentIDField.Value;
     c.RewriteUrl = "NEW-Web-Site-Page";
     c.SourceType = CategorySourceType.FlexPage;
     c.StoreId = MTApp.CurrentStore.Id;            
     MTApp.CatalogServices.Categories.Create(c);
     this.BvinField.Value = c.Bvin;
     return LoadCategory();
 }
        //
        // GET: /CustomPage/
        public ActionResult Index(string slug)
        {
            Category cat = MTApp.CatalogServices.Categories.FindBySlugForStore(slug,
                                        MTApp.CurrentRequestContext.CurrentStore.Id);
            if (cat == null) cat = new Category();
            MTApp.CurrentRequestContext.CurrentCategory = cat;

            // Record View for Analytics
            RecordCategoryView(cat.Bvin);

            // Get page.html Template
            ThemeManager tm = MTApp.ThemeManager();
            if (cat.TemplateName == string.Empty) { cat.TemplateName = "default.html"; }
            string template = tm.GetTemplateFromCurrentTheme(cat.TemplateName);

            // Fill with data from category, making sure legacy description is used if no area data
            CategoryPageVersion version = cat.GetCurrentVersion();
            if (version.Id == 0)
            {
                // Create Initial Version
                version.PublishedStatus = PublishStatus.Draft;
                version.PageId = cat.Bvin;
                cat.Versions.Add(version);
                MTApp.CatalogServices.Categories.Update(cat);
                version = cat.GetCurrentVersion();
            }
            if (!version.Areas.HasArea("main"))
            {
                version.Areas.SetAreaContent("main", cat.PreTransformDescription);
            }

            TemplateProcessor proc = new TemplateProcessor(this.MTApp, template);
            string processed = proc.RenderForDisplay();

            // Process Template Here
            return new ContentResult() { Content = processed, ContentEncoding = Encoding.UTF8, ContentType = "text/html" };

            /* OLD RAZOR VIEW */
            //ViewBag.Title = cat.MetaTitle;
            //ViewBag.MetaKeywords = cat.MetaKeywords;
            //ViewBag.MetaDescription = cat.MetaDescription;
            //ViewBag.DisplayHtml = TagReplacer.ReplaceContentTags(cat.Description,
            //                                                     this.MTApp,
            //                                                     "",
            //                                                     Request.IsSecureConnection);
            //return View(cat);
        }
        public ActionResult CategoryTrail(Category cat, List<BreadCrumbItem> extras)
        {
            CategorySnapshot snap = new CategorySnapshot(cat);

            BreadCrumbViewModel model = new BreadCrumbViewModel();
            model.HomeName = MerchantTribe.Commerce.Content.SiteTerms.GetTerm(MerchantTribe.Commerce.Content.SiteTermIds.Home);

            LoadTrailForCategory(model, snap, false);

            if (extras != null)
            {
                foreach (BreadCrumbItem item in extras)
                {
                    model.Items.Enqueue(item);
                }
            }
            return View("BreadCrumb", model);
        }
Esempio n. 11
0
 public CategorySnapshot(Category cat)
 {
     this.Bvin = cat.Bvin;
     this.StoreId = cat.StoreId;
     this.ParentId = cat.ParentId;
     this.Name = cat.Name;
     this.SourceType = cat.SourceType;
     this.ImageUrl = cat.ImageUrl;
     this.LatestProductCount = cat.LatestProductCount;
     this.CustomPageUrl = cat.CustomPageUrl;
     this.ShowInTopMenu = cat.ShowInTopMenu;
     this.Hidden = cat.Hidden;
     this.CustomPageId = cat.CustomPageId;
     this.CustomPageLayout = cat.CustomPageLayout;
     this.SortOrder = cat.SortOrder;
     this.MetaTitle = cat.MetaTitle;
     this.RewriteUrl = cat.RewriteUrl;
 }
        //
        // GET: /CustomPage/
        public ActionResult Index(string slug)
        {
            Category cat = MTApp.CatalogServices.Categories.FindBySlugForStore(slug,
                                        MTApp.CurrentRequestContext.CurrentStore.Id);
            if (cat == null) cat = new Category();
            MTApp.CurrentRequestContext.CurrentCategory = cat;

            ViewBag.Title = cat.MetaTitle;
            if (String.IsNullOrEmpty(ViewBag.Title)) { ViewBag.Title = cat.Name; }
            ViewBag.MetaKeywords = cat.MetaKeywords;
            ViewBag.MetaDescription = cat.MetaDescription;

            // Record View for Analytics
            RecordCategoryView(cat.Bvin);

            // Get page.html Template
            ThemeManager tm = MTApp.ThemeManager();
            if (cat.TemplateName == string.Empty) { cat.TemplateName = "default.html"; }
            string template = tm.GetTemplateFromCurrentTheme(cat.TemplateName, "default.html"); // Try default in theme before system

            // Fill with data from category, making sure legacy description is used if no area data
            CategoryPageVersion version = cat.GetCurrentVersion();
            if (version.Id == 0)
            {
                // Create Initial Version
                version.PublishedStatus = PublishStatus.Draft;
                version.PageId = cat.Bvin;
                cat.Versions.Add(version);
                MTApp.CatalogServices.Categories.Update(cat);
                version = cat.GetCurrentVersion();
            }
            if (!version.Areas.HasArea("main"))
            {
                version.Areas.SetAreaContent("main", cat.PreTransformDescription);
            }

            ITagProvider tagProvider = new TagProvider();
            Processor proc = new Processor(this.MTApp, template, tagProvider);

            var model = proc.RenderForDisplay();
            return View("~/views/shared/templateengine.cshtml", model);
        }
 private void UpdateIconImage(Category c)
 {
     IconImage = MerchantTribe.Commerce.Storage.DiskStorage.CategoryIconUrl(MTApp, c.Bvin, c.ImageUrl, true);
     if (IconImage == string.Empty || c.ImageUrl == string.Empty)
     {
         IconImage = Page.ResolveUrl("~/content/admin/images/MissingImage.png");
     }
 }
        private bool Save(Category c)
        {
            bool result = false;

            if (c != null)
            {
                c.Name = this.NameField.Text.Trim();
                c.Description = this.DescriptionField.Text.Trim();
                c.PreTransformDescription = this.DescriptionField.PreTransformText;
                c.MetaDescription = this.MetaDescriptionField.Text.Trim();
                c.MetaTitle = this.MetaTitleField.Text.Trim();
                c.MetaKeywords = this.MetaKeywordsField.Text.Trim();
                c.ShowInTopMenu = false;
                // Me.chkShowInTopMenu.Checked
                c.Hidden = this.chkHidden.Checked;

                // Icon Image Upload
                if ((this.iconupload.HasFile))
                {
                    string fileName = System.IO.Path.GetFileNameWithoutExtension(iconupload.FileName);
                    string ext = System.IO.Path.GetExtension(iconupload.FileName);

                    if (MerchantTribe.Commerce.Storage.DiskStorage.ValidateImageType(ext))
                    {
                        fileName = MerchantTribe.Web.Text.CleanFileName(fileName);
                        if ((MerchantTribe.Commerce.Storage.DiskStorage.UploadCategoryIcon(MTApp.CurrentStore.Id, c.Bvin, this.iconupload.PostedFile)))
                        {
                            c.ImageUrl = fileName + ext;
                        }
                    }
                    else
                    {
                        result = false;
                        this.MessageBox1.ShowError("Only .PNG, .JPG, .GIF file types are allowed for icon images");
                    }
                }

                // Banner Image Upload
                if ((this.bannerupload.HasFile))
                {
                    string fileName = System.IO.Path.GetFileNameWithoutExtension(bannerupload.FileName);
                    string ext = System.IO.Path.GetExtension(bannerupload.FileName);

                    if (MerchantTribe.Commerce.Storage.DiskStorage.ValidateImageType(ext))
                    {
                        fileName = MerchantTribe.Web.Text.CleanFileName(fileName);
                        if ((MerchantTribe.Commerce.Storage.DiskStorage.UploadCategoryBanner(MTApp.CurrentStore.Id, c.Bvin, this.bannerupload.PostedFile)))
                        {
                            c.BannerImageUrl = fileName + ext;
                        }
                    }
                    else
                    {
                        result = false;
                        this.MessageBox1.ShowError("Only .PNG, .JPG, .GIF file types are allowed for icon images");
                    }
                }

                //if ((CategorySourceType)ViewState["type"] == CategorySourceType.ByRules) {
                //    c.SourceType = CategorySourceType.ByRules;
                //}
                //else if ((CategorySourceType)ViewState["type"] == CategorySourceType.CustomLink) {
                //    c.SourceType = CategorySourceType.CustomLink;
                //}
                //else if ((CategorySourceType)ViewState["type"] == CategorySourceType.Manual) {
                c.SourceType = CategorySourceType.Manual;
                //}
                //else if ((CategorySourceType)ViewState["type"] == CategorySourceType.CustomPage) {
                //    c.SourceType = CategorySourceType.CustomPage;
                //}
                string templateName = this.TemplateList.SelectedItem.Value;
                if (string.IsNullOrEmpty(templateName)) { templateName = "Grid"; }
                c.TemplateName = templateName;
                c.PreContentColumnId = this.PreContentColumnIdField.SelectedValue;
                c.PostContentColumnId = this.PostContentColumnIdField.SelectedValue;
                c.DisplaySortOrder = (CategorySortOrder)int.Parse(this.SortOrderDropDownList.SelectedValue);

                string oldUrl = c.RewriteUrl;

                // no entry, generate one
                if (c.RewriteUrl.Trim().Length < 1)
                {
                    c.RewriteUrl = MerchantTribe.Web.Text.Slugify(c.Name, true, true);
                }
                else
                {
                    c.RewriteUrl = MerchantTribe.Web.Text.Slugify(this.RewriteUrlField.Text, true, true);
                }
                this.RewriteUrlField.Text = c.RewriteUrl;

                if (UrlRewriter.IsCategorySlugInUse(c.RewriteUrl, c.Bvin, MTApp.CurrentRequestContext))
                {
                    this.MessageBox1.ShowWarning("The requested URL is already in use by another item.");
                    return false;
                }

                c.ShowTitle = this.chkShowTitle.Checked;
                c.Keywords = this.keywords.Text.Trim();

                c.CustomerChangeableSortOrder = true;
                // Me.CustomerOverridableSortOrderCheckBox.Checked

                if (this.BvinField.Value == string.Empty)
                {
                    c.ParentId = this.ParentIDField.Value;
                    result = MTApp.CatalogServices.Categories.Create(c);
                    if (result)
                    {
                        result = MTApp.CatalogServices.Categories.SubmitChanges();
                    }
                }
                else
                {
                    result = MTApp.CatalogServices.Categories.Update(c);
                    if (result)
                    {
                        result = MTApp.CatalogServices.Categories.SubmitChanges();
                    }
                }

                if (result == false)
                {
                    this.lblError.Text = "Unable to save category. Uknown error.";
                }
                else
                {
                    // Update bvin field so that next save will call updated instead of create
                    this.BvinField.Value = c.Bvin;

                    if (oldUrl != string.Empty)
                    {
                        if (oldUrl != c.RewriteUrl)
                        {
                            MTApp.ContentServices.CustomUrls.Register301(oldUrl,c.RewriteUrl,
                                                  c.Bvin, CustomUrlType.Category, MTApp.CurrentRequestContext, MTApp);
                            this.UrlsAssociated1.LoadUrls();
                        }
                    }
                }

            }

            return result;
        }
 private bool Save()
 {
     Category c = MTApp.CatalogServices.Categories.Find(this.BvinField.Value);
     if (c == null)
     {
         c = new Category();
     }
     return Save(c);
 }
 private Catalog.Category CreateSampleCategoryPage(string name, string url, string description)
 {
     Catalog.Category result = new Category();
     result.CustomPageLayout = CustomPageLayoutType.WithSideBar;
     result.SourceType = CategorySourceType.CustomPage;
     result.Name = name;
     result.RewriteUrl = url;
     result.Description = description;
     result.MetaTitle = MerchantTribe.Web.Text.TrimToLength(name, 250);
     result.MetaDescription = MerchantTribe.Web.Text.TrimToLength(description, 250);
     result.Keywords = MerchantTribe.Web.Text.TrimToLength(name, 250);
     result.ShowTitle = true;
     result.ShowInTopMenu = true;
     CatalogServices.Categories.Create(result);
     return result;
 }
Esempio n. 17
0
        public string RenderCategory(MerchantTribeApplication app, List<BreadCrumbItem> extras, Category cat)
        {            
            CategorySnapshot snap = new CategorySnapshot(cat);

            BreadCrumbViewModel model = new BreadCrumbViewModel();
            model.HomeName = MerchantTribe.Commerce.Content.SiteTerms.GetTerm(MerchantTribe.Commerce.Content.SiteTermIds.Home);

            LoadTrailForCategory(model, snap, false, app);

            if (extras != null && extras.Count > 0)
            {
                foreach (BreadCrumbItem item in extras)
                {
                    model.Items.Enqueue(item);
                }
            }

            return Render(app, model);
        }
Esempio n. 18
0
        protected void btnNew_Click(object sender, ImageClickEventArgs e)
        {
            Category c = new Category();
            c.ParentId = this.lstParents.SelectedItem.Value;
            CategorySourceType sourceType = CategorySourceType.Manual;
            System.Enum.TryParse<CategorySourceType>(this.lstType.SelectedItem.Value, out sourceType);
            c.SourceType = sourceType;
            c.Name = "NEW Page";            
            c.RewriteUrl = "NEW-Page";
            c.StoreId = MTApp.CurrentStore.Id;

            if (c.SourceType == CategorySourceType.CustomPage)
            {
                c.GetCurrentVersion().Areas.SetAreaContent("Main", string.Empty);
                c.TemplateName = "default.html";                
            }
            MTApp.CatalogServices.Categories.Create(c);

            string editUrl = "~" + MTApp.CatalogServices.EditorRouteForCategory(c.SourceType, c.Bvin);
            editUrl = Page.ResolveUrl(editUrl);
            Response.Redirect(editUrl);            
        }
 private void BreadCrumbs(Category cat)
 {
     var renderer = new code.TemplateEngine.TagHandlers.BreadCrumbs();
     ViewBag.BreadCrumbsFinal = renderer.RenderCategory(this.MTApp, new List<Models.BreadCrumbItem>(), cat);
 }
        public ActionResult DrillDownIndex(string slug)
        {
            ViewBag.BodyClass = "store-categorydrilldown-page";

            Category cat = MTApp.CatalogServices.Categories.FindBySlugForStore(slug,
                                        MTApp.CurrentRequestContext.CurrentStore.Id);
            if (cat == null) cat = new Category();

            ViewBag.Title = cat.MetaTitle;
            if (String.IsNullOrEmpty(ViewBag.Title)) { ViewBag.Title = cat.Name; }
            ViewBag.MetaKeywords = cat.MetaKeywords;
            ViewBag.MetaDescription = cat.MetaDescription;
            ViewBag.DisplayHtml = TagReplacer.ReplaceContentTags(cat.Description,
                                                                 this.MTApp,
                                                                 "",
                                                                 Request.IsSecureConnection);

            string key = Request.QueryString["node"] ?? string.Empty;
            if (key == "-") key = string.Empty;
            ViewBag.Key = key;

            int pageNumber = GetPageNumber();
            int pageSize = 9;
            int totalItems = 0;

            CategoryPageViewModel model = new CategoryPageViewModel();

            CategoryFacetManager manager = CategoryFacetManager.InstantiateForDatabase(MTApp.CurrentRequestContext);
            List<CategoryFacet> facets = manager.FindByCategory(cat.Bvin);
            List<ProductProperty> properties = LoadProperties(facets);
            if (key == string.Empty)
            {
                key = CategoryFacetKeyHelper.BuildEmptyKey(facets.Count);
            }
            List<long> parsedKey = CategoryFacetKeyHelper.ParseKeyToList(key);

            List<Product> products = MTApp.CatalogServices.FindProductsMatchingKey(key,
                                                                            pageNumber,
                                                                            pageSize,
                                                                            ref totalItems);

            List<ProductFacetCount> productCounts = manager.FindCountsOfVisibleFacets(key, facets, properties);
            List<long> visibleIds = manager.FindVisibleFacetsIdsForKey(key, facets);

            model.Products = PrepProducts(products);
            model.LocalCategory = cat;
            model.PagerData.PageSize = pageSize;
            model.PagerData.TotalItems = totalItems;
            model.PagerData.CurrentPage = pageNumber;
            model.PagerData.PagerUrlFormat = UrlRewriter.BuildUrlForCategory(new CategorySnapshot(cat),
                                            MTApp.CurrentRequestContext.RoutingContext,
                                            "{0}");
            model.PagerData.PagerUrlFormatFirst = UrlRewriter.BuildUrlForCategory(new CategorySnapshot(cat),
                                            MTApp.CurrentRequestContext.RoutingContext);
            model.SubCategories = PrepSubCategories(MTApp.CatalogServices.Categories.FindVisibleChildren(cat.Bvin));

            StringBuilder sbNotSelected = new StringBuilder();

            List<BreadCrumbItem> extraCrumbs = new List<BreadCrumbItem>();

            for (int i = 0; i < facets.Count; i++)
            {
                if (visibleIds.Contains(facets[i].Id))
                {
                    // Find the property that matches the facet
                    var p = (from pr in properties
                             where pr.Id == facets[i].PropertyId
                             select pr).SingleOrDefault();
                    if (p != null)
                    {
                        if (parsedKey[i] < 1)
                        {
                            // not selected
                            this.RenderNonSelection(sbNotSelected, i, parsedKey[i], key, facets[i], p, productCounts, model);
                        }
                        else
                        {
                            // selected
                            this.RenderSelection(sbNotSelected, i, parsedKey[i], key, facets[i], p, facets, model, extraCrumbs);
                        }
                    }
                }
            }

            ViewBag.ExtraCrumbs = extraCrumbs;
            ViewBag.Filters = sbNotSelected.ToString();

            // Banner
            if (cat.BannerImageUrl.Trim().Length > 0)
            {
                ViewBag.ShowBanner = true;
                ViewBag.BannerUrl = MerchantTribe.Commerce.Storage.DiskStorage.CategoryBannerUrl(
                                        MTApp,
                                        cat.Bvin,
                                        cat.BannerImageUrl,
                                        Request.IsSecureConnection);
            }
            else
            {
                ViewBag.ShowBanner = false;
            }

            // Record Category View
            MerchantTribe.Commerce.SessionManager.CategoryLastId = cat.Bvin;

            return View("DrillDown", model);
        }
        private bool Save()
        {
            bool result = false;

            Category c = MTApp.CatalogServices.Categories.Find(this.BvinField.Value);
            if (c == null)
            {
                c = new Category();
            }
            if (c != null)
            {
                c.Name = this.NameField.Text.Trim();
                c.Description = this.DescriptionField.Text.Trim();
                c.PreTransformDescription = this.DescriptionField.PreTransformText;
                c.MetaDescription = this.MetaDescriptionField.Text.Trim();
                c.MetaTitle = this.MetaTitleField.Text.Trim();
                c.MetaKeywords = this.MetaKeywordsField.Text.Trim();
                c.ShowInTopMenu = false;
                c.SourceType = CategorySourceType.CustomPage;

                string oldUrl = c.RewriteUrl;

                // no entry, generate one
                if (c.RewriteUrl.Trim().Length < 1)
                {
                    c.RewriteUrl = MerchantTribe.Web.Text.Slugify(c.Name, true, true);
                }
                else
                {
                    c.RewriteUrl = MerchantTribe.Web.Text.Slugify(this.RewriteUrlField.Text, true, true);
                }
                this.RewriteUrlField.Text = c.RewriteUrl;

                if (UrlRewriter.IsCategorySlugInUse(c.RewriteUrl, c.Bvin, MTApp.CurrentRequestContext))
                {
                    this.MessageBox1.ShowWarning("The requested URL is already in use by another item.");
                    return false;
                }

                if (this.chkShowSidebar.Checked)
                {
                    c.CustomPageLayout = CustomPageLayoutType.WithSideBar;
                }
                else
                {
                    c.CustomPageLayout = CustomPageLayoutType.Empty;
                }

                c.CustomerChangeableSortOrder = true;

                if (this.BvinField.Value == string.Empty)
                {
                    c.ParentId = this.ParentIDField.Value;
                    result = MTApp.CatalogServices.Categories.Create(c);
                    if (result)
                    {
                        result = MTApp.CatalogServices.Categories.SubmitChanges();
                    }
                }
                else
                {
                    result = MTApp.CatalogServices.Categories.Update(c);
                    if (result)
                    {
                        result = MTApp.CatalogServices.Categories.SubmitChanges();
                    }
                }

                if (result == false)
                {
                    this.lblError.Text = "Unable to save category. Uknown error.";
                }
                else
                {
                    // Update bvin field so that next save will call updated instead of create
                    this.BvinField.Value = c.Bvin;

                    if (oldUrl != string.Empty)
                    {
                        if (oldUrl != c.RewriteUrl)
                        {
                            MTApp.ContentServices.CustomUrls.Register301(oldUrl,
                                                  c.RewriteUrl,
                                                  c.Bvin, CustomUrlType.Category, MTApp.CurrentRequestContext,
                                                  MTApp);
                            this.UrlsAssociated1.LoadUrls();
                        }
                    }
                }
            }

            return result;
        }
        private bool Save(Category current, Category posted, System.Collections.Specialized.NameValueCollection form)
        {

            bool result = false;

            if (current != null)
            {
                current.Name = posted.Name.Trim();

                /* Areas */
                string mainArea = string.Empty;
                if (form["area-main"] != null)
                {
                    mainArea = form["area-main"];
                }
                current.Description = mainArea;
                current.PreTransformDescription = mainArea;
                current.GetCurrentVersion().Areas.SetAreaContent("main", mainArea);                
                
                /* Other Settings */
                current.MetaDescription = form["metadescription"] ?? current.MetaDescription;
                current.MetaTitle = form["metatitle"] ?? current.MetaTitle;
                current.MetaKeywords = form["metakeywords"] ?? current.MetaKeywords;
                current.ShowInTopMenu = false; // This could be changed to support show in top menu functionality
                current.SourceType = CategorySourceType.CustomPage;

                // hidden checkbox
                string isChecked = form["hidden"] ?? string.Empty;
                current.Hidden = (isChecked == "true");                

                string oldUrl = current.RewriteUrl;

                // no entry, generate one
                if (current.RewriteUrl.Trim().Length < 1)
                {
                    current.RewriteUrl = MerchantTribe.Web.Text.Slugify(current.Name, true, true);
                }
                else
                {
                    current.RewriteUrl = MerchantTribe.Web.Text.Slugify(form["rewriteurl"] ?? current.RewriteUrl, true, true);
                }
                
                if (UrlRewriter.IsCategorySlugInUse(current.RewriteUrl, current.Bvin, MTApp.CurrentRequestContext))
                {
                    FlashWarning("The requested URL is already in use by another item.");
                    return false;
                }

                current.TemplateName = posted.TemplateName;
                
                current.CustomerChangeableSortOrder = true;

                
                result = MTApp.CatalogServices.Categories.Update(current);
                                
                if (result == true)
                {
                    if (oldUrl != string.Empty)
                    {
                        if (oldUrl != current.RewriteUrl)
                        {
                            MTApp.ContentServices.CustomUrls.Register301(oldUrl,
                                                  current.RewriteUrl,
                                                  current.Bvin, CustomUrlType.Category, MTApp.CurrentRequestContext,
                                                  MTApp);
                            
                        }
                    }
                }
            }

            return result;
        }
        private void PopulateStoreLink(Category c)
        {

            HyperLink m = new HyperLink();
            m.ImageUrl = "~/BVAdmin/Images/Buttons/ViewInStore.png";
            m.ToolTip = c.MetaTitle;
            m.NavigateUrl = UrlRewriter.BuildUrlForCategory(new CategorySnapshot(c), MTApp.CurrentRequestContext.RoutingContext);
            m.EnableViewState = false;
            this.inStore.Controls.Add(m);

        }
        private bool Save(Category c)
        {
            bool result = false;

            if (c != null)
            {
                c.Name = this.NameField.Text.Trim();
                c.MetaTitle = this.MetaTitleField.Text.Trim();
                c.CustomPageUrl = this.LinkToField.Text.Trim();
                c.ShowInTopMenu = false;                
                c.Hidden = this.chkHidden.Checked;

                // Icon Image Upload
                if ((this.iconupload.HasFile))
                {
                    string fileName = System.IO.Path.GetFileNameWithoutExtension(iconupload.FileName);
                    string ext = System.IO.Path.GetExtension(iconupload.FileName);

                    if (MerchantTribe.Commerce.Storage.DiskStorage.ValidateImageType(ext))
                    {
                        fileName = MerchantTribe.Web.Text.CleanFileName(fileName);
                        if ((MerchantTribe.Commerce.Storage.DiskStorage.UploadCategoryIcon(MTApp.CurrentStore.Id, c.Bvin, this.iconupload.PostedFile)))
                        {
                            c.ImageUrl = fileName + ext;
                        }
                    }
                    else
                    {
                        result = false;
                        this.MessageBox1.ShowError("Only .PNG, .JPG, .GIF file types are allowed for icon images");
                    }
                }

                c.SourceType = CategorySourceType.CustomLink;
                
                if (this.BvinField.Value == string.Empty)
                {
                    c.ParentId = this.ParentIDField.Value;
                    result = MTApp.CatalogServices.Categories.Create(c);
                    if (result)
                    {
                        result = MTApp.CatalogServices.Categories.SubmitChanges();
                    }
                }
                else
                {
                    result = MTApp.CatalogServices.Categories.Update(c);
                    if (result)
                    {
                        result = MTApp.CatalogServices.Categories.SubmitChanges();
                    }
                }

                if (result == false)
                {
                    this.lblError.Text = "Unable to save category. Uknown error.";
                }
                else
                {
                    // Update bvin field so that next save will call updated instead of create
                    this.BvinField.Value = c.Bvin;
                }

            }

            return result;
        }
        public ActionResult Index(string slug)
        {
            Category cat = MTApp.CatalogServices.Categories.FindBySlugForStore(slug, MTApp.CurrentRequestContext.CurrentStore.Id);
            if (cat == null) cat = new Category();

            if (cat.SourceType != CategorySourceType.FlexPage)
            {
                CheckFor301("/" + slug);
                return Redirect("~/Error?type=category");
            }

            if (cat.Hidden)
            {
                return Redirect("~/Error?type=category");
            }

            FlexPageEditorViewModel editorModel = new FlexPageEditorViewModel();
            editorModel.CategoryId = cat.Bvin;
            editorModel.IsPreview = false;
            editorModel.CurrentPageUrl = Request.AppRelativeCurrentExecutionFilePath;
            editorModel.IsEditMode = false;

            ViewBag.Title = cat.MetaTitle;
            ViewBag.MetaKeywords = cat.MetaKeywords;
            ViewBag.MetaDescription = cat.MetaDescription;
            ViewData["basecss"] = Url.Content("~/content/FlexBase.css");
            ViewData["slug"] = slug;
            MTApp.CurrentRequestContext.FlexPageId = cat.Bvin;
            MTApp.CurrentRequestContext.UrlHelper = this.Url;

            if (MTApp.IsEditMode)
            {
                editorModel.IsEditMode = true;
                string editCSS = "<link href=\"" + Url.Content("~/content/flexedit.css") + "\" rel=\"stylesheet\" type=\"text/css\" />";
                string editJS = "<script type=\"text/javascript\" src=\"" + Url.Content("~/content/FlexEdit.js") + "\"></script>";
                editJS += "<script type=\"text/javascript\" src=\"" + Url.Content("~/scripts/Silverlight.js") + "\"></script>";

                // Inject CSS and JS into head section of page
                ViewData["AdditionalMetaTags"] += "\n" + editCSS + "\n" + editJS;
            }

            // Pre-Populate Empty Page
            if (cat.Versions.Count < 1)
            {
                cat.Versions.Add(new CategoryPageVersion() { AdminName = "First Version", PublishedStatus = PublishStatus.Published, Root = cat.GetSimpleSample() });
                MTApp.CatalogServices.Categories.Update(cat);
                cat = MTApp.CatalogServices.Categories.Find(cat.Bvin);
            }

            // Load Content Parts for Page
            try
            {
                if (MTApp.IsEditMode)
                {
                    if (Request["preview"] == "1")
                    {
                        ViewData["ContentParts"] = cat.Versions[0].Root.RenderForDisplay(MTApp, cat);
                        editorModel.IsPreview = true;
                    }
                    else
                    {
                        ViewData["ContentParts"] = cat.Versions[0].Root.RenderForEdit(MTApp, cat);
                        editorModel.IsPreview = false;
                    }
                }
                else
                {
                    ViewData["ContentParts"] = cat.Versions[0].Root.RenderForDisplay(MTApp, cat);
                    editorModel.IsPreview = false;
                }
            }
            catch (Exception ex)
            {
                ViewData["ContentParts"] = ex.Message + ex.StackTrace;
            }

            // Save Editor Model to View Data
            ViewData["FlexEditorModel"] = editorModel;

            // Stuff the flex page content into the area field on the category
            // it will be rendered in main area tag
            if (cat.Versions[0].Areas == null) cat.Versions[0].Areas = new AreaData();
            cat.Versions[0].Areas.SetAreaContent("Main", (string)ViewData["ContentParts"]);

            MTApp.CurrentRequestContext.CurrentCategory = cat;

            string template = this.MTApp.ThemeManager().GetTemplateFromCurrentTheme("default-no-menu.html");
            Processor p = new Processor(this.MTApp, this.ViewBag, template, new TagProvider());

            StringBuilder output = new StringBuilder();
            p.RenderForDisplay(output);
            return Content(output.ToString());
        }
 private Catalog.Category CreateSampleCategory(string name, string url, string description, string template)
 {
     Catalog.Category result = new Category();
     result.Name = name;
     result.RewriteUrl = url;
     result.Description = description;
     result.MetaTitle = MerchantTribe.Web.Text.TrimToLength(name, 250);
     result.MetaDescription = MerchantTribe.Web.Text.TrimToLength(description, 250);
     result.Keywords = MerchantTribe.Web.Text.TrimToLength(name, 250);
     result.ShowTitle = true;
     result.ShowInTopMenu = true;
     result.TemplateName = template;
     CatalogServices.Categories.Create(result);
     return result;
 }
Esempio n. 27
0
        // Create or Update
        public override string PostAction(string parameters, System.Collections.Specialized.NameValueCollection querystring, string postdata)
        {
            string data = string.Empty;
            string bvin = FirstParameter(parameters);
            ApiResponse<CategoryDTO> response = new ApiResponse<CategoryDTO>();

            CategoryDTO postedCategory = null;
            try
            {
                postedCategory = MerchantTribe.Web.Json.ObjectFromJson<CategoryDTO>(postdata);
            }
            catch(Exception ex)
            {
                response.Errors.Add(new ApiError("EXCEPTION", ex.Message));
                return MerchantTribe.Web.Json.ObjectToJson(response);                
            }

            Category c = new Category();
            c.FromDto(postedCategory);

            if (bvin == string.Empty)
            {
                if (MTApp.CatalogServices.Categories.Create(c))
                {
                    bvin = c.Bvin;
                }
            }
            else
            {
                MTApp.CatalogServices.Categories.Update(c);
            }
            Category resultCategory = MTApp.CatalogServices.Categories.Find(bvin);                    
            if (resultCategory != null) response.Content = resultCategory.ToDto();
            
            data = MerchantTribe.Web.Json.ObjectToJson(response);            
            return data;
        }
        private string LoadUrls(Category cat)
        {
            if (cat == null) return string.Empty;

            List<CustomUrl> all = MTApp.ContentServices.CustomUrls.FindBySystemData(cat.Bvin);
            if (all == null) return string.Empty;
            if (all.Count < 1) return string.Empty;
            
            StringBuilder sb = new StringBuilder();
            sb.Append("<ul class=\"redirects301\">");
            foreach (CustomUrl c in all)
            {
                sb.Append("<li>");
                sb.Append(HttpUtility.HtmlEncode(c.RequestedUrl));
                sb.Append(" <a href=\"#\" class=\"remove301\" id=\"remove" + c.Bvin + "\">Remove");
                sb.Append("</a></li>");
            }
            sb.Append("</ul>");
            return sb.ToString();            
        }
        private bool Save()
        {
            bool result = false;

            Category c = MTApp.CatalogServices.Categories.Find(this.BvinField.Value);
            if (c == null)
            {
                c = new Category();
            }
            if (c != null)
            {
                c.Name = this.NameField.Text.Trim();
                c.Description = this.DescriptionField.Text.Trim();                
                c.MetaDescription = this.MetaDescriptionField.Text.Trim();
                c.MetaTitle = this.MetaTitleField.Text.Trim();
                c.MetaKeywords = this.MetaKeywordsField.Text.Trim();
                c.ShowInTopMenu = false;
                c.SourceType = CategorySourceType.DrillDown;

                // no entry, generate one
                if (c.RewriteUrl.Trim().Length < 1)
                {
                    c.RewriteUrl = MerchantTribe.Web.Text.Slugify(c.Name, true, true);
                }
                else
                {
                    c.RewriteUrl = MerchantTribe.Web.Text.Slugify(this.RewriteUrlField.Text, true, true);
                }
                this.RewriteUrlField.Text = c.RewriteUrl;

                c.CustomerChangeableSortOrder = true;

                if (this.BvinField.Value == string.Empty)
                {
                    c.ParentId = this.ParentIDField.Value;
                    result = MTApp.CatalogServices.Categories.Create(c);
                }
                else
                {
                    result = MTApp.CatalogServices.Categories.Update(c);
                }

                if (result == false)
                {
                    this.lblError.Text = "Unable to save category. Uknown error.";
                }
                else
                {
                    // Update bvin field so that next save will call updated instead of create
                    this.BvinField.Value = c.Bvin;
                }

            }

            return result;
        }
        public ActionResult Index(string slug)
        {
            ViewBag.BodyClass = "store-category-page";

            Category cat = MTApp.CatalogServices.Categories.FindBySlugForStore(slug,
                                        MTApp.CurrentRequestContext.CurrentStore.Id);
            if (cat == null) cat = new Category();

            ViewBag.Title = cat.MetaTitle;
            if (String.IsNullOrEmpty(ViewBag.Title)) { ViewBag.Title = cat.Name; }
            ViewBag.MetaKeywords = cat.MetaKeywords;
            ViewBag.MetaDescription = cat.MetaDescription;
            ViewBag.DisplayHtml = TagReplacer.ReplaceContentTags(cat.Description,
                                                                 this.MTApp,
                                                                 "",
                                                                 Request.IsSecureConnection);

            ViewBag.AddToCartButton = this.MTApp.ThemeManager().ButtonUrl("AddToCart", Request.IsSecureConnection);
            ViewBag.DetailsButton = this.MTApp.ThemeManager().ButtonUrl("View", Request.IsSecureConnection);

            int pageNumber = GetPageNumber();
            int pageSize = 9;
            int totalItems = 0;

            CategoryPageViewModel model = new CategoryPageViewModel();
            List<Product> products = MTApp.CatalogServices.FindProductForCategoryWithSort(
                                            cat.Bvin,
                                            CategorySortOrder.ManualOrder,
                                            false,
                                            pageNumber, pageSize, ref totalItems);
            model.Products = PrepProducts(products);
            model.LocalCategory = cat;
            model.PagerData.PageSize = pageSize;
            model.PagerData.TotalItems = totalItems;
            model.PagerData.CurrentPage = pageNumber;
            model.PagerData.PagerUrlFormat = UrlRewriter.BuildUrlForCategory(new CategorySnapshot(cat),
                                            MTApp.CurrentRequestContext.RoutingContext,
                                            "{0}");
            model.PagerData.PagerUrlFormatFirst = UrlRewriter.BuildUrlForCategory(new CategorySnapshot(cat),
                                            MTApp.CurrentRequestContext.RoutingContext);
            model.SubCategories = PrepSubCategories(MTApp.CatalogServices.Categories.FindVisibleChildren(cat.Bvin));

            // Banner
            if (cat.BannerImageUrl.Trim().Length > 0)
            {
                ViewBag.ShowBanner = true;
                ViewBag.BannerUrl = MerchantTribe.Commerce.Storage.DiskStorage.CategoryBannerUrl(
                                        MTApp,
                                        cat.Bvin,
                                        cat.BannerImageUrl,
                                        Request.IsSecureConnection);
            }
            else
            {
                ViewBag.ShowBanner = false;
            }

            // Record Category View
            MerchantTribe.Commerce.SessionManager.CategoryLastId = cat.Bvin;
            MTApp.CurrentRequestContext.CurrentCategory = cat;

            if (cat.TemplateName == "BV Grid") cat.TemplateName = "Grid"; // Safety Check from older versions
            string viewName = cat.TemplateName.Trim();
            return View(viewName, model);
        }