@lola212121 - I raised three energetic boys - ensuring good behaviour is a constant process, and you have to be consistent. Say No and mean it. If you threaten a sanction, carry through on it, despite tantrums. Be prepared to do the same thing over and over again, until the lesson is learned - if you try something and it doesn't work, don't give up. Have rewards for good behaviour too - if they walk nicely by the trolley, and are helpful going round the shop, they get a treat - I know the sugar police will faint, but a little packet of sweets to eat on the way home will not kill them.
Bringing up children is constant work - you have to keep reminding them of what you expect of them, and making sure they are doing it.
If I was really struggling with my children's behaviour at the supermarket, I'd do the bulk of the shopping online, for a few weeks, so I could do some really short, practice trips - for half a dozen, inessential treat items. I'd tell the children that I expected them to stay by the trolley/with me, and that, if they did, we'd be coming away with icecreams or cake - but that, if they didn't do as they were told, we would leave immediately, and there would be NO treats. And I would carry through on the threat, if, after a warning, they did not behave.
I would do that as many times as it took, for the lesson to sink in.
Sadly, the longer you leave it to try to teach them how to behave in public, the harder it will be, and the more times you will have to teach the lesson before they learn it.