Follow us on Twitter X-Cart on Facebook Wiki
Shopping cart software Solutions for online shops and malls

Smarty variable to {php}{/php} section

 
Reply
   X-Cart forums > X-Cart 4 > Dev Questions > Changing design
 
Thread Tools Search this Thread
  #1  
Old 02-18-2011, 11:04 AM
 
spwestwood spwestwood is offline
 

Member
  
Join Date: Aug 2007
Posts: 17
 

Default 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,
__________________
spwestwood.
Version 4.1.9
Version 4.4
Reply With Quote
  #2  
Old 02-19-2011, 05:49 AM
 
geckoday geckoday is offline
 

X-Wizard
  
Join Date: Aug 2005
Posts: 1,073
 

Default Re: Smarty variable to {php}{/php} section

PHP Code:
{php}$variable=$this->_tpl_vars['products']['product']['extra_fields']['0']['value'];{/php
__________________
Manuka Bay Company
X-Cart Version 4.0.19 [Linux]

UGG Boots and other fine sheepskin products
http://www.snowriver.com
Reply With Quote
  #3  
Old 02-19-2011, 11:47 PM
  enterfusion's Avatar 
enterfusion enterfusion is offline
 

Advanced Member
  
Join Date: Mar 2004
Location: Pittsburg, CA
Posts: 70
 

Default 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
__________________
-Eric

X-cart 4.3.2 up and running.
Apache, PHP 5.2, APC, Redhat, Checkout One, On Sale, Smart Search, Remember Cart.
Lots of other customization's, but perhaps typical of x-cart installations.

X-cart 5 sort of in limbo, trying to make things work without much luck.
Reply With Quote
  #4  
Old 02-21-2011, 04:37 AM
 
spwestwood spwestwood is offline
 

Member
  
Join Date: Aug 2007
Posts: 17
 

Default 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.
__________________
spwestwood.
Version 4.1.9
Version 4.4
Reply With Quote
Reply
   X-Cart forums > X-Cart 4 > Dev Questions > Changing design


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -8. The time now is 10:39 AM.

   

 
X-Cart forums © 2001-2020