Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Liam Dilley 153 posts 379 karma points
    May 28, 2018 @ 06:22
    Liam Dilley
    0

    Listing Paginated Products in Category

    Hi All, I am still fairly new to Umbraco and stepping into Merchello.

    I am having issues with understanding the Category view and display products within it.

    • In Merchello you have a category in the shop which can show multiple collections.
    • I have used fastrack and it basically has the concept of the following:

      @foreach (var product in Model.Products)

    Which seems to only ever render 10 products and has no pagination knowledge or anything.

    I have seen the various forum posts which indicate things like ProductContentQuery but I am struggling to put it together.

    If I have the following in my category view:

    var productQuery = merchelloHelper.ProductContentQuery().Page(CurrentPage).ItemsPerPage(PageSize);

    This will always render all products. So I am trying to work out how I render all products that are in the category. I could get all collection Keys and do a constrain based on those keys? But how do I get those keys?

    I am probably missing something obvious so please call me a noob but hopefully someone can point me into the right direction?

  • Liam Dilley 153 posts 379 karma points
    Jun 01, 2018 @ 02:32
    Liam Dilley
    0

    Not sure why no one would know but I managed to work things out.

    A category and the layout from Fastrack will work fine but the "All Products" will and has a permanent limit of 10 items.

    When you access @Model.Products as well it does not have the tools to properly form pagination as you may want a eCommerce site.

    SO:

    The main parts for the solution to this were:

    var productQuery = merchelloHelper.ProductContentQuery().Page(CurrentPage).ItemsPerPage(PageSize).ConstrainByCollectionKey(Model.Products.CollectionKey);
    

    This will setup a paged product output for the category based on the collectionKey. You would have parameters for your page size and current page based on a URL parameter.

    To get a total count of items you could use @Model.Products.Count() but I do not trust it or find info on the limit that may have total.

        var totalCount = merchelloHelper.ProductContentQuery().ItemsPerPage(999999).ConstrainByCollectionKey(Model.Products.CollectionKey);
    

    This may not be pretty but this can be used to get the total count to use for the pagination.

    The trick is with the "Shop all". If you make a Category that displays all the shop using the default collection provided by Merchello it does not have a collection key and will only show 10 products with Model.Products as mentioned earlier. I have set a simple if for the Model.Name for my "Shop All" and there set the values differently in this case:

    productQuery = merchelloHelper.ProductContentQuery().ItemsPerPage(PageSize).Page(CurrentPage);
    totalCount = merchelloHelper.ProductContentQuery().ItemsPerPage(999999);
    

    From here I been able to effectively build paginated product catalogues for a store and they render quite quickly.

Please Sign in or register to post replies

Write your reply to:

Draft