You could create boolean variables in the global singleton for each shelf + product combo, like:
shelf1_has_apples = true
shelf2_has_rice = false
And add a counter to each shelf's script so that if the inventory of a given product reaches zero, the global boolean is updated to false, like in shelf1:
if apples < 1:
Global.shelf1_has_apples = false
or in shelf2:
if rice > 0:
Global.shelf2_has_rice = true
And then when the player needs to query what shelf has apples, you can do something like this:
func what_shelf_has_apples():
if Global.shelf1_has_apples == true
print("Shelf 1 has apples!")
else:
pass
if Global.shelf2_has_apples == true
print("Shelf 2 has apples!")
else:
pass
etc.
Unless I am misunderstanding what you wanna do here!