You put items in a sack: they keep their individual qualities
You stack the items: they all get a new "in-the-middle" quality.
Why?
When stacking, you say "rat eye x 10". So you can't keep track of individual qualities.
If items are differently named, they can't stack.
Is that realistic?
No.
Should you care?
No.
Because, as Nikodemus says, stacks are OOC. You don't really have a "pile of rat eyes" when you stack 10 of them. It's only to make stuff easier for us.
You can't have stacks with different quality items or differently named items, because that would beat the point of stacks.
The only problem is the autostacking, which should be disabled on trade. A newly bought weapon should not immediately be stacked with another lower-quality weapon of the same kind to prevent the issue that Garile describes.
Current workarounds: place items in sacks before trade and/or equip valuable weapons.