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

Using a Smarty tag in PHP code

 
Reply
   X-Cart forums > X-Cart 4 > Dev Questions > Changing design
 
Thread Tools Search this Thread
  #1  
Old 12-31-2010, 01:18 PM
 
MAPerformance MAPerformance is offline
 

Senior Member
  
Join Date: Dec 2005
Posts: 145
 

Default Using a Smarty tag in PHP code

Hey all,

I'm trying to implement a rating system I found that uses PHP to display the "stars" image. Here is the code I want to put in my main/product.tpl below the Buy Now and Wishlist buttons:

PHP Code:
<?php $rr->showStars("productid"); ?>

I want to use the productid because the ratings system uses an SQL database to keep track of everything and each item needs a unique identifier. Thanks in advance for any help.
__________________
www.maperformance.com

X-Cart Version: 4.4.3 Gold
Reply With Quote
  #2  
Old 01-01-2011, 05:28 AM
  rogue's Avatar 
rogue rogue is offline
 

X-Adept
  
Join Date: Apr 2007
Location: Loveland, Ohio
Posts: 770
 

Default Re: Using a Smarty tag in PHP code

I think it's more complicated than that. You have an object reference there "$rr". So that object has to be defined somewhere in the code you cut from. Then after that is resolved, there are other things you may need to do.
__________________
Richard Williams
Rogue Wave Limited

Initial Inventory Imports
Daily Inventory Updates
Daily Inventory Reports
Drop Ship Support
Order Export to Shipper/Supplier
Shopping Feeds That Work
Programming for X-Cart

richard@roguewavelimited.com
http://www.roguewavelimited.com
Reply With Quote
  #3  
Old 01-01-2011, 08:46 AM
 
Shamun Shamun is offline
 

X-Adept
  
Join Date: Jun 2009
Location: North Carolina
Posts: 841
 

Default Re: Using a Smarty tag in PHP code

Using PHP in smarty can be done like this:
Code:
{php}Your PHP code here{/php}

However using PHP within smarty is not recommended as it decreases performance and caching ability is reduced. You should instead create its own php file and then assign into smarty.


Smarty code cant be used in php.
__________________
- Shane Munroe
Reply With Quote
  #4  
Old 01-06-2011, 07:03 AM
 
Johny1 Johny1 is offline
 

Advanced Member
  
Join Date: Feb 2007
Posts: 72
 

Default Re: Using a Smarty tag in PHP code

I'm having a similar problem.

Shamum I've used the code you gave but I'm having trouble. I need to push details from Smarty tags through a PHP script when a user clicks a submit button.

The way I have it at the moment is:

Code:
{php}$strBillingAddress1 = "{/php}{$address.address}{php}";{php}

So I want the address to show up for this field, however the result I get is:

Code:
?><?php echo Array['address']['address']; ?> <?php

Where am I going wrong?

Any help is much appreciated
__________________
X-Cart Gold 4.5.4
Reply With Quote
  #5  
Old 01-11-2011, 07:25 AM
 
MAPerformance MAPerformance is offline
 

Senior Member
  
Join Date: Dec 2005
Posts: 145
 

Default Re: Using a Smarty tag in PHP code

OK, so is there a way to have smarty generate a variable equal to the productid which can then be read by the php script?

Code:
<?php echo rating_bar('SMARTY_PRODUCTID_VARIABLE_HERE','5'); ?>

In the first set of single-quotes, I want the productid (assigned by SMARTY as a variable?), the second single-quote number is how many stars show up. Or, is it possible to have the php script in this case grab the productid from the X-Cart database?
__________________
www.maperformance.com

X-Cart Version: 4.4.3 Gold
Reply With Quote
  #6  
Old 01-11-2011, 10:23 AM
 
PhilJ PhilJ is offline
 

X-Guru
  
Join Date: Nov 2002
Posts: 4,094
 

Default Re: Using a Smarty tag in PHP code

Try...

Code:
<?php $p = $this->get_template_vars('product'); $rr->showStars($p['productid']); ?>
Or...
Code:
<?php $p = $this->get_template_vars('product'); echo rating_bar($p['productid'],'5'); ?>
Or, just use this
__________________
xcartmods.co.uk
Reply With Quote

The following user thanks PhilJ for this useful post:
MAPerformance (01-28-2011)
  #7  
Old 01-28-2011, 12:13 PM
 
MAPerformance MAPerformance is offline
 

Senior Member
  
Join Date: Dec 2005
Posts: 145
 

Default Re: Using a Smarty tag in PHP code

Quote:
Originally Posted by PhilJ
Or, just use this

Thanks for the tip but I'm having issues getting to work. I've followed all instruction to a T and every time I put the code in the template to get the star rating to show up, I get these errors all over the page:
Code:
INVALID SQL: 1046 : No database selected SQL QUERY FAILURE:SELECT cdseoReplaceID AS id, cdseoUrl AS url, cdseoLinkTitle AS title FROM wcm_cdseo WHERE cdseoType = "xcmscategory" INVALID SQL: 1046 : No database selected SQL QUERY FAILURE:SELECT cdseoReplaceID AS id, cdseoUrl AS url, cdseoLinkTitle AS title FROM wcm_cdseo WHERE cdseoType = "xcmsentry"

It seems pretty obvious it's some kind of conflict with CDSEOPro, but I have no idea where to start looking to fix it.
__________________
www.maperformance.com

X-Cart Version: 4.4.3 Gold
Reply With Quote
  #8  
Old 02-09-2011, 12:27 PM
 
MAPerformance MAPerformance is offline
 

Senior Member
  
Join Date: Dec 2005
Posts: 145
 

Default Re: Using a Smarty tag in PHP code

Bump. Any have any idea about this new problem?
__________________
www.maperformance.com

X-Cart Version: 4.4.3 Gold
Reply With Quote
  #9  
Old 02-09-2011, 03:44 PM
 
geckoday geckoday is offline
 

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

Default Re: Using a Smarty tag in PHP code

Most likely the code you are calling closes the DB connection that is used by X-Cart and/or CDSEO.
__________________
Manuka Bay Company
X-Cart Version 4.0.19 [Linux]

UGG Boots and other fine sheepskin products
http://www.snowriver.com
Reply With Quote
Reply
   X-Cart forums > X-Cart 4 > Dev Questions > Changing design



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 01:43 AM.

   

 
X-Cart forums © 2001-2020