Gotta admit... this looks pretty good as a prototype. ChatGPT didn't know that metafields are not actually exposed to the Script Editor, and it didn't know that price is not a float... but when I told it these things it made a champion effort to overcome the problems.