fix buy when res is undefined