News:

Looking for documentation? Take a look on our wiki

Main Menu

vDispatcher::trigger dont work with system plugins from Joomla

Started by vdweb.cz, May 08, 2024, 18:21:03 PM

Previous topic - Next topic

vdweb.cz

Hi,
J: ‎4.4.4
VM: 4.2.8 11000


Plugins from folder plugins/system/* dont work with trigers

for example my plugin in J3 and VM 3.8 use this trigger function plgVmConfirmedOrder:

class plgSystemVD_matomo extends JPlugin {
function plgVmConfirmedOrder($cart, $order) {
//do something



in file:
components/com_virtuemart/helpers/cart.php
you have this:
$returnValues = vDispatcher::trigger('plgVmConfirmedOrder', array(&$this, $orderDetails));


but joomla J4 need system plugin triggers name start with "on"
soo if i want use plgVmConfirmedOrder in my plugin
correct name for this trigger must be: onplgVmConfirmedOrder

After that
you mast replace
$returnValues = vDispatcher::trigger('onplgVmConfirmedOrder', array(&$this, $orderDetails));

and in plugin use this
class plgSystemVD_matomo extends JPlugin {
function onplgVmConfirmedOrder($cart, $order) {
//do something


And after that triggers are called


Do you know about this incompatibility with Joomla?


Sorry for my english ;-)

Ghost

You should either extend vmPlugin or manually register listeners in your plugin.

vdweb.cz

Hi, but joomla plugin dont handle this triger plgVmConfirmedOrder

because in J4 trigers must start with "on" plgVmConfirmedOrder -> onplgVmConfirmedOrder


But this is about Virtuemart developers to fix that and rename all names:



They use this trigger in:
administrator/components/com_virtuemart/helpers/vdispatcher.php

static function trigger ($name, $params){

if(self::$dispatcher === null){
if(JVM_VERSION<4){
self::$dispatcher = JEventDispatcher::getInstance();
} else {
self::$dispatcher = JFactory::getApplication();
}
}

if(JVM_VERSION<4){
return self::$dispatcher->trigger($name, $params);
} else {
return self::$dispatcher->triggerEvent($name, $params);
}
}


$dispatcher->triggerEvent($name, $params); is valid php in J4 but problem is in name plgVmConfirmedOrder joomla dont start this triger withou prefix "on"

Do you understand?

Ghost

VM devs can't just change event names because that would break all existing plugins. Furthermore, events don't have to start with "on". You just need to register the listeners yourself or extend vmPlugin which already handles this.

AH

The work to register vm triggers is already completed

There is no need to change the names to start with "on"
Regards
A

Joomla 4.4.5
php 8.1

Milbo

Ghost, thank you for your answers, because you just wrote mainly the reasons. The force to use "on" is not really cool. but they just want to prevent that any function is registered as listener. Excluding any function startin with _ would have been more usefull, I think.

vdweb.cz just check the vmPlugin how we register the functions there.
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

vdweb.cz

Guys, i dont understand what:
"register listeners in your plugin"
or
"extend vmPlugin"


I have clasic joomla system plugin:
class plgSystemVD_matomo extends JPlugin {

and for this plugin i have listener plgVmConfirmedOrder:

class plgSystemVD_matomo extends JPlugin {
   function plgVmConfirmedOrder($cart, $order) {
      //do something

But joomla dont run this listener.

I speak about plugins from folder plugins/system/*
My plugin is in here: plugins/system/vd_matomo

Jumbo!

Quote from: vdweb.cz on May 13, 2024, 11:58:01 AMGuys, i dont understand what:
"register listeners in your plugin"
or
"extend vmPlugin"


I have clasic joomla system plugin:
class plgSystemVD_matomo extends JPlugin {

and for this plugin i have listener plgVmConfirmedOrder:

class plgSystemVD_matomo extends JPlugin {
   function plgVmConfirmedOrder($cart, $order) {
      //do something

But joomla dont run this listener.

I speak about plugins from folder plugins/system/*
My plugin is in here: plugins/system/vd_matomo

You need to register custom events in the constructor if you want to use them in a system plugin.

Example:
<?php

defined
('_JEXEC') or die;

class 
PlgSystemVD_matomo extends JPlugin {
  public function 
__construct(&$subject$config)
  {
    
parent::__construct($subject$config);

    
// For Joomla 4 and Joomla 5
    
if (version_compare(JVERSION'4.0.0''ge')) {
      
$this->registerLegacyListener('plgVmConfirmedOrder');
    }
  }

  public function 
plgVmConfirmedOrder($cart$order)
  {
    
// Do whatever you want
  
}
}

vdweb.cz

Jumbo! thank you soo much thats what i need...
Big thanks for your help and your fantastic VP One Page Checkout ;-)

Quote from: Jumbo! on May 13, 2024, 13:47:08 PM....