cart.php 3.58KB
2 downloads
Code For Adding Tax Total To My Php Shopping Cart
Started by smallc28, Nov 18 2012 12:43 PM
6 replies to this topic
#1
Posted 18 November 2012 - 12:43 PM
#2
Posted 18 November 2012 - 08:36 PM
Do not expect to get very much help from this community by attaching the PHP file. Our community is full of people who are weary to download a file from a complete stranger mainly for security breech reasons. That could easily be an executable whose extension is changed.
Especially since you are absolutely new here.
Post the code (within code tags please), and rephrase your question to be more clear
Especially since you are absolutely new here.
Post the code (within code tags please), and rephrase your question to be more clear
#3
Posted 18 November 2012 - 08:49 PM
Sorry about my last post a bit new to this site 
What I'm trying to figure out is how can I add Total Tax.Total Including Tax: to my shopping cart.
What I'm trying to figure out is how can I add Total Tax.Total Including Tax: to my shopping cart.
<?php
$cartOutput = "";
$cartTotal = "";
$pp_checkout_btn = '';
$product_id_array = '';
if (!isset($_SESSION["cart_array"]) || count($_SESSION["cart_array"]) < 1) {
$cartOutput = "<h2 align='center'>Your shopping cart is empty</h2>";
} else {
// Start PayPal Checkout Button
$pp_checkout_btn .= '<form action="[url="https://www.paypal.com/cgi-bin/webscr"]https://www.paypal.c...cgi-bin/webscr"[/url] method="post">
<input type="hidden" name="cmd" value="_cart">
<input type="hidden" name="upload" value="1">
<input type="hidden" name="business" value="you@youremail.com">';
// Start the For Each loop
$i = 0;
foreach ($_SESSION["cart_array"] as $each_item) {
$item_id = $each_item['item_id'];
$sql = mysql_query("SELECT * FROM products WHERE id='$item_id' LIMIT 1");
while ($row = mysql_fetch_array($sql)) {
$product_name = $row["product_name"];
$price = $row["price"];
$details = $row["details"];
$tax = $row["tax"];
}
$pricetotal = $price * $each_item['quantity'];
$cartTotal = $pricetotal + $cartTotal;
setlocale(LC_MONETARY, "en_US");
$pricetotal = money_format("%10.2n", $pricetotal);
// Dynamic Checkout Btn Assembly
$x = $i + 1;
$pp_checkout_btn .= '<input type="hidden" name="item_name_' . $x . '" value="' . $product_name . '">
<input type="hidden" name="amount_' . $x . '" value="' . $price . '">
<input type="hidden" name="quantity_' . $x . '" value="' . $each_item['quantity'] . '"> ';
// Create the product array variable
$product_id_array .= "$item_id-".$each_item['quantity'].",";
// Dynamic table row assembly
$cartOutput .= "<tr>";
$cartOutput .= '<td><a href="product.php?id=' . $item_id . '">' . $product_name . '</a><br /><img src="inventory_images/' . $item_id . '.jpg" alt="' . $product_name. '" width="40" height="52" border="1" /></td>';
$cartOutput .= '<td>' . $details . '</td>';
$cartOutput .= '<td>$' . $price . '</td>';
$cartOutput .= '<td><form action="cart.php" method="post">
<input name="quantity" type="text" value="' . $each_item['quantity'] . '" size="1" maxlength="2" />
<input name="adjustBtn' . $item_id . '" type="submit" value="change" />
<input name="item_to_adjust" type="hidden" value="' . $item_id . '" />
</form></td>';
//$cartOutput .= '<td>' . $each_item['quantity'] . '</td>';
$cartOutput .= '<td>' . $pricetotal . '</td>';
$cartOutput .= '<td><form action="cart.php" method="post"><input name="deleteBtn' . $item_id . '" type="submit" value="X" /><input name="index_to_remove" type="hidden" value="' . $i . '" /></form></td>';
$cartOutput .= '</tr>';
$i++;
}
?>
Edited by Zane, 18 November 2012 - 09:10 PM.
#4
Posted 18 November 2012 - 08:58 PM
And your question is?
http://thorpesystems.com | http://proemframework.org | http://github.com/trq
SmtpCatcher - A very simple mock sendmail useful for testing PHP mail scripts.
#5
Posted 18 November 2012 - 09:08 PM
What is the code for adding tax to a shopping cart
for example I would like php to add 6% tax for every item that appears my shopping cart.. instead of me doing is manually....I hope this was clear enough
for example I would like php to add 6% tax for every item that appears my shopping cart.. instead of me doing is manually....I hope this was clear enough
#6
Posted 19 November 2012 - 11:45 AM
$price = "1"; $taxrate = ".06"; $gettax = $price * $taxrate; $total = $price + $gettax;
#7
Posted 19 November 2012 - 03:00 PM
Thank you
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users














