Copied to clipboard

Flag this post as spam?

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


  • Lester 1 post 71 karma points
    Sep 20, 2021 @ 19:26
    Lester
    0

    Show all child products in multiple categories

    Hello,

    I've been looking at the https://try.vendr.net/ and I like what I see. It seem's like a very nice shop plugin for Umbraco, there doesn't seem to be a lot of those compared to other CMS'.

    Now I've been digging around the plugin trying to figure out how things are made and I'm wondering about something that is kinda crucial to me.

    I know my way around code but I'm not a developer.

    What I'm wondering about is showing ALL products on a category page. Let me explain:

    I have the Category page like the Vendr Demo and my structure is the following:

    Categories -> Cars -> BMW, Mercedes, ... -> 3-Serie, 4-serie, 5-serie, ... -> All cars in this model

    What I wish to accomplish:

    1. if I go to: Cars category I would like to see ALL BMW and Mercedes cars
    2. if I go to: BMW category I would like to show ALL cars in this category which is the ones in 3-4-5-serie.
    3. And if I go to the 3-Series I would get all products in this category. This one already works by default. But the two above I don't know how to accomplish

    I would greatly appreciate if someone would help me out.

  • Matt Brailsford 4124 posts 22215 karma points MVP 9x c-trib
    Sep 21, 2021 @ 08:19
    Matt Brailsford
    0

    Hi Lester,

    Sure thing. I think I'd probably suggest going via Examine, the search index that comes with Umbraco. I'd probably also suggest installing the Search Extension package by Callum Whyte to make searching a little easier https://github.com/callumbwhyte/umbraco-search-extensions but once installed you could probably do something like the following:

    if (_examineManager.TryGetIndex("ExternalIndex", out var index))
    {
        var searcher = index.GetSearcher();
        var query = searcher.CreatePublishedQuery()
            .And().NodeTypeAlias(Car.ModelTypeAlias)
            .And().Field("path", Model.Id.ToString());
        var results = query.Execute().GetResults<Car>();
        ...
    }
    

    Where Car is a Models Builder model for the car type and Model.Id is the current pages ID. So if you run that code on the Cars page it will list all cars, if you run that code on the BMW page it will list all BMW cars, etc, etc.

    Hope this helps

    Matt

  • Floyd49 1 post 71 karma points
    Sep 21, 2021 @ 12:20
    Floyd49
    0

    Hello,

    Thanks for the update and quick reply. I'll be sure to keep an eye on this thread. Looking for the same question for myloweslife.

Please Sign in or register to post replies

Write your reply to:

Draft