Cool solution kerrin!
I have done something a bit like this, but simply used a calculating constant field on both sides of the relationship. Then I specified to sort in descending order by the quantity.
If I use QuantitySort::Product I get the product with the highest quantity, but I can use the same relationship to place a portal on another layout with products listed in descending order by quantity. Plus I also use the same constant calc for several other relationships.
The outcome is the same as with your method, though.