But how do you stop buying ice cream?

Fill your freezer with frozen food other than ice cream.

You buy your groceries while that piece of your brain has no excuse to make loud demands ;-)

Eat your dinner before going to the shop.

Also, doing high-effort endurance exercise for long enough suppresses grelin production (the hunger hormone). I've seen 30+ minutes of running or 60+ minutes of cycling as the most common rules of thumb.

So in order to stack all these effects to maximum effect: plan exercise before meal, plan mean before doing groceries.