TO WHOEVER INVENTED THE OPEN OFFICE, I'D JUST LIKE TO SAY: >:-(
It's not that the idea is totally without merit, but it is certainly more than usually prone to chaos, and too many open office perpetrators fail to put in place the tools and practices that could make them successful. For those of us who work best without constant interruption (I would argue, that's everybody) it can be incredibly disruptive to be surrounded by other people's phone calls, quick chats, and general grabass. And then there are those people who insist on walking up to you several times a day with a "quick question," not realizing that they've just derailed your entire thought process and negated your last half hour of work.
Now, I'm not here to advocate for outlawing fun—or even obnoxious people. I genuinely enjoy being able to see and easily chat with my coworkers from all departments. But I recognize that my "easy chat" is a neighbor's "I'M TRYING TO CONCENTRATE," so it's important to offer people an opt-out. This can be as simple as allowing people to work from home if they're feeling vulnerable or need to concentrate (honestly, people should probably be given that option anyway). It's even better to provide sound-proof phone-use zones, for taking calls, and quiet, unassigned offices where anybody can go to get away from the general hubbub when and if they need to. You should probably have at least one of these small offices available per every 4 or 5 employees to make sure everybody's getting the quiet time they need. Unfortunately, most open offices don't provide us those sorts of zones, so we'll look at a few things you can personally do to reclaim a little privacy and discourage wanton barging.
Hopefully your organization already uses one (if not, they need to get with the times). It helps if there is an office-wide understanding, but even if there's not, you can encourage people to reach out to you via chat instead of physically marching up on your desk. Alternately, you can ask them to email you, if that's your thing.
Don't waste time with those subtle, in-ear, is-that-a-headphone-or-just-a-shadow style pips; no, those only solve a fraction of the problem (also, do those actually stay in anyone's ears? Not mine). Go for the full-on, obvious, over-ear, these-also-prevent-frostbite-in-extreme-climates ones. Not only will they block/mask more sound, they'll also make it obvious to your coworkers that you are, in fact, working (SHOCKER), and not just sitting there, waiting for somebody to come talk to you. If you can afford them, it's worth getting noise-canceling ones, for your own peace of mind—"Seriously, who keeps putting on Weird Al Radio?!"
Something subtle, like desk-mounted acoustic panels can create an illusion of privacy which provides a nice placebo effect for you, and, if you're lucky, they might even make the droppers-by feel a little more like intruders. They also provide a good place to tack some pictures of kittens (or of your children, if you’re into that), conceal that collection of not-quite-empty coffee mugs you’ve been working on for the past three weeks, and even serve the greater good by absorbing ambient office noise. Everybody wins! Level 2 of the barrier method involves hobbyhorses, and should only be used in extreme cases.
Don't be a jerk (good rule of thumb), but you shouldn't be afraid to ask people to respect your needs. It's okay to encourage people not to walk up on you. Let them know they can schedule time with you if they need to talk in person, but that chat is their friend for quick questions. If they need to give you a lot of detail, or time is not sensitive, an email is a good alternative. And everyone should be discouraged from first sending an email, and then chatting you to tell you about the email, and then immediately walking over to followup on their email. That is terrible for everyone's productivity.
Now, I don’t want to give you the wrong impression about my coworkers; the ones reading this are lovely.* But that’s the point: it doesn’t matter how much you like the people around you, they can still be distracting. It’s not even their fault! On the contrary, it’s to be expected and, to a point, even encouraged. People have to collaborate, and ask questions, and point out the person in a t-rex costume outside the window, and that’s why it’s important to equip yourself to create your own sanctuary, when you need it.
Maintain those boundaries,
*Honestly, all of my coworkers are fantastic, and nobody should take this personally.