If the intent is for the script to delete items in the store's inventory that only are there because a PC sold them, then the script may have to do more than that. Since (to my initial read) it deletes all items on the store, not just sold items from the player/
There are probably several ways to do this. Two come immediately to mind.
First, use OnStoreOpened to check when the store is first opened and make a list of the resrefs (and maybe stack sizes) of all the items in inventory. Then, write an OnStoreClosed script that runs through the store's inventory when the PC closes the store and gets rid of any items not in the original items list. The OnStoreClosed event could also be done as a heartbeat script and it could do things like delay if any PC is still in the area, etc.
Another approach would be to create a duplicate store and, every time the store is closed (or on a heartbeat, but I would hesitate to do this more often than needed, especially if it is potentially running for many stores) delete all the items from the store that the PCs interact with and then copy the items from the duplicate store over. The second approach is similar to the first, the main difference being that it uses another store to (effectively) keep the list of original items. It's potentially lest efficient than the first approach, but it might have the advantage of not allowing multiple copies of items to show up in the store (for instance when a sold item has the same resref as an original item). Whether that's something desired or not is up to the builder.