Create a custom hierarchical categories for vendors

Hi guys,
I have a custom table created (vendor_categories), that link to users table of modx, my question is how to create a tree look menu from my hierarchical categories table?

here’s my vendor_categories table with sample categories.

and here’s my query sample.
<?php
/Add in our package/
$base_path = !empty($base_path) ? $base_path : $modx->getOption(‘core_path’).‘components/vendors/’;
$vendors = $modx->addPackage(‘vendors’, $base_path.‘model/’);

    $output = '';
    
     $cond = $modx->newQuery('vendorCategories');
     $cond->where(array(
         'parent' => 0
        
    ));
    

    $category = $modx->getCollection('vendorCategories', $cond);
    
    //$subs = $category->getMany('Children');
  
    foreach($category as $cat) {
        
        $fields = $cat->toArray();
       
        $output .= $modx->getChunk('product-services-category', $fields);
       
        print_r('<pre class="test">');
        print_r($fields);
        print_r('</pre>');
        
    }
    
    return $output;

Any help is appreciated, Thank you ')

I think you might be able to duplicate the Wayfinder snippet and change its class key, since it produces a tree based on each object’s parent field.

You might have to alter some other parts of the code if field names like pagetitle are hard-coded into it.

You could set the rank field to sort within each level.