VirtueMart Forum

VirtueMart 2 + 3 + 4 => Virtuemart Development and bug reports => Topic started by: alanaasmaa on August 17, 2016, 13:23:53 PM

Title: Custom Functions after Order (ConfirmedOrder, PaymentCancel..)
Post by: alanaasmaa on August 17, 2016, 13:23:53 PM
Hi,

I'm trying to figure out how to create custom virtuemart/joomla plugin that calls out custom functions.

It should call out function:
after user makes order
after user cancels order
after order payment fails
after payment is successful

and maybe others if possible, i would not like to hardcode cause then updating would be harder.


My code is like this and only first section works.
public function plgVmConfirmedOrder($cart, $order)
    {
        echo '<h1>plgVmConfirmedOrder</h1>';
        echo '<script type="text/javascript">alert("plgVmConfirmedOrder")</script>';
        // This one works
    }
    public function plgVmOnUserPaymentCancel()
    {
        echo '<h1>plgVmOnUserPaymentCancel</h1>';
        echo '<script type="text/javascript">alert("plgVmOnUserPaymentCancel")</script>';
    }
    public function plgVmOnPaymentResponseReceived()
    {
        echo '<h1>plgVmOnPaymentResponseReceived</h1>';
        echo '<script type="text/javascript">alert("plgVmOnPaymentResponseReceived")</script>';
    }
    public function plgVmOnPaymentNotification()
    {
        echo '<h1>plgVmOnPaymentNotification</h1>';
        echo '<script type="text/javascript">alert("plgVmOnPaymentNotification")</script>';
    }
    public function plgVmOnConfirmedOrderStorePaymentData()
    {
        echo '<h1>plgVmOnConfirmedOrderStorePaymentData</h1>';
        echo '<script type="text/javascript">alert("plgVmOnConfirmedOrderStorePaymentData")</script>';
    }
    public function plgVmOnDisplayProductFE()
    {
        echo "<h1>plgVmOnDisplayProductFE</h1>";
        echo '<script type="text/javascript">alert("plgVmOnDisplayProductFE")</script>';
    }
    public function plgVmOnAddToCart()
    {
        echo "<h1>plgVmOnAddToCart</h1>";
        echo '<script type="text/javascript">alert("plgVmOnAddToCart");</script>';
    }
    public function plgVmOnPaymentSelectCheck()
    {
        echo "<h1>plgVmOnPaymentSelectCheck</h1>";
        echo '<script type="text/javascript">alert("plgVmOnPaymentSelectCheck");</script>';
    }


First time virtuemart user, thanks

Title: Re: Custom Functions after Order (ConfirmedOrder, PaymentCancel..)
Post by: Studio 42 on August 17, 2016, 13:39:08 PM
Add a new paiement (or shipment in some case)plugin and don't check if it is right payment so it's always called.
Title: Re: Custom Functions after Order (ConfirmedOrder, PaymentCancel..)
Post by: alanaasmaa on August 17, 2016, 14:34:59 PM
Quote from: Studio 42 on August 17, 2016, 13:39:08 PM
Add a new paiement (or shipment in some case)plugin and don't check if it is right payment so it's always called.

Thanks, for the reply. Could you tell me whan is the right star for payment plugin cause i tried it but it didn't work.

if (!class_exists('vmCustomPlugin')) {
    require(JPATH_VM_PLUGINS . DS . 'vmcustomplugin.php');
}

class plgVmCustomKauppakanava extends vmCustomPlugin
{


EDIT: Got it working as payment plugin. Now these two functions work. But i need more. I need ATLEAST one that calls a function when payment is complete.

public function plgVmConfirmedOrder($cart, $order)
    {
        echo '<h1>plgVmConfirmedOrder</h1>';
        echo '<script type="text/javascript">alert("plgVmConfirmedOrder")</script>';
        // Vahvista tilaus
    }
    public function plgVmOnUserPaymentCancel()
    {
        echo '<h1>plgVmOnUserPaymentCancel</h1>';
        echo '<script type="text/javascript">alert("plgVmOnUserPaymentCancel")</script>';
        // Peruuta tilaus
    }
Title: Re: Custom Functions after Order (ConfirmedOrder, PaymentCancel..)
Post by: Studio 42 on August 17, 2016, 15:22:53 PM
If i remember good it's plgVmOnPaymentResponseReceived
Check plugin/vmpaiment/standard folder for the most used trigger, all triggered function begin with "plgVm"
Title: Re: Custom Functions after Order (ConfirmedOrder, PaymentCancel..)
Post by: Milbo on August 17, 2016, 23:05:00 PM
This is the right trigger, when the payment providers sends something.

I think he needs plgVmOnUpdateOrderPayment
Title: Re: Custom Functions after Order (ConfirmedOrder, PaymentCancel..)
Post by: bma on February 01, 2017, 13:58:38 PM
Hi All,

I developed an plugin in order to catch "plgVmOnUpdateOrderPayment", but will never invoked.

Herewith the code:

jimport ('joomla.plugin.plugin');

if (!class_exists('vmCustomPlugin')) {
    require(JPATH_VM_PLUGINS . DS . 'vmcustomplugin.php');
}

class plgVmcustomAfterOrderConfirmedHook extends vmCustomPlugin {
      function plgVmConfirmedOrder($cart, $order){
                      DO ACTIONS
      }
        
     function plgVmOnUpdateOrderPayment($cart, $order){
                      DO ACTIONS
     }
}


What I miss?

thanks a lot
Title: Re: Custom Functions after Order (ConfirmedOrder, PaymentCancel..)
Post by: Studio 42 on February 01, 2017, 18:25:34 PM
Stupid question, have you published the plugin in Joomla ?
Title: Re: Custom Functions after Order (ConfirmedOrder, PaymentCancel..)
Post by: bma on February 02, 2017, 07:25:32 AM
Yes, of course  8)
Title: Re: Custom Functions after Order (ConfirmedOrder, PaymentCancel..)
Post by: Studio 42 on February 02, 2017, 14:34:47 PM
The problem is perhaps here :
class plgVmcustomAfterOrderConfirmedHook extends vmCustomPlugin {

I'm not sure that vmCustom Plugins are always loaded here.
If you only call it for this 2 triggers, perhaps try to convert it to a shipment or payment plugin
Title: Re: Custom Functions after Order (ConfirmedOrder, PaymentCancel..)
Post by: bma on February 02, 2017, 14:55:02 PM
I tried also as vmPayment and as System plugins... but doesn't been invoked.

Here below the vmPayment statement:

<?php
defined 
('_JEXEC') or die('Direct Access to ' basename (__FILE__) . ' is not allowed.');

defined('DS') or define('DS'DIRECTORY_SEPARATOR);

jimport ('joomla.plugin.plugin');

if (!
class_exists ('vmPSPlugin')) {
require(JPATH_VM_PLUGINS DS 'vmpsplugin.php');
}

class 
plgVmcustomAfterOrderConfirmedHook extends vmPSPlugin {

function __construct (& $subject$config) {

parent::__construct ($subject$config);
}

      function 
plgVmConfirmedOrder($cart$order){
DO SOMETHING
         
}
    
  function plgVmOnUpdateOrderPayment($cart$order){
  
DO SOMETHING
  }
}
?>



I use VirtueMart 3.0.19.3 Blue Corvus 9439 & Joomla! 3.6 and the plugin is enable on "Extensions-Plugins" section.

Many thanks for your support
Title: Re: Custom Functions after Order (ConfirmedOrder, PaymentCancel..)
Post by: Studio 42 on February 02, 2017, 15:06:30 PM
You have to install it in the right folder and use right class name.
Main file
JOOMLAROOT\plugins\vmpayment\confirmedhook\confirmedhook.php

basic code for the file confirmedhook.php

<?php
defined 
('_JEXEC') or die();

if (!
class_exists ('vmPSPlugin')) {
require(JPATH_VM_PLUGINS DS 'vmpsplugin.php');
}

class 
plgVmPaymentConfirmedHook extends vmPSPlugin {
      function 
plgVmConfirmedOrder($cart$order){
                      
//DO ACTIONS
      
}
         
     function 
plgVmOnUpdateOrderPayment($cart$order){
                     
// DO ACTIONS
     
}


}
Title: Re: Custom Functions after Order (ConfirmedOrder, PaymentCancel..)
Post by: bma on February 02, 2017, 15:21:14 PM
THAAAAANKS, with the right classname it works.... finally :) :D

best regards