Adding shipping to PHPCart

This forum is dedicated to discussions about shopping carts/ecommerce.
Forum rules
PLEASE READ THE FORUM RULES BEFORE YOU POST:
viewtopic.php?f=12&t=1901
Post Reply
User avatar
iamafireman
 
 
Posts: 84
Joined: Mon May 26, 2008 2:41 am
Location: Tennessee

Adding shipping to PHPCart

Post by iamafireman »

I am by no means an expert, but i think i figured out how to add shipping to the PHP WebShop. I used the code that was already there and modified it.
I have the code setup to add shipping based on the subtotal. If the sub total is greater than $xx then the shipping will be $xx, If its less it will be $xx. It is easy to change to what ever you want asfar as the amount of shipping you want based on the totals.

Here is the full code
<?php

$cart = isset($_SESSION['cart']) ? $_SESSION['cart'] : '';
$itemcount = isset($_SESSION['itemcount']) ? $_SESSION['itemcount'] : 0;

$strHTML = "";

if ($itemcount == 0)
{
$strHTML = "<h3>Your shopping cart is empty.</h3>";
}
else
{
$strHTML = "<div style=\"overflow:auto; height=358px;\">"."\n";
$strHTML .= "<table border=\"0\" cellpadding=\"3\" cellspacing=\"2\" width=\"100%\">"."\n";
$strHTML .= "<tr>"."\n";
$strHTML .= "<td>Product code</td>"."\n";
$strHTML .= "<td>Product name</td>"."\n";
$strHTML .= "<td>Quantity</td>"."\n";
$strHTML .= "<td>Price</td>"."\n";
$strHTML .= "<td>Total</td></tr>"."\n";

$total = 0;
$shipping = 0;
$subtotal = 0;
for ($i=0; $i<$itemcount; $i++)
{
$strHTML .= "<tr>"."\n";
$strHTML .= "<td>".$cart[PRODUCTCODE][$i]."</td>"."\n";
$strHTML .= "<td>".$cart[PRODUCTNAME][$i]."</td>"."\n";
$strHTML .= "<td><input type=\"text\" name=\"quantity".($i)."\" value=\"".$cart[QUANTITY][$i]."\" size=\"3\"></td>"."\n";
$strHTML .= "<td>"."$".number_format($cart[PRICE][$i],2)."</td>"."\n";
$strHTML .= "<td>"."$".number_format($cart[PRICE][$i]*$cart[QUANTITY][$i],2)."</td>"."\n";
$strHTML .= "</tr>"."\n";

$subtotal = $subtotal + ($cart[PRICE][$i]*$cart[QUANTITY][$i]);

}
if ($subtotal > 49.99)
{
$shipping = 3.25;
}
else
{
$shipping = 10;
}

$total = $subtotal + $shipping;


$strHTML .= "<tr>"."\n";
$strHTML .= "<td></td><td></td><td></td>"."\n";
$strHTML .= "<td>SubTotal</td>"."\n";
$strHTML .= "<td>"."$".number_format($subtotal, 2)."</td>"."\n";
$strHTML .= "</tr>"."\n";
$strHTML .= "<tr>"."\n";
$strHTML .= "<td></td><td></td><td></td>"."\n";
$strHTML .= "<td>Shipping</td>"."\n";
$strHTML .= "<td>"."$".number_format($shipping, 2)."</td>"."\n";
$strHTML .= "</tr>"."\n";
$strHTML .= "<tr>"."\n";
$strHTML .= "<td></td><td></td><td></td>"."\n";
$strHTML .= "<td>Total</td>"."\n";
$strHTML .= "<td>"."$".number_format($total, 2)."</td>"."\n";
$strHTML .= "</tr>"."\n";
$strHTML .= "</table>"."\n";
$strHTML .= "</div>"."\n";
}
echo $strHTML;

?>
Here is the you change. No decimals are needed if you use whole numbers.
if ($subtotal > 49.99)
{
$shipping = 3.25;
}
else
{
$shipping = 10;
You can try it

HERE


I have tested it , but take no responsibility if it messes up :D
Last edited by iamafireman on Sun Jan 25, 2009 5:01 am, edited 1 time in total.
User avatar
iamafireman
 
 
Posts: 84
Joined: Mon May 26, 2008 2:41 am
Location: Tennessee

Post by iamafireman »

let me know how its coming.
User avatar
iamafireman
 
 
Posts: 84
Joined: Mon May 26, 2008 2:41 am
Location: Tennessee

Post by iamafireman »

This is the code that need to be modified,
<?php

// display PayPal checkout?
if ($_SESSION['paymenttype'] == "PayPal")
{
echo "<font style=\"font-size:13px\" color=\"#000000\" face=\"Times New Roman\">Please click the PayPal button below to securely pay for your order.<br><br></font>\n";
echo "<form target=\"PayPal\" action=\"https://www.paypal.com/cgi-bin/webscr\" method=\"post\">\n";
echo "<input type=\"hidden\" name=\"cmd\" value=\"_cart\">\n";
echo "<input type=\"hidden\" name=\"business\" value=\"paypal@pablosoftwaresolutions.com\">\n";
echo "<input type=\"hidden\" name=\"receiver_email\" value=\"paypal@pablosoftwaresolutions.com\">\n";
echo "<input type=\"hidden\" name=\"upload\" value=\"1\">\n";

$itemcount = $_SESSION['itemcount'];
$cart = $_SESSION['cart'];

for ($i=0; $i<$itemcount; $i++)
{
$item = $i+1;
echo "<input type=\"hidden\" name=\"item_name_" . $item . "\" value=\"" . $cart[PRODUCTNAME][$i] . "\">\n";
echo "<input type=\"hidden\" name=\"item_number_" . $item . "\" value=\"" . $cart[PRODUCTCODE][$i] . "\">\n";
echo "<input type=\"hidden\" name=\"amount_" . $item . "\" value=\"" . number_format($cart[PRICE][$i]*$cart[QUANTITY][$i],2) . "\">\n";
}
echo "<input type=\"hidden\" name=\"currency_code\" value=\"USD\">\n";
echo "<input type=\"hidden\" name=\"no_shipping\" value=\"1\">\n";
echo "<input type=\"hidden\" name=\"no_note\" value=\"1\">\n";
echo "<input type=\"image\" name=\"submit\" src=\"http://images.paypal.com/images/x-click-but6.gif\" alt=\"Make payments with PayPal, it's fast, free, and secure!\">\n";
echo "</form>\n";
}

?>
User avatar
iamafireman
 
 
Posts: 84
Joined: Mon May 26, 2008 2:41 am
Location: Tennessee

Post by iamafireman »

i found the code paypal says to use to upload the total amount of a thirdparty shopping cart but i havn't been able to get it to work.It's called
"Passing the Aggregate Cart Amount to PayPal"

https://www.paypal.com/cgi-bin/webscr?c ... ut-outside
User avatar
Eddy
 
 
Posts: 473
Joined: Tue Nov 27, 2007 1:52 am
Location: Nederland.

Post by Eddy »

I did move the answer from Navaldesign to a new topic (sticky) please follow this link.

I did make it a sticky so people can find easy the custom Webshop_plus from Navaldesign!

viewtopic.php?p=66968#66968
Post Reply