News:

Looking for documentation? Take a look on our wiki

Main Menu

How to call functions plgVmOnAddToCart

Started by fcplpl, October 19, 2021, 09:32:42 AM

Previous topic - Next topic

fcplpl

Hi,

VM 2, J2.5

This is my first plugin - Tracking code

Plugin works fine

My question is:

How do I display functions on the screen -> plgVmConfirmedOrder? How do I check if it works?

I cannot and do not know how to do it to see the result for the test version functions plgVmConfirmedOrder

Please Help Me.

My code:

defined('_JEXEC') or die('Restricted access');

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

class plgSystemEcommerceVmHomebook extends JPlugin {

function onAfterDispatch(){

$app = JFactory::getApplication();

   if ($app->getName() != 'site' ) {
      return true;
   }

function plgEcommerceHomebook(&$subject, $config)
    {
      parent::__construct($subject, $config);
      $this->_plugin = JPluginHelper::getPlugin('system', 'EcommerceVmHomebook');
      $this->_params = new JParameter($this->_plugin->params);
   }
   
$code = $this->params->get('code', '');
$affiliation = $this->params->get('affiliation', '');
$anonymization = $this->params->get('anonymization', '');

$input = JFactory::getApplication()->input;
       
$extension_name = $input->get('option', '', 'cmd');
$view = $input->get('view', '', 'cmd');
$task = $input->get('task', '', 'cmd');

if (!class_exists( 'VmConfig' )) require(JPATH_ROOT.DS.'administrator'.DS.'components'.DS.'com_virtuemart'.DS.'helpers'.DS.'config.php');
VmConfig::loadConfig();

if (!class_exists('CurrencyDisplay'))
require(JPATH_ROOT.DS.'administrator'.DS.'components'.DS.'com_virtuemart'.DS.'helpers'.DS.'currencydisplay.php');
$currency = CurrencyDisplay::getInstance();

$doc = JFactory::getDocument();

if(!$task=='confirm'){

$scripts_ga = "

!function(d,m,e,v,n,t,s){d['DomodiTrackObject'] = n;
   d[n] = window[n] || function() {(d[n].queue=d[n].queue||[]).push(arguments)},
   d[n].l = 1 * new Date(), t=m.createElement(e), s=m.getElementsByTagName(e)[0],
   t.async=1;t.src=v;s.parentNode.insertBefore(t,s)}(window,document,'script',
   'https://pixel.wp.pl/w/tr.js','dmq');
   dmq('init', '$code');
           
";

$doc->addScriptDeclaration($scripts_ga);

}

if ($extension_name == 'com_virtuemart' && 'productdetails' == $view){
       
$category_id = $input->get('virtuemart_category_id', '');
$product_id = $input->get('virtuemart_product_id', '');

if (!class_exists('CurrencyDisplay'))
require(VMPATH_ADMIN . DS . 'helpers' . DS . 'currencydisplay.php');
$currency = CurrencyDisplay::getInstance();
      
$productModel= VmModel::getModel('product');
$product = $productModel->getProduct($product_id);

$categoryModel = VmModel::getModel('category');
$category = $categoryModel->getCategory($category_id);

$product_prices = round($product->prices['salesPrice']);

if ($product->virtuemart_product_id == $product_id) {

$scripts_detail = "
dmq('track', 'ViewContent', {
content_type: 'product',
id:'$product->virtuemart_product_id',
name:'$product->product_name',
content_category:'$category->category_name',
price:$product_prices,
in_stock: true
});

";

$doc->addScriptDeclaration($scripts_detail);

}       

}

function plgVmConfirmedOrder($cart, $order) {

echo "confirm order event";
die();

}

GJC Web Design

you've got syntax errors .. unclosed functions and your

function plgVmConfirmedOrder($cart, $order) {

echo "confirm order event";
die();

}

is not inside the class

if all correct it should successfully die and display the echo when plgVmConfirmedOrder($cart, $order) is triggered
GJC Web Design
VirtueMart and Joomla Developers - php developers https://www.gjcwebdesign.com
VM4 AusPost Shipping Plugin - e-go Shipping Plugin - VM4 Postcode Shipping Plugin - Radius Shipping Plugin - VM4 NZ Post Shipping Plugin - AusPost Estimator
Samport Payment Plugin - EcomMerchant Payment Plugin - ccBill payment Plugin
VM2 Product Lock Extension - VM2 Preconfig Adresses Extension - TaxCloud USA Taxes Plugin - Virtuemart  Product Review Component
https://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation

fcplpl

.....

function plgVmConfirmedOrder($cart, $order) {

echo "confirm order event";
die();

}

}

}

I have the code corrected.

I don't know where this function should appear? Concole, VM Administrator, Log system, etc... ?

I don't know how to check. Just getting started, I want to know how to see the code for this function

GJC Web Design

just search the VM files for the function e.g. plgVmConfirmedOrder -- probably in the orders model

this is triggered when an order is confirmed either by a payment plugin or manually in admin
GJC Web Design
VirtueMart and Joomla Developers - php developers https://www.gjcwebdesign.com
VM4 AusPost Shipping Plugin - e-go Shipping Plugin - VM4 Postcode Shipping Plugin - Radius Shipping Plugin - VM4 NZ Post Shipping Plugin - AusPost Estimator
Samport Payment Plugin - EcomMerchant Payment Plugin - ccBill payment Plugin
VM2 Product Lock Extension - VM2 Preconfig Adresses Extension - TaxCloud USA Taxes Plugin - Virtuemart  Product Review Component
https://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation

fcplpl

I found in

administrator/.../models/orders.php

$returnValues = $dispatcher->trigger('plgVmConfirmedOrder', array($cart, $order));

unfortunately I don't know how I can call a function to see the result on the screen.

Please give me an example

GJC Web Design

 afaik this trigger is only enabled for payment plugins and triggered from the admin function  CreateOrderHead()

      VmConfig::importVMPlugins('vmpayment');

      $cart = VirtueMartCart::getCart();
      $returnValues = $dispatcher->trigger('plgVmConfirmedOrder', array($cart, $order));

I always use plgVmOnUpdateOrderPayment ($data,$old_order_status) for confirmed orders

I think there is a list of triggers on the forum here somewhere or just search VM for   plgVm

GJC Web Design
VirtueMart and Joomla Developers - php developers https://www.gjcwebdesign.com
VM4 AusPost Shipping Plugin - e-go Shipping Plugin - VM4 Postcode Shipping Plugin - Radius Shipping Plugin - VM4 NZ Post Shipping Plugin - AusPost Estimator
Samport Payment Plugin - EcomMerchant Payment Plugin - ccBill payment Plugin
VM2 Product Lock Extension - VM2 Preconfig Adresses Extension - TaxCloud USA Taxes Plugin - Virtuemart  Product Review Component
https://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation

fcplpl

Thank you for your help.
Everything is already working