How to fix, "Fatal error: Cannot declare class ... name is already in use"

Written by Max Milbers on .

This error is usually simpel to solve.

VirtueMart uses since Version 3.4.0 autoloading. The classes are registered in the file vmdefines. Before this was done very dirty without any extra function or class in the file VmConfig.php.

So some 3rd party developers included the vm core functions by just using.

if (!class_exists( 'VmConfig' )) require(JPATH_ROOT .'/administrator/components/com_virtuemart/helpers/config.php');

This set in earlier times the important path definitions, but now it just includes the file VmConfig and does "nothing". Since VirtueMart version 3.4.0 we must load the configuration extra.

The function itself is cached, so it does not hurt to call it another time. Any "optimsation" just makes it slower. So just add a 

VmConfig::loadConfig();

Usually this code is on top of the main file. Or in the constructor.

 

or here as best praxis

if (file_exists(JPATH_ROOT.DS.'administrator/components/com_virtuemart/helpers/config.php')) {
if (!class_exists( 'VmConfig' )) require(JPATH_ROOT .'/administrator/components/com_virtuemart/helpers/config.php');
VmConfig::loadConfig();
} else {
$app = JFactory::getApplication();
$app->enqueueMessage('Virtuemart not installed for'.get_class($this).', return','error');
return false;
}