Jump to content

Create a PHP include inside .TPL file


Guest Web Roots

Recommended Posts

Guest EverythingWeb

It isn't possible.

You'd need to do the PHP stuff in the relevant .inc.php file and then assign it to a {TEMPLATE_VARIABLE} to use in the .tpl

Example;

If you want to include a PHP Script on the ViewProd page, you'd

include('mynewPHP.inc.php') in includes/content/viewProd.inc.tpl

call the function/or grab the content: $myNewData = myCustomFunction();

$template->assign('MY_TEMPLATE_VAL', $myNewData);

It's *along* those lines, but probably not 100% - but should give you enough to get on with :)

Link to comment
Share on other sites

Guest Brivtech

Anyone know how to include a PHP file inside a TPL for CC4?

What will the file do? Perhaps there's another way of achieving what you want to er, achieve. :)

Link to comment
Share on other sites

Guest Web Roots

Anyone know how to include a PHP file inside a TPL for CC4?

What will the file do? Perhaps there's another way of achieving what you want to er, achieve. :)

I want to insert a PHP code to be dispaly in orderFor.tpl (a ATM payment data generated by the code).

The code to be implemented:

<?php

// Include the SOAP classes

require_once('nusoap/lib/nusoap.php');

// Specify the Hi-Media client account

// Coloque o seu Login e Password da seguinte forma: $idcliente=â€ÂEXEMPLO†e

// $password="EXEMPLO"

$idcliente="EXEMPLO";

$password="EXEMPLO";

$origem="origem"; //For your reference, you can write anything you want (for further information check other Hi-Media documentation)

$valor="100.9";

$informacao="informaçao teste";

$IDUserBackoffice="-1";

// Specify the webservice information

$action='http://hm.comprafacil.pt/SIBSClick/webservice/SaveCompraToBDValor1';

//$action='http://mobileware.telemoveis.com/SIBSClick/webservice/SaveCompraToBDValor_op1';

$serverpath ='http://hm.comprafacil.pt/SIBSClick/webservice/clicksmsV4.asmx';

//http://mobileware.telemoveis.com/SIBSClickTeste/webservice/clicksmsV2.asmx;

$client = new soapclient($serverpath);

// Check for errors and output them

$err = $client->getError();

if ($err) {

echo '<p>Constructor error</p><pre>' . $err . '</pre>';

}

// Compose the SOAP message

$msg=$client->serializeEnvelope('<SaveCompraToBDValor1 xmlns="http://hm.comprafacil.pt/SIBSClick/webservice/"><origem>'.$origem.'</origem><IDCliente>'.$idcliente.'</IDCliente><password>'.$password.'</password><valor>'.$valor.'</valor><informacao>'.$informacao.'</informacao><IDUserBackoffice>'.$IDUserBackoffice.'</IDUserBackoffice></SaveCompraToBDValor1>','',array(),'document', 'literal');

// Send the SOAP message

$response = $client->send($msg,$action);

// Check for errors and output them

if ($client->fault) {

echo '<p>Fault</p><pre>';

print_r($response);

echo '</pre>';

}

// Output the SOAP query and response

echo "<p>SOAP query</p>";

echo '<pre>' . htmlspecialchars($client->request, ENT_QUOTES) . '</pre>';

echo "<p>SOAP response</p>";

echo '<pre>' . htmlspecialchars($client->response, ENT_QUOTES) . '</pre>';

// Save the SOAP response result to a variable

$result=$response['SaveCompraToBDValor1Result'];

//Save the SOAP response result values to the corresponding variables

$referencia=$response['referencia'];

$entidade=$response['entidade'];

$valorOut=$response['valorOut'];

$error=$response['error'];

//Output the SOAP response result values

echo "<p>SOAP response values</p>";

echo 'Referencia='.$referencia.'<br>';

echo 'Entidade='.$entidade.'<br>';

echo 'Valor='.$valorOut;

?>

Link to comment
Share on other sites

Guest Brivtech

Yes, follow EverythingWeb's instructions.

Instead of inserting the php in the actual TPL file, you need to insert a reference marker. When the template file is parsed, the inc.php file that relates to that template file can insert in your php script (or fetch it as an includes), which passed it into the template for display.

Once you get the hang of it, it's actually very simple.

Link to comment
Share on other sites

Guest Web Roots

I want to include a PHP to display in order.tpl. For that i need to use orderForm.inc.php because tlp can't include PHP right? How can i exact put that file in orderForm.inc.php to be displayed?

The php file ends with:

//Output the SOAP response result values

echo "<p>SOAP response values</p>";

echo 'Reference='.$ref.'<br>';

echo 'Company='.$entidade.'<br>';

echo 'Value='.$valorOut;

Rgds,

WR

Link to comment
Share on other sites

Guest EverythingWeb

include('yourPHPFile.php');

$template->assign('SOAP_REF', $ref);

$template->assign('SOAP_COMPANY', $entidade);

$template->assign('SOAP_VALUE', $valorOut);

Something along those lines - you'll need to check the includes/content/viewOrder.inc.php file to get the correct value names etc, but there should be enough there for you to figure the rest out :yeahhh:

Link to comment
Share on other sites

Guest Brivtech

... and using Will's example above, in your template file (.tpl), where you want that information to appear, you put the assigned variable name between curly brackets, so in the relevant places following the example, you'd have (with some pretend formatting thrown in):

<strong>Reference Number:</strong> {SOAP_REF}<br />

<strong>Company:</strong> {SOAP_COMPANY}<br />

<strong>Value:</strong> £{SOAP_VALUE}

Can't really be any more specific on this.

Link to comment
Share on other sites

Guest Web Roots

Until now working fine.

Now just have a problem, i need to use "Grand Total" VAR to myFile.php but i use $prod_total (i think this is the VAR) don't return any value.

The display is:

<strong>Reference Number:</strong> {SOAP_REF}<br />

<strong>Company:</strong> {SOAP_COMPANY}<br />

<strong>Value:</strong> £{SOAP_VALUE}

but {SOAP_VALUE} must came from myFile.php (Reference and company number are generated based on Value from GRAND TOTAL)

Rgds,

WR

Link to comment
Share on other sites

Guest EverythingWeb

It sounds like you need the actual cart total variable used in CubeCart, in which case, find the corresponding value being used to output it in the screen and use it.

I *think* it'll be along the lines of $basket['prod_total'] but you'll need to check.

Link to comment
Share on other sites

Guest Web Roots

I need the total price with taxes, shipping that return in Print_order_form "Grand Total"

It sounds like you need the actual cart total variable used in CubeCart, in which case, find the corresponding value being used to output it in the screen and use it.

I *think* it'll be along the lines of $basket['prod_total'] but you'll need to check.

I see what you mean. I find in cart the {VAL_CART_TOTAL} that came from VAR $grandTotal. Now the problem is pass $grandTotal to the ws.php (my php file) After the var is declared (in cart.inc.php) go to confirm.inc.php and after that i were i need because my ws.php is included in orderForm.inc.php

Rgds,

WR

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...