Custom Functions after Order (ConfirmedOrder, PaymentCancel..)

Started by alanaasmaa, August 17, 2016, 13:23:53 PM

Previous topic - Next topic

alanaasmaa

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


Studio 42

Add a new paiement (or shipment in some case)plugin and don't check if it is right payment so it's always called.

alanaasmaa

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
    }

Studio 42

If i remember good it's plgVmOnPaymentResponseReceived
Check plugin/vmpaiment/standard folder for the most used trigger, all triggered function begin with "plgVm"

Milbo

This is the right trigger, when the payment providers sends something.

I think he needs plgVmOnUpdateOrderPayment
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

bma

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

Studio 42

Stupid question, have you published the plugin in Joomla ?


Studio 42

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

bma

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

Studio 42

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
     
}


}

bma

THAAAAANKS, with the right classname it works.... finally :) :D

best regards