There are three things that affect NPC happiness - 1) how crowded they are, 2) if they like/dislike the biome they're in, 3) if they like/dislike the other NPCs near them. To get an NPC to sell a pylon you'll need them to have a net effect of 2 out of the 3 happiness criteria.
So here are some examples:
- The Merchant by himself (+1 for criteria 1 because he's not crowded) in the Forest (+1 for criteria 2 because he likes the forest) (+0 for criteria 3 because there's no one to like or dislike) will sell a forest pylon.
- The Arms Dealer with only the Nurse nearby (+1 for criteria 1 because he's not crowded) in the Jungle (+0 since he neither likes nor dislikes the jungle) (but +1 for criteria 3 because he likes the Nurse) will sell the jungle pylon. Even though his preferred biome is the desert. If he's by himself (+1 criteria 1) in the desert (+1 criteria 2) he'll sell the desert pylon.
One good tip is that in order to purchase a pylon you don't even need two NPCs - just one that likes the biome, or two that like each other and doesn't hate the biome they're in. And then once you purchase a pylon, you do need two NPCs for it to work (but they don't even have to be happy at that point).