I’m surprised, your site works as desired, if you really call the_post
for the button. This function does not echo the post’s ID, it simply fetches the next post of the current query.
If I understood you correctly (and I’m not so sure about that), you only want to get the current post’s ID so you can work with it, right?
All you need to do is call the_ID();
wherever you want to output the ID. If you want to pass it to a function or in some way want to work with the data, use get_the_ID();
instead.
In your case, this would be:
<a href="#" onclick="amzn_onsitecartAdd('<?php the_ID(); ?>');" ...