Ejemplo n.º 1
0
        protected override void Render(StringBuilder sb, 
                            MerchantTribeApplication app, 
                            dynamic viewBag, 
                            ProductListViewModel model, 
                            bool showPagers, int columns)
        {
            var profiler = MiniProfiler.Current;
            using (profiler.Step("Rendering Grid..."))
            {
                var preppedItems = PrepProducts(model.Items, columns, app);
                var pagerRenderer = new code.TemplateEngine.TagHandlers.Pager();
                var productRenderer = new code.TemplateEngine.TagHandlers.SingleProduct();

                if (showPagers == true)
                {
                    pagerRenderer.Render(sb, model.PagerData);                    
                }
                foreach (var item in preppedItems)
                {
                    productRenderer.RenderModel(sb, item, app);
                }
                if (showPagers == true)
                {
                    pagerRenderer.Render(sb, model.PagerData);                    
                }
            }
        }
Ejemplo n.º 2
0
        protected override void Render(StringBuilder sb,
                            MerchantTribeApplication app,
                            dynamic viewBag,
                            ProductListViewModel model,
                            bool showPagers, int columns)
        {
            var profiler = MiniProfiler.Current;
            using (profiler.Step("Rendering Detailed List..."))
            {
                var preppedItems = base.PrepProducts(model.Items, columns, app);
                var pagerRenderer = new code.TemplateEngine.TagHandlers.Pager();

                string buttonUrlDetails = app.ThemeManager().ButtonUrl("View", app.IsCurrentRequestSecure());
                string buttonUrlAddToCart = app.ThemeManager().ButtonUrl("AddToCart", app.IsCurrentRequestSecure());

                if (showPagers == true)
                {
                    pagerRenderer.Render(sb, model.PagerData);
                }
                foreach (var item in preppedItems)
                {
                    RenderSingleModel(sb, item, app, buttonUrlDetails, buttonUrlAddToCart);
                }
                if (showPagers == true)
                {
                    pagerRenderer.Render(sb, model.PagerData);
                }
            }
        }
        //
        // GET: /ContentBlocks/LastProductsViewed/
        public ActionResult Index(ContentBlock block)
        {
            ProductListViewModel model = new ProductListViewModel();
            model.Title = SiteTerms.GetTerm(SiteTermIds.RecentlyViewedItems);
            model.Items = LoadItems();

            return View(model);
        }
 public string Render(MerchantTribe.Commerce.MerchantTribeApplication app, dynamic viewBag, MerchantTribe.Commerce.Content.ContentBlock block)
 {
     ProductListViewModel model = new ProductListViewModel();
     model.Title = SiteTerms.GetTerm(SiteTermIds.RecentlyViewedItems);
     model.Items = LoadItems(app);
     
     return RenderModel(model, app);
 }
Ejemplo n.º 5
0
        protected override void Render(StringBuilder sb,
                            MerchantTribeApplication app,
                            dynamic viewBag,
                            ProductListViewModel model,
                            bool showPagers, int columns)
        {
            var profiler = MiniProfiler.Current;
            using (profiler.Step("Rendering Bulk Order List..."))
            {
                var preppedItems = base.PrepProducts(model.Items, columns, app);
                var pagerRenderer = new code.TemplateEngine.TagHandlers.Pager();

                if (showPagers == true)
                {
                    pagerRenderer.Render(sb, model.PagerData);
                }
                
                if (showPagers == true)
                {
                    pagerRenderer.Render(sb, model.PagerData);
                }

                                
                sb.Append("<form action=\"" + app.CurrentRequestContext.UrlHelper.Content("~/cart/bulkadd") + "\" method=\"post\">");
                sb.Append("<table width=\"100%\">");
                foreach (var item in preppedItems)
                {                    
                    sb.Append("<tr>");
                    sb.Append("<td class=\"checkbox\">");
                    if (item.Item.HasOptions())
                    {
                        sb.Append("&nbsp;");
                    }
                    else
                    {
                        sb.Append("<input type=\"checkbox\" name=\"bulkitem\" value=\"" + item.Item.Bvin + "\" />");
                    }
                    sb.Append("</td>");
                    sb.Append("<td class=\"records\">");
                    RenderSingleModel(sb, item, app);                            
                    sb.Append("</td>");
                    sb.Append("</tr>");              
                } 
                sb.Append("</table>");

                string buttonUrlAddToCart = app.ThemeManager().ButtonUrl("AddToCart", app.IsCurrentRequestSecure());
                sb.Append("<input type=\"image\" name=\"addtocart\" src=\"" + buttonUrlAddToCart + "\" alt=\"Add To Cart\" />");
                sb.Append("</form>");

            }
        }
        public string RenderModel(ProductListViewModel model, MerchantTribeApplication app)
        {
            StringBuilder sb = new StringBuilder();            

            var productRenderer = new code.TemplateEngine.TagHandlers.SingleProduct();

            sb.Append("<div class=\"productgrid\">");    
            sb.Append("<div class=\"decoratedblock\">");
            sb.Append("<h4>" + HttpUtility.HtmlEncode(model.Title) + "</h4>");
            foreach (var p in model.Items)
            {
                sb.Append(productRenderer.RenderToString(p, app));
            }
            sb.Append("<div class=\"clear\"></div>");
            sb.Append("</div>");
            sb.Append("</div>");
            
            return sb.ToString();
        }
        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);
        }
 protected abstract void Render(StringBuilder sb,
                     MerchantTribeApplication app,
                     dynamic viewBag,
                     ProductListViewModel model,
                     bool showPagers, int columns);