X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Changing design (https://forum.x-cart.com/forumdisplay.php?f=51)
-   -   Smarty variable to {php}{/php} section (https://forum.x-cart.com/showthread.php?t=58128)

spwestwood 02-18-2011 11:04 AM

Smarty variable to {php}{/php} section
 
Hi,

I have a quick question. I want to display an extra field value on the cart page, and then do some database lookups with that value. For this I need to access a smarty variable in a {php}{/php} section.

I got it working on an install of xcart 4.4.1. In this version I have:

Extra field value:
Code:

{$product.extra_fields.0.value}
Then in the php section:
Code:

{php}$variable=$this->_tpl_vars['product']['extra_fields']['0']['value'];{/php}

Now I want to move this over to my current install, which is 4.1.9.

Extra field value (slightly different):
Code:

{$products[product].extra_fields.0.value}.
php section:
Code:

{php} ?? {/php}

The {php} bit I did for the version 4.2 doesn't work. Does anyone know how I can do this?

Thanks,

geckoday 02-19-2011 05:49 AM

Re: Smarty variable to {php}{/php} section
 
PHP Code:

{php}$variable=$this->_tpl_vars['products']['product']['extra_fields']['0']['value'];{/php


enterfusion 02-19-2011 11:47 PM

Re: Smarty variable to {php}{/php} section
 
The recommended method is here:

// get assigned template var 'foo'
$myVar = $smarty->get_template_vars('foo');

// get all assigned template vars
$all_tpl_vars = $smarty->get_template_vars();

// take a look at them
print_r($all_tpl_vars);

http://www.smarty.net/docsv2/en/api.get.template.vars

spwestwood 02-21-2011 04:37 AM

Re: Smarty variable to {php}{/php} section
 
Thanks for all your help! With both your replies I managed to get it working.

What worked was:
Code:

{php}$variable=$this->_tpl_vars['products'][0]['extra_fields']['0']['value'];{/php} 

Annoyingly it has to have a the cart id value [0], and ['product'] didn't work. I sorted it out by having a variable which I looped:

Code:

{php}
$cartid=0;
$variable=$this->_tpl_vars['products'][$cartid]['extra_fields']['0']['value'];
$cartid=$cartid+1;
{/php} 


This is very ugly but it works. Thanks again.


All times are GMT -8. The time now is 02:08 PM.

Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.