We report on the observation of magnetic quantum ratchet effect in (Cd,Mn)Te- and CdTe-based quantum well structures with an asymmetric lateral dual grating gate superlattice subjected to an external magnetic field applied normal to the quantum well plane. A dc electric current excited by cw terahertz laser radiation shows 1/B-oscillations with an amplitude much larger as compared to the photocurrent at zero magnetic field. We show that the photocurrent is caused by the combined action of a spatially periodic in-plane potential and the spatially modulated radiation due to the near field effects of light diffraction. Magnitude and direction of the photocurrent are determined by the degree of the lateral asymmetry controlled by the variation of voltages applied to the individual gates. The observed magneto-oscillations with enhanced photocurrent amplitude result from Landau quantization and, for (Cd,Mn)Te at low temperatures, from the exchange enhanced Zeeman splitting in diluted magnetic heterostructures. Theoretical analysis, considering the magnetic quantum ratchet effect in the framework of semiclassical approach, describes quite well the experimental results.