First important rule "any plugin can be triggered by ANY trigger !"

Lets take as example the captcha trigger onInit. Before we execute a trigger, we use usually an import for the plugin family. For example import all plugins which belong to vmpayments. It creates the idea, that just the plugins of the familiy vmpayment are triggered. But in fact all plugins are triggered, which are already imported and have a function with the called name. The import before does not magically say to the trigger "activate now only plugins of the family X".

We had a lot problems due different sorting of plugin calls. Sometimes a payment plugin was loaded before a custom plugin and vice versa. So the vDispatcher got the function:

    static function importVMPlugins($ptype){

        static $types = array('vmextended'=>TRUE,'vmuserfield'=>TRUE, 'vmcalculation'=>TRUE, 'vmcustom'=>TRUE, 'vmcoupon'=>TRUE, 'vmshipment'=>TRUE, 'vmpayment'=>TRUE);
        if(!isset($types[$ptype])) return;

        foreach($types as $type => $v){
            //vmStartTimer('importPlugins');
            JPluginHelper::importPlugin($type);
            unset($types[$type]);
            //vmTime('time to import plugins '.$type,'importPlugins');
            if($type == $ptype){
                break;
            }
        }
    }

It ensures, that if you load one family, the others are loaded in correct order. This functions ensures that a payment plugin is not loaded without a calulation plugin before. Imagine the payment plugin sends a price, which is changed by the calculation plugin later. Actually, that could not happen in praxis, but it is a good theoretical example, why it is important to load the plugin families in the right order. The function is very performant, any loaded family is removed from the list, so calling that command multiple times just results in a short return. The joomla importPlugin function does not check, if it was already called for the family. So just adding this function enhanced the performance despite flawed code due adding unnecessary imports.

The directTrigger

It sounds rather silly to fire all plugins of a family when you already know which plugin you want to use. For example in Joomla it would be the captcha plugin already selected in the config. Or in our case, very obvious the payment plugins. So VirtueMart has the direct Triggers, which enable only the selected plugin and fire the function. This is also one of the technics to increase the VirtueMart speed.