They always do know how to push our buttons with the best/worst timing, don't they? :)
I think there are things to do to prevent this situation.
(I have no idea what age your child is, so modify as necessary)
Can you give him a role to play in the outing like carrying the shopping list, counting the money, checking off the list, etc?
Is the trip appropriately lengthy for his age?
Do you give him limited choices like which store to go to first or which restaurant or which toothbrush to buy, etc?
Are your expectations of what "being good" looks like realistic and age-appropriate?
Are your expectations that he can ask what he doesn't understand age-appropriate?
Have you communicated clearly the plan for the day, ie "Today we need to buy groceries and then shoes for daddy."
I think it is important for kids not to feel like they're just being dragged along. Inviting them to participate in the activity can both alleviate this kind of scenario, and be an opportunity for practicing sorting, letter and number recognition, sequencing, etc.
When I teach parenting classes, one of the activities is a role-play of this exact scenario that allows parents to experience it from the perspective of the toddler! Being dragged along is no fun for anyone, even in a role-play scenario. Often the parents have an "aha!" moment when they next experience what it's like to have the above techniques applied, and they find that even in the role play they are much more 'compliant' and happy to participate!
I'm not advocating that every outing be about comforting the child, but I am suggesting to consider his experience of the same scenario. You may find yourself in this scenario a lot less if you do.