If you have a valid and correct prescription at hand, it is unnecessary for you to see an eye doctor before buying sunglasses, you just need to offer the prescription to the local optical stores, then they can preocess the prescription sunglasses for you. You can still place your order online, there are many online stores that offer prescription sunglasses with wide selection of fashionable frames.
If you have perfect eyesight and you see your doctor regularly, then there is no need to see him before buying sunglasses. You can just use your prescription that you ever had to get your sunglasses either at your local optical store or online. Where as, if you have eye problems, you should see your doctor before getting your sunglasses.
If you're going to buy regular non prescription sunglasses, I don't think you need to do it. However, if you need to order prescription sunglasses, you'd better see your eye doctor unless you take eye exam frequently.