Exemplo n.º 1
0
        public void Process(StringBuilder output,
                            MerchantTribe.Commerce.MerchantTribeApplication app,
                            dynamic viewBag,
                            ITagProvider tagProvider,
                            ParsedTag tag,
                            string innerContents)
        {
            MiniPagerViewModel model = new MiniPagerViewModel();

            model.TotalPages = tag.GetSafeAttributeAsInteger("totalpages");
            if (model.TotalPages >= 1)
            {
                // manual load
                model.CurrentPage = tag.GetSafeAttributeAsInteger("currentpage");
                model.PagerUrlFormat = tag.GetSafeAttribute("urlformat");
                model.PagerUrlFormatFirst = tag.GetSafeAttribute("urlformatfirst");
                if (model.CurrentPage < 1) model.CurrentPage = GetPageFromRequest(app);
            }
            else
            {
                // find everything from current category
                model = FindModelForCurrentCategory(app, viewBag, tag);
            }
            
            Render(output, model);
        }
Exemplo n.º 2
0
        public void Process(StringBuilder output,
                            MerchantTribe.Commerce.MerchantTribeApplication app,
                            dynamic viewBag,
                            ITagProvider tagProvider,
                            ParsedTag tag,
                            string innerContents)
        {
            MiniPagerViewModel model = new MiniPagerViewModel();

            model.TotalPages = tag.GetSafeAttributeAsInteger("totalpages");
            if (model.TotalPages >= 1)
            {
                // manual load
                model.CurrentPage         = tag.GetSafeAttributeAsInteger("currentpage");
                model.PagerUrlFormat      = tag.GetSafeAttribute("urlformat");
                model.PagerUrlFormatFirst = tag.GetSafeAttribute("urlformatfirst");
                if (model.CurrentPage < 1)
                {
                    model.CurrentPage = GetPageFromRequest(app);
                }
            }
            else
            {
                // find everything from current category
                model = FindModelForCurrentCategory(app, viewBag, tag);
            }

            Render(output, model);
        }
Exemplo n.º 3
0
        public void Process(StringBuilder output,
            MerchantTribe.Commerce.MerchantTribeApplication app,
            dynamic viewBag,
            ITagProvider tagProvider,
            ParsedTag tag,
            string innerContents)
        {
            PagerViewModel model = new PagerViewModel();
            //model.TotalPages = tag.GetSafeAttributeAsInteger("totalpages");
            model.TotalItems = tag.GetSafeAttributeAsInteger("totalitems");
            model.PageSize = tag.GetSafeAttributeAsInteger("pagesize");
            if (model.PageSize < 1) model.PageSize = 1;
            model.CurrentPage = tag.GetSafeAttributeAsInteger("currentpage");
            model.PagerUrlFormat = tag.GetSafeAttribute("urlformat");
            model.PagerUrlFormatFirst = tag.GetSafeAttribute("urlformatfirst");

            Render(output, model);
        }
Exemplo n.º 4
0
        public void Process(StringBuilder output,
                            MerchantTribe.Commerce.MerchantTribeApplication app,
                            dynamic viewBag,
                            ITagProvider tagProvider,
                            ParsedTag tag,
                            string innerContents)
        {
            var profiler = MiniProfiler.Current;

            var model = new List <SingleCategoryViewModel>();

            int columns = tag.GetSafeAttributeAsInteger("columns");

            if (columns < 1)
            {
                columns = 3;
            }

            string source = tag.GetSafeAttribute("source");

            switch (source.Trim().ToLowerInvariant())
            {
            case "manual":
                string        manualBvins = tag.GetSafeAttribute("categories");
                List <string> bvins       = manualBvins.Split(',').ToList();
                model = PrepSubCategories(app.CatalogServices.Categories.FindManySnapshots(bvins), app);
                break;

            default:
                using (profiler.Step("Pull Products for Category"))
                {
                    var cat = app.CurrentRequestContext.CurrentCategory;


                    string categoryId = tag.GetSafeAttribute("categories");
                    using (profiler.Step("Checking for non-current category on grid"))
                    {
                        if (categoryId.Trim().Length < 1 || categoryId.Trim().ToLowerInvariant() == "current")
                        {
                            if (app.CurrentRequestContext.CurrentCategory != null)
                            {
                                categoryId = app.CurrentRequestContext.CurrentCategory.Bvin;
                                cat        = app.CatalogServices.Categories.Find(categoryId);
                            }
                        }
                    }

                    model = PrepSubCategories(app.CatalogServices.Categories.FindVisibleChildren(cat.Bvin), app);
                }
                break;
            }

            Render(output, app, viewBag, model, columns);
        }
Exemplo n.º 5
0
        public void Process(StringBuilder output,
                            MerchantTribe.Commerce.MerchantTribeApplication app,
                            dynamic viewBag,
                            ITagProvider tagProvider,
                            ParsedTag tag,
                            string innerContents)
        {
            PagerViewModel model = new PagerViewModel();

            //model.TotalPages = tag.GetSafeAttributeAsInteger("totalpages");
            model.TotalItems = tag.GetSafeAttributeAsInteger("totalitems");
            model.PageSize   = tag.GetSafeAttributeAsInteger("pagesize");
            if (model.PageSize < 1)
            {
                model.PageSize = 1;
            }
            model.CurrentPage         = tag.GetSafeAttributeAsInteger("currentpage");
            model.PagerUrlFormat      = tag.GetSafeAttribute("urlformat");
            model.PagerUrlFormatFirst = tag.GetSafeAttribute("urlformatfirst");

            Render(output, model);
        }
Exemplo n.º 6
0
        public void Process(StringBuilder output,
                            MerchantTribe.Commerce.MerchantTribeApplication app,
                            dynamic viewBag,
                            ITagProvider tagProvider,
                            ParsedTag tag,
                            string innerContents)
        {
            var profiler = MiniProfiler.Current;
                        
            var model = new List<SingleCategoryViewModel>();

            int columns = tag.GetSafeAttributeAsInteger("columns");
            if (columns < 1) columns = 3;                
            
            string source = tag.GetSafeAttribute("source");
            switch (source.Trim().ToLowerInvariant())
            {
                case "manual":
                    string manualBvins = tag.GetSafeAttribute("categories");
                    List<string> bvins = manualBvins.Split(',').ToList();
                    model = PrepSubCategories(app.CatalogServices.Categories.FindManySnapshots(bvins), app);                    
                    break;
                default:
                    using (profiler.Step("Pull Products for Category"))
                    {
                        var cat = app.CurrentRequestContext.CurrentCategory;
                        

                        string categoryId = tag.GetSafeAttribute("categories");
                        using (profiler.Step("Checking for non-current category on grid"))
                        {
                            if (categoryId.Trim().Length < 1 || categoryId.Trim().ToLowerInvariant() == "current")
                            {
                                if (app.CurrentRequestContext.CurrentCategory != null)
                                {
                                    categoryId = app.CurrentRequestContext.CurrentCategory.Bvin;
                                    cat = app.CatalogServices.Categories.Find(categoryId);
                                }
                            }
                        }

                        model = PrepSubCategories(app.CatalogServices.Categories.FindVisibleChildren(cat.Bvin), app);                                            
                    }
                    break;
            }

            Render(output, app, viewBag, model, columns);
        }
Exemplo n.º 7
0
        private MiniPagerViewModel FindModelForCurrentCategory(MerchantTribe.Commerce.MerchantTribeApplication app, dynamic viewBag, ParsedTag tag)
        {
            MiniPagerViewModel model = new MiniPagerViewModel();

            // get the current category
            var cat = app.CurrentRequestContext.CurrentCategory;

            if (cat == null)
            {
                return(model);
            }


            model.CurrentPage = GetPageFromRequest(app);
            int currentPageForCount = model.CurrentPage;

            if (model.CurrentPage == WebAppSettings.ViewAllPagesConstant)
            {
                // View All Requested
                model.TotalPages = 1;
            }
            else
            {
                // View by Pages Requested, calculate how many we have
                int pageSize = tag.GetSafeAttributeAsInteger("pagesize");
                if (pageSize < 1)
                {
                    pageSize = 9;
                }

                // Get Count of items in category, ignore pages because we just want the count
                int totalItems = 0;
                app.CatalogServices.FindProductForCategoryWithSort(cat.Bvin, MerchantTribe.Commerce.Catalog.CategorySortOrder.ManualOrder, false,
                                                                   1, 1, ref totalItems);
                model.TotalPages = MerchantTribe.Web.Paging.TotalPages(totalItems, pageSize);
            }

            model.PagerUrlFormat = UrlRewriter.BuildUrlForCategory(new CategorySnapshot(cat),
                                                                   app.CurrentRequestContext.RoutingContext,
                                                                   "{0}");
            model.PagerUrlFormatFirst = UrlRewriter.BuildUrlForCategory(new CategorySnapshot(cat),
                                                                        app.CurrentRequestContext.RoutingContext);
            return(model);
        }
        public void Process(StringBuilder output,
                            MerchantTribe.Commerce.MerchantTribeApplication app,
                            dynamic viewBag,
                            ITagProvider tagProvider,
                            ParsedTag tag,
                            string innerContents)
        {
            var profiler = MiniProfiler.Current;

            bool showPagers = false;
            int  columns    = 3;
            var  model      = new ProductListViewModel();

            using (profiler.Step("Attribute Gathering"))
            {
                model.PagerData.PageSize = tag.GetSafeAttributeAsInteger("pagesize");
                if (model.PagerData.PageSize < 1)
                {
                    model.PagerData.PageSize = 9;
                }

                columns = tag.GetSafeAttributeAsInteger("columns");
                if (columns < 1)
                {
                    columns = 3;
                }

                if (tag.GetSafeAttribute("page") == "all")
                {
                    model.PagerData.CurrentPage = WebAppSettings.ViewAllPagesConstant;
                }
                else
                {
                    model.PagerData.CurrentPage = tag.GetSafeAttributeAsInteger("page");
                }
                if (model.PagerData.CurrentPage < 1 && model.PagerData.CurrentPage != WebAppSettings.ViewAllPagesConstant)
                {
                    model.PagerData.CurrentPage = GetPageFromRequest(app);
                }

                model.PagerData.TotalItems = 0;

                showPagers = tag.GetSafeAttributeAsBoolean("showpager");
            }

            string source = tag.GetSafeAttribute("source");

            switch (source.Trim().ToLowerInvariant())
            {
            case "featured":
                model.Items = app.CatalogServices.Products.FindFeatured(1, model.PagerData.PageSize);
                showPagers  = false;
                break;

            case "manual":
                string        manualProducts = tag.GetSafeAttribute("products");
                List <string> bvins          = manualProducts.Split(',').ToList();
                model.Items = app.CatalogServices.Products.FindMany(bvins);

                string        manualSkus = tag.GetSafeAttribute("skus");
                List <string> skus       = manualSkus.Split(',').ToList();
                model.Items.AddRange(app.CatalogServices.Products.FindManySkus(skus));

                showPagers = false;
                break;

            default:
                using (profiler.Step("Pull Products for Category"))
                {
                    var    cat        = app.CurrentRequestContext.CurrentCategory;
                    string categoryId = tag.GetSafeAttribute("categoryid");
                    using (profiler.Step("Checking for non-current category on grid"))
                    {
                        if (categoryId.Trim().Length < 1 || categoryId.Trim().ToLowerInvariant() == "current")
                        {
                            if (app.CurrentRequestContext.CurrentCategory != null)
                            {
                                categoryId = app.CurrentRequestContext.CurrentCategory.Bvin;
                                cat        = app.CatalogServices.Categories.Find(categoryId);
                            }
                        }
                    }

                    using (profiler.Step("Build Data for Render"))
                    {
                        int totalItems = 0;
                        using (profiler.Step("Get the Products"))
                        {
                            // View All Support
                            if (model.PagerData.CurrentPage == WebAppSettings.ViewAllPagesConstant)
                            {
                                model.PagerData.CurrentPage = 1;
                                model.PagerData.PageSize    = 250;  // int.MaxValue; - Use a reasonable limit here instead of max int.
                            }

                            model.Items = app.CatalogServices.FindProductForCategoryWithSort(
                                categoryId,
                                CategorySortOrder.ManualOrder,
                                false,
                                model.PagerData.CurrentPage, model.PagerData.PageSize, ref totalItems);

                            model.PagerData.TotalItems = totalItems;
                        }
                        using (profiler.Step("Build the Pager Urls"))
                        {
                            model.PagerData.PagerUrlFormat = UrlRewriter.BuildUrlForCategory(new CategorySnapshot(cat),
                                                                                             app.CurrentRequestContext.RoutingContext,
                                                                                             "{0}");
                            model.PagerData.PagerUrlFormatFirst = UrlRewriter.BuildUrlForCategory(new CategorySnapshot(cat),
                                                                                                  app.CurrentRequestContext.RoutingContext);
                        }
                    }
                }
                break;
            }

            Render(output, app, viewBag, model, showPagers, columns);
        }
        public void Process(StringBuilder output,
                            MerchantTribe.Commerce.MerchantTribeApplication app,
                            dynamic viewBag,
                            ITagProvider tagProvider,
                            ParsedTag tag,
                            string innerContents)
        {
            var profiler = MiniProfiler.Current;

            bool showPagers = false;
            int columns = 3;
            var model = new ProductListViewModel();

            using (profiler.Step("Attribute Gathering"))
            {
                model.PagerData.PageSize = tag.GetSafeAttributeAsInteger("pagesize");
                if (model.PagerData.PageSize < 1) model.PagerData.PageSize = 9;

                columns = tag.GetSafeAttributeAsInteger("columns");
                if (columns < 1) columns = 3;

                if (tag.GetSafeAttribute("page") == "all")
                {
                    model.PagerData.CurrentPage = WebAppSettings.ViewAllPagesConstant;
                }
                else
                {
                    model.PagerData.CurrentPage = tag.GetSafeAttributeAsInteger("page");
                }
                if (model.PagerData.CurrentPage < 1 && model.PagerData.CurrentPage != WebAppSettings.ViewAllPagesConstant)
                {
                    model.PagerData.CurrentPage = GetPageFromRequest(app);
                }

                model.PagerData.TotalItems = 0;

                showPagers = tag.GetSafeAttributeAsBoolean("showpager");
            }

            string source = tag.GetSafeAttribute("source");
            switch (source.Trim().ToLowerInvariant())
            {
                case "featured":
                    model.Items = app.CatalogServices.Products.FindFeatured(1, model.PagerData.PageSize);
                    showPagers = false;
                    break;
                case "manual":
                    string manualProducts = tag.GetSafeAttribute("products");
                    List<string> bvins = manualProducts.Split(',').ToList();
                    model.Items = app.CatalogServices.Products.FindMany(bvins);

                    string manualSkus = tag.GetSafeAttribute("skus");
                    List<string> skus = manualSkus.Split(',').ToList();
                    model.Items.AddRange(app.CatalogServices.Products.FindManySkus(skus));

                    showPagers = false;
                    break;
                default:
                    using (profiler.Step("Pull Products for Category"))
                    {
                        var cat = app.CurrentRequestContext.CurrentCategory;
                        string categoryId = tag.GetSafeAttribute("categoryid");
                        using (profiler.Step("Checking for non-current category on grid"))
                        {
                            if (categoryId.Trim().Length < 1 || categoryId.Trim().ToLowerInvariant() == "current")
                            {
                                if (app.CurrentRequestContext.CurrentCategory != null)
                                {
                                    categoryId = app.CurrentRequestContext.CurrentCategory.Bvin;
                                    cat = app.CatalogServices.Categories.Find(categoryId);
                                }
                            }
                        }

                        using (profiler.Step("Build Data for Render"))
                        {
                            int totalItems = 0;
                            using (profiler.Step("Get the Products"))
                            {
                                
                                // View All Support
                                if (model.PagerData.CurrentPage == WebAppSettings.ViewAllPagesConstant)
                                {
                                    model.PagerData.CurrentPage = 1;
                                    model.PagerData.PageSize = 250; // int.MaxValue; - Use a reasonable limit here instead of max int.
                                }
                                
                                model.Items = app.CatalogServices.FindProductForCategoryWithSort(
                                                       categoryId,
                                                       CategorySortOrder.ManualOrder,
                                                       false,
                                                       model.PagerData.CurrentPage, model.PagerData.PageSize, ref totalItems);
                                
                                model.PagerData.TotalItems = totalItems;
                            }
                            using (profiler.Step("Build the Pager Urls"))
                            {
                                model.PagerData.PagerUrlFormat = UrlRewriter.BuildUrlForCategory(new CategorySnapshot(cat),
                                                        app.CurrentRequestContext.RoutingContext,
                                                        "{0}");
                                model.PagerData.PagerUrlFormatFirst = UrlRewriter.BuildUrlForCategory(new CategorySnapshot(cat),
                                                        app.CurrentRequestContext.RoutingContext);
                            }
                        }
                    }
                    break;
            }

            Render(output, app, viewBag, model, showPagers, columns);
        }
Exemplo n.º 10
0
        private MiniPagerViewModel FindModelForCurrentCategory(MerchantTribe.Commerce.MerchantTribeApplication app, dynamic viewBag, ParsedTag tag)
        {
            MiniPagerViewModel model = new MiniPagerViewModel();

            // get the current category
            var cat = app.CurrentRequestContext.CurrentCategory;
            if (cat == null) return model;

                        
            model.CurrentPage = GetPageFromRequest(app);
            int currentPageForCount = model.CurrentPage;

            if (model.CurrentPage == WebAppSettings.ViewAllPagesConstant)
            {
                // View All Requested
                model.TotalPages = 1;
            }
            else
            {
                // View by Pages Requested, calculate how many we have
                int pageSize = tag.GetSafeAttributeAsInteger("pagesize");
                if (pageSize < 1) pageSize = 9;

                // Get Count of items in category, ignore pages because we just want the count
                int totalItems = 0;
                app.CatalogServices.FindProductForCategoryWithSort(cat.Bvin, MerchantTribe.Commerce.Catalog.CategorySortOrder.ManualOrder, false,
                                        1, 1, ref totalItems);
                model.TotalPages = MerchantTribe.Web.Paging.TotalPages(totalItems, pageSize);
            }

            model.PagerUrlFormat = UrlRewriter.BuildUrlForCategory(new CategorySnapshot(cat),
                                        app.CurrentRequestContext.RoutingContext,
                                        "{0}");
            model.PagerUrlFormatFirst = UrlRewriter.BuildUrlForCategory(new CategorySnapshot(cat),
                                    app.CurrentRequestContext.RoutingContext);
            return model;
        }