Attempted to load class "JFactory" from the global namespace. Joomla 5

Started by berghoff, March 31, 2024, 17:27:23 PM

Previous topic - Next topic


I have a following code to generate xml price:


define('_JEXEC', 1);
if (!defined('_JDEFINES'))
require_once JPATH_BASE . '/includes/defines.php';
require_once JPATH_BASE . '/includes/framework.php';

use \Joomla\CMS\Factory;

$container = \Joomla\CMS\Factory::getContainer();
$container->alias('session.web', '')
->alias('session', '')
->alias('JSession', '')
->alias(\Joomla\CMS\Session\Session::class, '')
->alias(\Joomla\Session\Session::class, '')
->alias(\Joomla\Session\SessionInterface::class, '');
$app = $container->get(\Joomla\CMS\Application\SiteApplication::class);

\Joomla\CMS\Factory::$application = $app;

require(JPATH_BASE .'/administrator/components/com_virtuemart/helpers/config.php');

and it was working fine until I did update to Joomla 5.0.3 from 4.4.3 (virtuemart 4.2.6)
now I get the following error:

HTTP 500 Whoops, looks like something went wrong.
Attempted to load class "JFactory" from the global namespace.
Did you forget a "use" statement?
in /administrator/components/com_virtuemart/helpers/config.php (line 363)

if(!$defined){            JLoader::register('vmDefines', JPATH_ROOT.'/administrator/components/com_virtuemart/helpers/vmdefines.php');//In WP, we run the define, when we render vm, in Joomla we have to run them here            if(defined('JVERSION')){                VmDefines::defines(JFactory::getApplication()->getName());                require_once(VMPATH_ADMIN .'/helpers/vmecho.php');            }            $defined = true;        }

please help me fix my script


As far as I understand,

Virtuemart works only in backward capability with Joomla 5
all the project should be updated
for example JFactory:: should be replaced with \Joomla\CMS\Factory:: etc
so no chance to expect it soon?

I am using backward capability plugin that replaces all this stuff, but, for some reason, it does not work on my extension.

If I use $app->execute() everything starts to work but it is not the solution

Please help me to fix this one


OK, finally. I solved it myself by adding reference to plugins/behaviour/compat/src/classmap/classmap.php