Add sorting inventories function.