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)
-   -   Using a Smarty tag in PHP code (https://forum.x-cart.com/showthread.php?t=57299)

MAPerformance 12-31-2010 01:18 PM

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.

rogue 01-01-2011 05:28 AM

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.

Shamun 01-01-2011 08:46 AM

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.

Johny1 01-06-2011 07:03 AM

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 :mrgreen:

MAPerformance 01-11-2011 07:25 AM

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?

PhilJ 01-11-2011 10:23 AM

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 :)

MAPerformance 01-28-2011 12:13 PM

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.

MAPerformance 02-09-2011 12:27 PM

Re: Using a Smarty tag in PHP code
 
Bump. Any have any idea about this new problem?

geckoday 02-09-2011 03:44 PM

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.


All times are GMT -8. The time now is 11:46 PM.

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