I don't think this question can be fully answered, so I'll just list out some possibilities, as well as some evidence for and against.
First Possibility: Law actually swapped not only their brains, but a lot of their internals as well. Sanji in Nami's body claims to be the best swimmer on the crew and thus he has to be the one to rescue the samurai's torso from the sea. But why does Sanji still have his abilities while in Nami's body? It might make sense if Law swapped the internals of the bodies, including muscles.
Where this theory seems to fail: Franky and Chopper's bodies seem to work as normal. Also, when Sanji and Nami swap back, Sanji feels the pain his body went through under Nami after she punches him, saying "My body hurts from a whole lot more than one punch." If the injuries were only skin deep, he likely wouldn't collapse from the pain here.
Second Possibility: Law actually did swap their souls. And somehow, in the world of One Piece, skills and memory are stored in the soul, thus why Sanji still has fighting potential while in Nami's body. And maybe the soul really is stored in the physical heart (Who's to say in a fictional world? Whether it was the actual heart is not important, however, and as previously stated, the physical representation of the swap did not look like a real heart.). And what else is stored in the soul? The urge to smoke, apparently.
Where this theory is weak: If the characters still have access to the actual brain of the body they're in, and thus the memories and knowledge, this would be odd, as they don't appear to have much idea of how to use their abilities. Nami in Franky's body seems particularly inept.
Third Possibility: Law swapped their brains. It is very plausible that the urge to smoke would carry over, then, along with all their memories. Though as to why Sanji retains some physical prowess, there would seem to be no good answer.
The second and third possibilities likely are more credible, as Sanji does struggle a bit in Nami's body, saying at times he can't keep up,etc. But at the same time, he's clearly got too much physical prowess while in Nami's body, so something is definitely off. It could possibly be a combination of the second and third as well.