Jump to content

Build Theme!
  •  
  • Infected?

WE'RE SURE THAT YOU'LL LOVE US!

Hey there! :wub: Looks like you're enjoying the discussion, but you're not signed up for an account. When you create an account, we remember exactly what you've read, so you always come right back where you left off. You also get notifications, here and via email, whenever new posts are made. You can like posts to share the love. :D Join 93098 other members! Anybody can ask, anybody can answer. Consistently helpful members may be invited to become staff. Here's how it works. Virus cleanup? Start here -> Malware Removal Forum.

Try What the Tech -- It's free!


Photo

Adding a Service Charge to Shopping Cart using PHP


  • Please log in to reply
4 replies to this topic

#1 GaryORLFC

GaryORLFC

    Authentic Member

  • Authentic Member
  • PipPip
  • 56 posts
  • Interests:Sports, Music, Gaming, Computers & Drinks With Friends.

Posted 02 May 2012 - 06:32 PM

Hi there,

Today I created a shopping cart following the tutorial on YouTube from phpacademy.

If you take a look here, you can see exactly what my (phpacademy's) shopping cart does.

I want to know how you could add a service charge to this shopping cart.

So when the users click PayPal Checkout, the receipt will show up with the users items + a service charge.

Could anyone help me out on this?

Posted Image

    Advertisements

Register to Remove


#2 GaryORLFC

GaryORLFC

    Authentic Member

  • Authentic Member
  • PipPip
  • 56 posts
  • Interests:Sports, Music, Gaming, Computers & Drinks With Friends.

Posted 02 May 2012 - 07:56 PM

Sorry for the bump. Either that, or is there any way to add a fee onto your shipping || handling cost?

Posted Image


#3 Nahumi

Nahumi

    Advanced Member

  • Visiting Tech
  • PipPipPipPip
  • 688 posts
  • Interests:Technical Support
    Software Development

Posted 04 May 2012 - 03:39 PM

Hello GaryORLFC, Without seeing the source code I can't tell you exactly how to implement this, but if you're using the usual HTML form method for PayPal you can just add the service charge to the "amount" field. If you post your code in the code tags, I can have a proper look at it for you. ^_^
Nahumi

Visiting Tech
@jamescpegg | FreeTrakr
The help you receive here is free.
If you wish, you may Donate to help keep us online..

#4 GaryORLFC

GaryORLFC

    Authentic Member

  • Authentic Member
  • PipPip
  • 56 posts
  • Interests:Sports, Music, Gaming, Computers & Drinks With Friends.

Posted 07 May 2012 - 08:02 AM

Hi Nahumi,

Thanks for the reply.

Here is the code for the Shopping Cart

<?php

session_start();

$page = 'index2.php';

$connect = mysql_connect("localhost","organis2_admin","dublin") or die("Could not connect to the database.");
mysql_selectdb("organis2_project") or die("Could not find the database.");

if (isset($_GET['add'])) {
$quantity = mysql_query('SELECT id, quantity FROM shoppingcart WHERE id='.mysql_real_escape_string((int)$_GET['add']));
while ($quantity_row = mysql_fetch_assoc($quantity)) {
if ($quantity_row['quantity']!=$_SESSION['quantity_'.(int)$_GET['add']]) {
$_SESSION['quantity_'.(int)$_GET['add']]+='1';
}
}
header('Location: '.$page);
}

if (isset($_GET['remove'])) {
$_SESSION['quantity_'.(int)$_GET['remove']]--;
header('Location:'.$page);
}

if (isset($_GET['delete'])) {
$_SESSION['quantity_'.(int)$_GET['delete']]='0';
header('Location:'.$page);
}

function products(){
$get = mysql_query('SELECT id, product, description, price FROM shoppingcart WHERE quantity > 0 AND id BETWEEN 1 AND 2 ORDER BY id DESC');
if (mysql_num_rows($get)==0){
echo "There are no products to display.";
}
else{
while($get_row = mysql_fetch_assoc($get)){
echo '<p>'.$get_row['product'].'<br />'.$get_row['description'].'<br />&euro;'.number_format($get_row['price'], 2).'<a href="shoppingcart.php?add='.$get_row['id'].'">Add</a></p>';

}
}
}

function products1(){
$get = mysql_query('SELECT id, product, description, price FROM shoppingcart WHERE quantity > 0 AND id BETWEEN 3 AND 5 ORDER BY id DESC');
if (mysql_num_rows($get)==0){
echo "There are no products to display.";
}
else{
while($get_row = mysql_fetch_assoc($get)){
echo '<p>'.$get_row['product'].'<br />'.$get_row['description'].'<br />&euro;'.number_format($get_row['price'], 2).'<a href="shoppingcart.php?add='.$get_row['id'].'">Add</a></p>';

}
}
}

function paypal_products() {
$num = 0;
foreach($_SESSION as $product => $value) {
if ($value!=0) {
if (substr($product, 0, 9)=='quantity_') {
$id = substr($product, 9, (strlen($product)-9));
$get = mysql_query('SELECT id, product, price FROM shoppingcart WHERE id='.mysql_real_escape_string((int)$id));
while ($get_row = mysql_fetch_assoc($get)) {
$num++;
echo '<input type="hidden" name="item_number_'.$num.'" value="'.$id.'">';
echo '<input type="hidden" name="item_name_'.$num.'" value="'.$get_row['product'].'">';
echo '<input type="hidden" name="amount_'.$num.'" value="'.$get_row['price'].'">';
echo '<input type="hidden" name="handling_'.$num.'" value="20">';
echo '<input type="hidden" name="quantity_'.$num.'" value="'.$value.'">';
}
}
}
}
}


function cart() {
$sub="";
$total="";
foreach($_SESSION as $product => $value) {
if ($value>0) {
if (substr($product, 0, 9)=='quantity_') {
$id = substr($product, 9, (strlen($product)-9));
$get = mysql_query('SELECT id, product, price FROM shoppingcart WHERE id='.mysql_real_escape_string((int)$id));
while ($get_row = mysql_fetch_assoc($get)) {
$sub = $get_row['price']*$value;
echo $get_row['product'].' x '.$value.' @ &euro;'.number_format($get_row['price'], 2).' = &euro;'.number_format($sub, 2).'<a href="shoppingcart.php?remove='.$id.'">[-]</a> <a href="shoppingcart.php?add='.$id.'">[+]</a> <a href="shoppingcart.php?delete='.$id.'">[Delete]</a><br />';
}
}
$total += $sub;
}
}
if ($total==0) {
echo "Your cart is empty.";
}
else {
echo 'Total: &euro;'.number_format($total, 2);
?>
<p>
<form action="https://www.paypal.c...cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_cart">
<input type="hidden" name="upload" value="1">
<input type="hidden" name="business" value="admin@organisemiparty.hostingspace.com">
<?php paypal_products(); ?>
<input type="hidden" name="currency_code" value="EUR">
<input type="hidden" name="amount" value="<?php echo $total; ?>">
<input type="image" src="http://www.paypal.co...lick-but03.gif" name="submit" alt="Make payments with PayPal - it's fast, free and secure!">
</form>
</p>

<?php

}
}

?>


Posted Image


#5 GaryORLFC

GaryORLFC

    Authentic Member

  • Authentic Member
  • PipPip
  • 56 posts
  • Interests:Sports, Music, Gaming, Computers &amp; Drinks With Friends.

Posted 11 May 2012 - 07:33 AM

Also, could someone help me out with the quantity part of the code? I want to be able to type in the number of items that I want instead of having to click [+] a certain amount of times. So, a form data that lets you input, let's say 7 of a specific item, and then when you click "Add to Cart" it will add 7 to the cart.

Posted Image

Related Topics



0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users