Nice!
I'd suggest that we don't call shop_amount() in this function, since that hits the server every time, and anyone removing an item from the shop would already pass shop_amount() for i. Instead, flag item_amount(), visit the URL to pull one or all, then return false if you didn't get enough, or put the difference back in if you got too many: