My dd has gone on almost every grocery shopping trip I have ever made and this is what I have always done (by the way, before she turned 2 I actually rarely went grocery shopping b/c I lived with my Mom, who did the shopping, so dd got her first real lesson in it at age 2-but we did a lot of other shopping where I let her run).
At that age, I would try to keep her as entertained as possible- toys/snacks,etc. If she really wanted to get down, I would tell her that she had to hold the shopping cart and if she let go she would have to get back in the cart. Then I would remind her once or twice (but no more), and follow thru with her getting back in the cart. As long as I could keep her contaiend there, I would continue shopping while she threw a fit. If she got out of hand (say, kicking me or climbing out), I would leave the store and put her straight in her car seat with a little talk about why we left. Oh, I forgot a *vital* part of this- bribery! Before we ever stepped foot in the store I would give her The Deal. If she is a good listener, she can ride the quarter horse on the way out (or pick a toy or whatever works for you). I think bribery is a great tool if you use it *before* they start acting up. So, it's more a "motivator". We shop at Bi-Lo a lot, so I would also remind her of the train we get to see when we get in and any other fun things she likes to see, like the lobster tank or whatever. This way, she is a bit siked about going in. Also, we round up samples (even the cake/junk ones) as we go.
If possible, try to break shopping into smaller trips, like go twice a week instead of once a week. Try all the positive stuff, and then hold your ground.
Another idea (which I ended up instituting), is to just not let him out of the cart at all. I found this useful b/c my dd was also a runner and hated hated hated the cart, and would not ride in any type of carrier (started at 12 mths, then around 18 mths I started working on her holding hands with me and at about 2 started insisting on cart-riding).
This is getting really long, sorry!
My dd is going on 4 now and still rides in the cart unless I only need a couple of things.
She is an excellent shopping companion and I actually don't bribe her most of the time. Also, I keep the bribe the same almost always-riding the quarter horse.
I say this is one where you have to endure some tantrums at first b/c he realizes this is a way for him to get to run around. It's much better for him to deal with staying in the cart (or nearby, if he can control himself), than it is for him to be yelled at and end up with a frustrated Mommy!
Good luck on it. It is not easy in the beginning to re-do the old way (running). I learned first hand with this also!
Sara