Knowing what is likely to trigger a tantrum (in the store) and avoiding it can help. For example, if you know you'll be pushing him in the carriage past that candy rack on the way out; give him something to be busy with just before you get to the rack. If having someone in front of you in line means you'll be standing by the candy rack longer than a two-year-old can (before wanting something), hang back until the person ahead leaves room for you to push him past the candy rack very quickly). (Explain to anyone behind you what you're doing. Standing a couple of feet farther back temporarily isn't going to slow anyone down.) If it isn't the candy rack that's likely to get him going, it may be the cereal aisle (with pictures on boxes that appeal to kids). Think of which foods might "get him going" and keep the carriage near less appealing stuff.
Generally, try to give him something that will keep him entertained and engrossed through the whole trip. He'll be happy for most of the time, which may help him be a little better with a minor frustration on the trip. Give him something like Cheerios (small, time-consuming, food pieces) to add to whatever toy/entertainment/book you give him. Something he doesn't have all the time can seem more interesting and fun than his "usual, old, favorite, truck".
Try to make the trip a really positive, "special time", with him. Talk to him, tell him where you'll be going next and what "we'll be doing next". Two-year-olds don't like surprises.
Other than that, talk (in a friendly way) to him before going into the store. Tell him the plans and what will and won't be bought/done. Give him a choice of what snack/little treat he may like to get, and mention it throughout the trip (so he has something to look forward to).
While he's still happy (beforehand) tell him that "the people in the store can't have people screaming and crying because the workers can't concentrate on their work." He may/may not understand, but eventually he will.
Some of these ideas may help, but if he ends up having a tantrum, leave your cart at the desk and do what you did - bring him outside "until he's ready to go in "and start over".