News:

Looking for documentation? Take a look on our wiki

Main Menu

Add custom html to thank you page

Started by sandomatyas, March 08, 2018, 15:08:37 PM

Previous topic - Next topic

sandomatyas

I need to add some custom tracking data to the thank you page of VM but without overriding the layout. So I created a vmCustom plugin and implemented function plgVmConfirmedOrder ($cart, $order), created the data but as far as I can see it must be sent with this code:
vRequest::setVar ('html', $html);
The $html variable contains the data which I need, I doublechecked, but I can't get it on the page, I think the vmpayment plugin overrides the output with another vRequest::setVar ('html', $html);
Is it possible to append some custom data with vmcustom plugin to the outpout which is generated by other plugins?
Or what is the correct way to do that?

Studio 42

You can add in orderdone file the text, or use a Joomla Message, if your text is not related to a product

sandomatyas

I need to create the plguin as a template-independent solution, so I don't want to use any template override.
It isn't a simple message, it's a javascript snippet + a noscript alternative which is generated by the plugin based on the order details (hash, etc)

Studio 42

I never had to do that, but a shipment plugin only having render for order done should work, simply do not check if it's the right plugin.
Because you dont explain what you want to render, it's hard to help you more.

Milbo

Please work with the new core. I did some changes there (download at least vm3.2.13)
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

sandomatyas

Quote from: Milbo on March 14, 2018, 09:11:20 AM
Please work with the new core. I did some changes there (download at least vm3.2.13)

what was changed?

Studio 42:
There is a PHP class which I need to use for the cart items. I create and object, add the order items, customer data, create a custom hash, etc. The class converts the wole data to a javascript code and returns as a string. I need to embed this javascript code to the thank you page, so when the browser loads the page it can be fired.

jenkinhill

Kelvyn
Lowestoft, Suffolk, UK

Retired from forum life November 2023

Please mention your VirtueMart, Joomla and PHP versions when asking a question in this forum

Studio 42

sandomatyas, for the javascript, yo can add custom header
$document = JFactory::getDocument();
$document->addCustomTag($anycode);
To inject the HTML, you can write a Joomla system plugin to add content to component but you need to add the Virtuemart dependencies, plgVmConfirmedOrder call the system plugin too, because they are always loaded.

sandomatyas

Quote from: Studio 42 on March 26, 2018, 17:44:37 PM
sandomatyas, for the javascript, yo can add custom header
$document = JFactory::getDocument();
$document->addCustomTag($anycode);
To inject the HTML, you can write a Joomla system plugin to add content to component but you need to add the Virtuemart dependencies, plgVmConfirmedOrder call the system plugin too, because they are always loaded.

The class generates a whole package, with <script></script> and <noscript> tags too, so I can't add it to the header :/

Jumbo!

Quote from: sandomatyas on March 09, 2018, 09:15:51 AM
I need to create the plguin as a template-independent solution, so I don't want to use any template override.
It isn't a simple message, it's a javascript snippet + a noscript alternative which is generated by the plugin based on the order details (hash, etc)

You should check VP Conversion Tracking plugin - https://www.virtueplanet.com/extensions/vp-conversion-tracking It does not exact same thing for you. You can add custom html to the thank you page layout, before closing the bottom of the body tag and also in the head section using this plugin.

Studio 42

 Joomla system plugin have other trigger, so you can add your code.
See https://docs.joomla.org/Plugin/Events/System
onBeforeRender
$document=JResponse::getBody();
// add your code to $document
JResponse::setBody($document);
Of Joomla 3 https://api.joomla.org/cms-2.5/classes/JApplicationWeb.html
JApplicationWeb::getBody, appendBody,setBody ...

sandomatyas

Hm, I thought it should be easier. Adding any dynamic tracking data to thank you page (google analytics, adwords, facebook,  any custom data provider etc) maybe isn't a unique request :)
Anyway, there is an other site which needs the same feature, but it's a Joomla 2.5 and VM 2.6.14 so I decided to override order_done.php but I can't get the order details or even virtuemart_order_id

sandomatyas

A code example is something like this:

require_once 'myTrackingClass.php';
$tracker = new myTrackingClass($userId, $userPassword, $accessToken);
$tracker->setCustomerEmail($customerEmail);
foreach($cartItems as $item)
{
$tracker->addCartItem($item->sku, $item->quantity, $item->price) ;
}

$tracker->createToken();

echo $html = $tracker->getHtmlOutput();


$html variable contains a <script> tag with javascript and a <noscript> version of that. This is what I need to embed to the thank you page.

Studio 42

See for eg.https://www.phpweb.info/joomla/virtuemart-3-code-track-order-transaction-google-analytic, it's the simplest solution(some codes are stupid, but you have all you need).
You can override orderdone in your template.

If you want do a plugin, then you have to check my explain for Joomla system plugin or find another trick yourself.