A thief who stole a man’s expensive glasses and sweets from a shop in his town has been ordered to carry out unpaid work.