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

berghoff

Hi,
I have a following code to generate xml price:

<?php

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', 'session.web.site')
->alias('session', 'session.web.site')
->alias('JSession', 'session.web.site')
->alias(\Joomla\CMS\Session\Session::class, 'session.web.site')
->alias(\Joomla\Session\Session::class, 'session.web.site')
->alias(\Joomla\Session\SessionInterface::class, 'session.web.site');
$app = $container->get(\Joomla\CMS\Application\SiteApplication::class);

\Joomla\CMS\Factory::$application = $app;
var_dump($app);
$app->createExtensionNamespaceMap();

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

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:

ClassNotFoundError
HTTP 500 Whoops, looks like something went wrong.
Attempted to load class "JFactory" from the global namespace.
Did you forget a "use" statement?
Symfony\Component\ErrorHandler\Error\
ClassNotFoundError
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

berghoff

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

berghoff

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