It can be hard but the only way out is to exercise self-control. I stay out of stores unless I'm there for a specific item, buy it, and then get out.
One way to keep it in check is to write a list before going to the grocery store, or any other store, and DO NOT buy ANYTHING that is not on that list. If it isn't on my list I don't buy it. End of discussion with self.
Another way we use is that DW created a nice spreadsheet that is central to our daily financial matters. In it at the top is our income and then subtracted is the known expenses for that month such as estimated utilities, groceries, "spending cash" that we allow for things that come up like gifts or impulse spending, outstanding cc charges and the like. This is the 21st century so of course we use credit cards but we pay them off every month. When our allotted spending is spent, then spending stops for all but the most dire of emergencies, discussed below.
The same thing can be easily done with a pen and paper, that's why they call it a spreadsheet, which is what businesses used before computers. You just have to do the arithmetic by hand with a calculator.
And we always know exactly how much of that "allotted spending" is left because the spreadsheet automatically calculates it and at the bottom that number is displayed.
Of course "stuff happens" and we have an amount in savings for that. Water heater broke? Transmission fell out of the car? Roof leaking? Not a problem, that comes out of the "stuff happens" fund. But here's the key: Money comes out of there for ONLY reasons that serious. Everyone else is going to the beach and we wanna go too? Great sale on something I or DW wants? Money for that does NOT come out of that fund. Ever. It takes total agreement from both of us that it is absolutely necessary to get a nickel out of that fund. Otherwise it simply does not exist.
For example, last April it was a new central A/C and a water heater. The expense was not a problem for us because we knew they were going to go and planned on those things breaking someday. The money for that was in the "stuff happens" fund. We knew it was going to happen sure as tomorrow's sunrise. We just don't know when. And that money is being replenished bit by bit over the next couple of years because eventually and inevitably those items will need replacement again. And when they do we'll be prepared for it.
So the key thing here is to be thinking years ahead, not daily, weekly or monthly.
Financially, where do you want to be five years from now? Ten years? Twenty years? And what are you doing TODAY to make that happen?
Because that's the only way it will happen.