Urgent help needed for Order Entry project

I am creating an order entry app, similar to a shopping cart app. The objective is to remove friction from the current complicated order process.

Internal and external users order “packages” AKA bundles, kits or assemblies. My product catalog thing contains a field that is a list for sub-products so a product contains 0-to-many “sub-products”. Each sub-product has 0-to-many sub-products. Simple recursion so far. Each order has attributes; bedrooms, bathrooms and style and some of the products have a size or type attribute populated from an options set.

When an order is created I need to create a complete bill of materials (BOM) that includes the root level product for pricing then add every “sub-product” from the root product’s product list. If any of the sub-products have sub-products, I need to include those in the BOM too.

The challenge: Some of the sub-products need to be added based upon information in the order. For instance, a 2 bedroom order needs to have 2 single bedroom sub-products placed in the order details, a 1 bath order only gets 1 bathroom kit.

If that isn’t enough to make it difficult, some of the sub-products have attributes like a bedroom package has bed size, King, Queen, Twin etc.

The goal is to recursively expand a single root product into all of it’s sub-components and present the user with an expanded list where they can select the desired attributes for the items in the list that offer a choice.

The only solution that I have found so far is to use run javascript on the server. Just can’t find docs on how to return a list that I can use in an RG. I am open to changing the structure as long as I can achieve the objective. I would consider a bounty/paid solution as well.