How to sort a view so that, say, all the nodes with stock=0 come last, and not sort by stock?
You could do this if you use something like the Views php module, because that will allow you to use php code to sort by.  I know that module is currently looking for additional maintainers, I just can't think of an alternative.

Once you've enabled it, and added a php field to sort by, I'd have it return something like:

min([commerce_stock], 1);  // replace [commerce_stock] with whatever your available stock variable is.


What that code will do is return 1 (the minimum) if you have any stock more than 1, but it will return 0 if the product is all out.

So it will only return 1 (there are items) or 0 (there are none), which is exactly what you want.  Next, you can add a sort by name or whatever you want to sort these two groups further.

Let us know if it works.  I was having a bit of problems getting this rolling, since my stock variable is just returning my product ID, and I'm not sure if I'm just running slightly out-of-date modules or what.  So let us know if a similar approach works when you try it!!