List container - how to show all

Topics: General
Sep 16, 2011 at 2:59 PM
Edited Sep 16, 2011 at 3:00 PM

Suppose I have 2 product lists(container), there are 2 products(containable) in each list.

Now I want to show all 4 products in a single list page, how can I combine them together?

 

Cheers,

Jing

Coordinator
Sep 16, 2011 at 4:05 PM

For now, you'll have to write your own controller action. In 2.0, you'll be able to do that. Or, you could use taxonomy and tag those guys with one common term, then query on that.

Sep 17, 2011 at 11:55 AM

thank you for your suggestion, I wrote a controller action to solve the problem, here it is (don't forget the route.):

 

namespace GuoZhu.News.Controllers
{
    public class JmmjController : Controller
    {
        private readonly IContentManager _contentManager;
        private readonly ISiteService _siteService;

        public JmmjController(IContentManager contentManager, ISiteService siteService, IShapeFactory shapeFactory)
        {
            _contentManager = contentManager;
            _siteService = siteService;
            Shape = shapeFactory;
        }

        private dynamic Shape { get; set; }

        [Themed]
        public ActionResult Products(PagerParameters pagerParameters)
        {
            // all jmmj products
            IContentQuery<ContentItem> query = _contentManager
                .Query(VersionOptions.Published, "ProductPage")
                .Join<RoutePartRecord>()
                .Where(r => r.Path.StartsWith("jmmj-products"));

            // container
            var container = _contentManager.Query<RoutePart, RoutePartRecord>(VersionOptions.Published)
                .Where(r => r.Path == "jmmj-products/all")
                .List()
                .Single()
                .As<ContainerPart>();

            // sorting
            var descendingOrder = container.Record.OrderByDirection == (int) OrderByDirection.Descending;
            query = query.OrderBy(container.Record.OrderByProperty, descendingOrder);

            // pager
            var pager = new Pager(_siteService.GetSiteSettings(), pagerParameters);
            pager.PageSize = pagerParameters.PageSize != null && container.As<ContainerPart>().Record.Paginated
                                 ? pager.PageSize
                                 : container.Record.PageSize;
            var pagerShape = Shape.Pager(pager).TotalItemCount(query.Count());

            var startIndex = container.Record.Paginated ? pager.GetStartIndex() : 0;
            var pageOfItems = query.Slice(startIndex, pager.PageSize).ToList();

            // list
            var list = Shape.List();
            list.AddRange(pageOfItems.Select(item => _contentManager.BuildDisplay(item, "Summary")));
            list.Classes.Add("content-items");
            list.Classes.Add("list-items");

            var model = _contentManager.BuildDisplay(container, "Detail");
            model.Content.Add(list, "7");
            if (container.As<ContainerPart>().Record.Paginated)
            {
                model.Content.Add(pagerShape, "7.5");
            }

            return new ShapeResult(this, model);
        }
    }
}