not sure exactly what is in the item code, but from a logic standpoint I see:
(spoilered for space)
STACK_ITEMNAME // (that is name not ID) this would have to be dynamic otherwise every single item would need a separate def.
STACK::1 = itemid,itemname,itemdata1,itemdata2,etc… // it would be good to include a stack priority pointer which points to an
STACK::2 = see above // item data value that says “put me first if i’m most rotten” for instance.
when this may not be as desirable is when you want a specific type of [itemname], which may be ameliorated by a stack dividing option that shows substacks by item ID.