Try going in with a recipe that you plan on making as soon as you get home, then the other stuff you buy should only be the stuff you know you'll actually eat or stuff that won't go bad. Of course there's the issue of having to buy more of a product than you need for the recipe, but that's hard to avoid.
If you need advice on how to better motivate yourself to make the choices you know you should make, I'm afraid I'm wholly unqualified to help.
Yeah, either swing by the store on your way home before cooking, or just buy shelf-stable foods that won’t spoil quickly. I have a 25 pound bag of rice in my cabinet. My wife and I have been eating on it for weeks now, and it doesn’t seem to be any smaller than when I bought it. And it’s never going to go bad.