Author Topic: Add custom html to thank you page  (Read 677 times)

sandomatyas

  • Jr. Member
  • **
  • Posts: 190
Add custom html to thank you page
« on: March 08, 2018, 15:08:37 pm »
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

  • Contributing Developer
  • Sr. Member
  • *
  • Posts: 3029
  • Joomla & Virtuemart addon developper
    • Studio 42 - Virtuemart & Joomla extentions
  • VirtueMart Version: 2.6 & 3.0.x.y
Re: Add custom html to thank you page
« Reply #1 on: March 08, 2018, 21:20:08 pm »
You can add in orderdone file the text, or use a Joomla Message, if your text is not related to a product

sandomatyas

  • Jr. Member
  • **
  • Posts: 190
Re: Add custom html to thank you page
« Reply #2 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)

Studio 42

  • Contributing Developer
  • Sr. Member
  • *
  • Posts: 3029
  • Joomla & Virtuemart addon developper
    • Studio 42 - Virtuemart & Joomla extentions
  • VirtueMart Version: 2.6 & 3.0.x.y
Re: Add custom html to thank you page
« Reply #3 on: March 09, 2018, 11:43:01 am »
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

  • Virtuemart Projectleader
  • Administrator
  • Super Hero
  • *
  • Posts: 9586
  • VM3.2 Cached and Optimized
    • VM3 Extensions
  • VirtueMart Version: VirtueMart 3 on joomla 3
Re: Add custom html to thank you page
« Reply #4 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)
I should fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

sandomatyas

  • Jr. Member
  • **
  • Posts: 190
Re: Add custom html to thank you page
« Reply #5 on: March 26, 2018, 15:09:43 pm »
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

  • UK Web Developer & Consultant
  • Global Moderator
  • Super Hero
  • *
  • Posts: 26841
  • Always on vacation
    • Jenkin Hill Internet
Re: Add custom html to thank you page
« Reply #6 on: March 26, 2018, 16:02:46 pm »
Kelvyn

Jenkin Hill Internet,
Lowestoft, Suffolk, UK

Unsolicited PMs/emails will be ignored.

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

Currently using VM.3.2.15.9866 on Joomla 3.8.8 PHP 7.0.30

Testing VM.3.2.15.9866 on J3.8.8

Studio 42

  • Contributing Developer
  • Sr. Member
  • *
  • Posts: 3029
  • Joomla & Virtuemart addon developper
    • Studio 42 - Virtuemart & Joomla extentions
  • VirtueMart Version: 2.6 & 3.0.x.y
Re: Add custom html to thank you page
« Reply #7 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.

sandomatyas

  • Jr. Member
  • **
  • Posts: 190
Re: Add custom html to thank you page
« Reply #8 on: March 27, 2018, 21:38:35 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!

  • 3rd party VirtueMart Developer
  • Full Member
  • *
  • Posts: 645
  • Full-stack Web Developer
    • www.virtueplanet.com
  • VirtueMart Version: Always latest
Re: Add custom html to thank you page
« Reply #9 on: March 27, 2018, 21:58:48 pm »
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

  • Contributing Developer
  • Sr. Member
  • *
  • Posts: 3029
  • Joomla & Virtuemart addon developper
    • Studio 42 - Virtuemart & Joomla extentions
  • VirtueMart Version: 2.6 &amp; 3.0.x.y
Re: Add custom html to thank you page
« Reply #10 on: March 28, 2018, 00:33:35 am »
 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

  • Jr. Member
  • **
  • Posts: 190
Re: Add custom html to thank you page
« Reply #11 on: March 29, 2018, 13:59:07 pm »
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

  • Jr. Member
  • **
  • Posts: 190
Re: Add custom html to thank you page
« Reply #12 on: March 29, 2018, 15:45:44 pm »
A code example is something like this:
Code: [Select]
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

  • Contributing Developer
  • Sr. Member
  • *
  • Posts: 3029
  • Joomla & Virtuemart addon developper
    • Studio 42 - Virtuemart & Joomla extentions
  • VirtueMart Version: 2.6 &amp; 3.0.x.y
Re: Add custom html to thank you page
« Reply #13 on: March 29, 2018, 16:09:43 pm »
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.