0

I have been migrating Joomla 3 to Joomla 4. There is one custom function in which I am triggering and changing order status and sending notification email to user. Functionality has been working fine in Joomla 3 but not in Joomla 4.

Below is my custom function for order status change:

    if (!class_exists( 'VmConfig' )){
       require(JPATH_ADMINISTRATOR.'/components/com_virtuemart/helpers/config.php'); 
       VmConfig::loadConfig();
    }
    $VMOrdermodel = VmModel::getModel('Orders');
    $data = array(
                'order_status' => 'X',
                'current_order_status' => 'P',
                'customer_notified' => 1,
                'customer_send_comment' => 1,
                'update_lines' => 1,
            );              
        $VMOrdermodel->updateStatusForOneOrder('order_id', $data);

Above code change order status, but I am getting an error while sending an VM Email.

    Undefined constant "Joomla\CMS\MVC\Controller\JPATH_COMPONENT"

I have updated code in my custom file as below:

    if (!defined('_JDEFINES')) {
       define('JPATH_BASE', realpath(dirname(__FILE__) . '/../../..'));
       require_once JPATH_BASE . '/includes/defines.php';
     }

      require_once JPATH_BASE . '/includes/framework.php';
      $container = \Joomla\CMS\Factory::getContainer();
      $container->alias(\Joomla\Session\SessionInterface::class, 'session.web.site');
      $app= $container->get(\Joomla\CMS\Application\SiteApplication::class);

Can someone suggest me how to resolve an issue?

Thanks!!

Ashish Patel
  • 3,551
  • 1
  • 15
  • 31

0 Answers0