My DS is 22 months, and would much prefer to "walk" as well. Walking, though, means running through the aisles at top speed, unstacking and restacking (or not) the contents of shelves, etc. So, unless there are two adults, one dedicated to supervising DS and making sure he doesn't hurt himself, someone else, or damage store goods, DS goes in the cart.
I have three strategies that have worked for us.
First, on the way to the store, I will repeat, over and over and over and over, "it's just Evan and mama today, so when we get to the store, you're going to ride in the cart. We can talk and sing and laugh and have snacks while you ride. You're going to ride in the cart today, the whole time we are in the store." I find that I don't have any trouble getting him into the cart if he is expecting to be there - if I don't communicate my expectations to him, though, he wails and turns into a slippery, writhing eel when I try to get him into the cart.
Second, we have a variety of snacks throughout the store. I peel an avocado from the produce aisle and he eats part of it (like an apple). The guy at the deli always gives him a slice of turkey. They have cookies at the bakery. There is always Veggie Booty.
I interact a lot with DS. I explain to him what we are getting, ask him to help me look for it, show it to him before I put it in the basket, etc. I sing and he boogies in his seat while I dance down the aisles. If we don't need anything in a particular aisle, we "race" to the end. It takes longer this way, which seems counterproductive, but it engages DS's attention and makes it easier for him to sit for that length of time.
I've not yet had a situation where I had to leave the store. There have certainly been times when DS has expressed frustration, but usually we can continue if I take the time to help him engage with something (me, snack, etc.). If he truly lost it, though, I would definitely cash it in and leave.