help on {php}

some php code


srand ((double) microtime( )*1000000);

$random_number = rand(500,999);



of course i can echo "$random_number

and it will show random range 500 to 999

but when i put the code in some .tpl

and using {$varX}

i got nothing.


{if $cart.payment_surcharge}<br />
	<li id="payment_surcharge_line"><br />
		<span>{$lang.payment_surcharge}:</span><br />
		<strong>{include file="common_templates/price.tpl" value=$cart.payment_surcharge span_id="payment_surcharge_value"}+{[COLOR="Red"]$varX}[/COLOR]</strong><br />
	</li><br />
	{math equation="x+y" x=$ y=$cart.payment_surcharge assign="_total"}<br />
	{/if}<br />

```<br />
<br />
in my mind, it should be show some number + some random number<br />
am i wrong?<br />
thank you



Not sure what you’re trying to accomplish, but your going to end up with a bunch of garbage for your html. If you want to add your variable to the amount returned by the price.tpl include then you should do something like:

{math equation="x+y" x=$cart.payment_surcharge y=$varX var="surcharge"}
{include file="common_templates/price.tpl" value=$surcharge span_id="payment_surcharge_value"}

Hello tbrinseth

I did like this

```php {math assign=“random” equation=‘rand(500,999)’}

{if $cart.payment_surcharge}

  • {$lang.payment_surcharge}:


  • {math equation=“x+y” x=$ y=$random assign=“_total”}

    {/if} ```

    and it show random 3 digit code right in cart or checkout

    but after place order the payment surchage only $1 in the order details. (yes i set $1 in backend)

    so the price only subtotal+ship(total) + $1 payment surcharge.

    so the random 3 digit is not in order details.

    am i miss something here?

    argghhh really confusing:confused: :confused: :confused:

    If you have no tag for a form element there’s no way your amount can be assigned to anything. It becomes display only.

    all i did was in the storefront.

    how about doing back in the admin (backend)

    is it possible to show to user the random code

    while it put the random code into the order total?

    The surcharge is part of the product_data. So if you use the ‘get_product_data’ PHP hook you can set that amount there. It will then go through to the template as the surcharge.

    But because this is random, when the item is added to the cart, the product data is going to be fetched again and a new surcharge will be applied.

    Why would you want a random surcharge anyway? Pretty hard to build a random business model.