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

Credit card surcharge

 
Reply
   X-Cart forums > X-Cart 4 > Dev Questions > Changing design
 
Thread Tools Search this Thread
  #1  
Old 05-17-2004, 04:12 AM
 
richard_o richard_o is offline
 

Member
  
Join Date: Apr 2004
Posts: 24
 

Default Credit card surcharge

Hi,

I'm attempting to add a credit card surcharge to my shopping cart. Starting off with editing cart_totals.tpl to have another row at the bottom showing the surcharge (in the same list as the sub total, discount, shipping etc).

I've run into problems immediately, though.

Starting simple, I just want to display the value of the surcharge on screen. I want to total the values of $cart.sub_total, $cart.discount and $cart.shipping_cost, and multiply it by 0.02 (to get the 2% surcharge value).

I can't get smarty to perform the addition/multiplication by following this approach:

{assign var="surcharge" value=($cart.sub_total+$cart.discount+$cart.shippi ng_cost)*0.02 }

and then using {$surcharge} to display the value on screen.

So I've tried it with php:

{php}echo(($cart.sub_total+$cart.discount+$cart.sh ipping_cost)*0.02);{/php}

And also

{php}echo(({$cart.sub_total}+{$cart.discount}+{$ca rt.shipping_cost})*0.02);{/php}



It's all a little bit confusing as I'm quite new to these smarty templates. If anyone has any ideas, I'd be very grateful.

Many thanks,

Richard
Reply With Quote
  #2  
Old 05-17-2004, 04:50 AM
 
jeremye jeremye is offline
 

Senior Member
  
Join Date: Apr 2004
Location: Philadelphia, PA
Posts: 158
 

Default

You actually need to use the math function within Smarty to calculate this value:

Code:
{math equation="(sub_total+discount+shipping_cost)*0.02" sub_total=$cart.sub_total discount=$cart.discount shipping_cost=$cart.shipping_cost assign="surcharge" format="%.2f"}

Note how you have to reference smarty variables within the equation (sub_total=$cart.sub_total).

Notice the "assign" variable is 'surcharge'. So you can then display the surcharge in the template as {$surcharge}.

The format=%.2f will output the surcharge as "1.22" or "1.00".

NOTE: Be very careful with using the MATH function. It is very inefficient and will cause your pages to load slowly if used in multiple loops. Try to use PHP for that if this is intended for looping.

Let me know if this works or not, since I haven't actually tested this.
__________________
Jeremy
X-Cart Gold v3.4.14 [Linux/Apache]
Heavily Modded
Reply With Quote
  #3  
Old 05-17-2004, 05:23 AM
 
richard_o richard_o is offline
 

Member
  
Join Date: Apr 2004
Posts: 24
 

Default

Thanks for the reply. It *almost* works - i.e. I can use the math function with known values, but cannot use smarty variables.

For example,

{math equation="4+5"
assign="surcharge"
format="%.2f"} {$surcharge}

produces '9.00' (correctly)

but

{math equation="sub_total+4" sub_total=$cart.sub_total
assign="surcharge"
format="%.2f"} {$surcharge}

yields the following error:

Warning: Smarty error: math: parameter Array not passed as argument

I might go and have another look at the smarty web site to see if any similar problems have arisen...
Reply With Quote
  #4  
Old 05-17-2004, 05:29 AM
 
jeremye jeremye is offline
 

Senior Member
  
Join Date: Apr 2004
Location: Philadelphia, PA
Posts: 158
 

Default

If you can print out $cart.sub_total then you should be able to use it in your math equation.

If you absolutely cannot get the math function to work, the PHP code should work just as well.
__________________
Jeremy
X-Cart Gold v3.4.14 [Linux/Apache]
Heavily Modded
Reply With Quote
  #5  
Old 05-17-2004, 05:41 AM
  TelaFirma's Avatar 
TelaFirma TelaFirma is offline
 

X-Adept
  
Join Date: Nov 2002
Location: North Carolina USA
Posts: 930
 

Default Re: Credit card surcharge

Quote:
Originally Posted by richard_o
I'm attempting to add a credit card surcharge to my shopping cart.

You better be very careful in deciding to do this. Please read your Agreements with Mastercard and Visa. There are only a few cases where charging a surcharge for Mastercard are acceptable.

Please contact your Credit Card Processing Gateway and discuss this prior to doing this. There are stiff penalties associated if you are not in compliance.
Reply With Quote
  #6  
Old 05-17-2004, 05:51 AM
 
richard_o richard_o is offline
 

Member
  
Join Date: Apr 2004
Posts: 24
 

Default

Quote:
You better be very careful in deciding to do this. Please read your Agreements with Mastercard and Visa. There are only a few cases where charging a surcharge for Mastercard are acceptable.

Please contact your Credit Card Processing Gateway and discuss this prior to doing this. There are stiff penalties associated if you are not in compliance.

Excellent point. Our site is UK based, and my boss assures me that it's OK over here, so long as you state clearly that there is a surcharge.

Thanks for the warning [/quote]
Reply With Quote
  #7  
Old 05-17-2004, 05:57 AM
 
Mod King Mod King is offline
 

Senior Member
  
Join Date: May 2004
Posts: 115
 

Default

Code:
{math equation="(sub_total+discount+shipping_cost)*0.02" sub_total=$cart.sub_total discount=$cart.discount shipping_cost=$cart.shipping_cost assign="surcharge" format="%.2f"}
You need it to be of that form which was stated above.
You have to assign the variables for the math equation for smarty to use them.
[/code]
__________________
Mod King
Reply With Quote
  #8  
Old 05-17-2004, 06:17 AM
 
richard_o richard_o is offline
 

Member
  
Join Date: Apr 2004
Posts: 24
 

Default

Quote:
You need it to be of that form which was stated above.
You have to assign the variables for the math equation for smarty to use them.

Unfortunately, using the snippet below (which I agree, looks like it should work fine) doesn't.

Quote:
{math equation="(sub_total+discount+shipping_cost)*0.02"
sub_total=$cart.sub_total
discount=$cart.discount
shipping_cost=$cart.shipping_cost
assign="surcharge"
format="%.2f"}


And it gives me this error message

Quote:
Warning: Smarty error: math: parameter sub not passed as argument

A real head-scratcher...
Reply With Quote
  #9  
Old 05-17-2004, 06:34 AM
 
Mod King Mod King is offline
 

Senior Member
  
Join Date: May 2004
Posts: 115
 

Default

hmm thats strange, you could make it calculate the surcharge in php, where it calculates the sub_total etc and just pass that to smarty
as like $cart.surcharge
__________________
Mod King
Reply With Quote
  #10  
Old 05-17-2004, 06:41 AM
 
richard_o richard_o is offline
 

Member
  
Join Date: Apr 2004
Posts: 24
 

Default

All sorted now! smarty wasn't liking the underscores in the equation. Working code is:

Quote:
{math equation="(subtotal+discount+shippingcost)*0.02"
subtotal=$cart.sub_total
discount=$cart.discount
shippingcost=$cart.shipping_cost
assign="surcharge"
format="%.2f"}

Thanks for all the help, everyone!
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 05:10 AM.

   

 
X-Cart forums © 2001-2020