SimpleCart categories as Wayfinder menu tree = problem

I have a small problem with building up a Wayfinder menu of SimpleCart product categories.
It all works fine except that if a product-resource is clicked to open its detail page, Wayfinder always renders the current category as a folder in Wayfinder tree if we are in first tree level.

Here is the Wayfinder call:

[[Wayfinder?
    &startId=`[[++shop_categories_startid]]`
    &level=`2`
    &rowIdPrefix=`cat-`
    &outerTpl=`ShopCategoriesOuterContainerChunk`
    &parentRowTpl=`ShopCategoriesParentRowChunk`
    &activeParentRowTpl=`ShopCategoriesParentRowActiveChunk`
    &innerTpl=`ShopCategoriesInnerContainerChunk`
    &rowTpl=`ShopCategoriesRowChunk`
    &hereTpl=`ShopCategoriesRowActiveChunk`
    &where=`[{"class_key:=":"scCategoryResource"}]`
]]

This is the rendered tree in its initial state! please have a look at “Feste Fette” - its now rendered correctly with &rowTpl, as it has no sub-categories:

If I now click on “Feste Fette” and then on a product to get to its detail-page the “Feste Fette” menu is rendered like this, using the & parentRowTpl:

I think I know whats the problem but don’t have a solution:

If I change the isfolder setting of the “Feste Fette” category to false, the rendering is correct.
But this setting isn’t static. It automatically changes to true if I create a new product inside this category.

As SimpleCart has a special parent child relation (scCategoryResources + scProductResources), WayFinder decides that the category has child elements and renders as a folder.

Any hint on how to solve this?

Seems to be a flaw in Wayfinder:

If I change line 298 in wayfinder.class.php from:

} elseif ($resource['isfolder'] && $this->_templates['activeParentRowTpl'] && ($resource['level'] < $this->_config['level'] || $this->_config['level'] == 0) && $this->isHere($resource['id'])) {

to:

} elseif ($resource['isfolder'] && $this->_templates['activeParentRowTpl'] && ($resource['level'] < $this->_config['level'] || $this->_config['level'] == 0) && $this->isHere($resource['id']) && $numChildren) {

it works like expected! At least in my environment.

With the change, Wayfinder doesn’t only check if isfolder = true, it also checks if the resource has childrens available (&& $numChildren) for rendering in the Wayfinder output.
Without the fix, Wayfinder will always determine a menu-item as folder (or parent menu item) even if it has no child items available for output.

Can anyone confirm this? If it works how I think, I’ll submit a pull-request to Wayfinder GitHub repo.

Does it make a difference by chance if you change that to this?

&where=`{"class_key:=":"scCategoryResource"}`

I have checked this and it makes no difference. The &where filter is working in both variants. But Wayfinder uses the wrong chunk.
Applying my Wayfinder fix and it is working again.

Wayfinder shouldn’t render a menu-item as “folder” (or parent item), if there are no child resources included in output.
As SimpleCart products are hidden in the category structure, Wayfinder should respect this.