Optical nonlinearity in a quantum dot–microcavity system under an external magnetic field