It depends massively on the table, the character, the item, the group, the DM, and the campaign
When starting a new game, most DMs allow players to use their starting wealth more-or-less as they see fit, just adding items to their character sheet. Whatever adventures or purchases resulted in owning those items are a part of the character’s history, which may or may not be explicitly described in the character’s backstory (though I’ve never met a DM who expected a backstory to include how every single item was obtained).
It is entirely possible to imagine exceptions here: a quick one-on-one roleplay of the purchasing experience(s), starting with nothing and finding or buying those items as a part of an introductory session, and so on. The DM may disallow certain items to be bought, require other certain items to be carried (IDs, uniforms, insignia, macguffens, whatever), and so on in infinite variation.
Adding additional items is more varied.
Many DMs will allow items to be bought off-screen between sessions if it would be appropriate. For example, say a session ends with the group returning to the big city from the dungeon with treasure. The players may be allowed to deduct gold pieces and add items to their character sheet for the next session, to represent what they’ve bought with their share of the loot. This is particularly common for higher-level characters making commonplace purchases (cloaks of resistance, belts of giant strength, and so on).
Other games, groups, DMs, or what have you will expect you to roleplay out the buying experience. Skills will be employed to find someone selling it, to estimate its value, to haggle over its price, and so on. In my experience, this tends to be more common with newer games; the group wants to see how the characters go about this process. As the campaign develops and moves on, this process becomes more routine and not worth the time, though I am sure that many groups still continue to do it even after they’ve done it a hundred times before.
In still more games, finding magic items for sale at all is rare, and almost all magic items are directly found in dungeons, or players have to go on specific sidequests in order to get them. Characters are only occasionally, or rarely, given the opportunity to specify what items they want to get.
All of these are in-character situations, and all valid
These descriptions are all about what the character has to do for items, whether that be to just buy a stock-standard item off-the-shelf for some standardized (by the book) price, all of which is just handwaved between sessions, or the character has to find and haggle down the price, or the character can’t find the item in a store and has to embark on a side-quest, or there isn’t even a side-quest and the character has to just accept what he finds in his adventures. Those are all a part of the story, and all valid stories to tell, but they all reflect the reality in-character.
Out of character, though, it is important to the functioning of the system that characters get more-or-less the items they want or need more-or-less when they could afford them
The system simply works terribly when this condition is not met. It is an important quality that a DM understands this, and works with players at tailoring the in-character experience of finding magic items to the out-of-character reality that certain items are necessary to meet the simple expectations and assumptions of the system.
Thus, even if it is impossible for a character to buy, or even do a side-quest for, a specific item, that doesn’t mean he shouldn’t get that specific item – it means that the DM should include the item somewhere down the line as part of the loot the players find. If it is just reality, in-character, that a person cannot simply expect a certain item, out-of-character the reality is that the player can and should expect certain items.
The DM obviously doesn’t have to give the player everything he or she wants as soon as he or she wants it. Mixing things up, making people work for it, and so on, add to the variety of the game and make the players’ efforts more rewarding. But the system still has to work, and it won’t if characters go too long without appropriate items.