Hi all,

I have a simple shopping cart script that works like a dream, except when I try and integrate it with paypal!

The problem I'm facing is that I cant get the individual items and individual prices to show up in paypal cart as individual. It either lists the last product added, and the total price, or various other combinations that I have no ideas about!

my cart code is:

<?php
function showCart() {
	global $db;
	$cart = $_SESSION['cart'];
	if ($cart) {
		$items = explode(',',$cart);
		$contents = array();
		foreach ($items as $item) {
			$contents[$item] = (isset($contents[$item])) ? $contents[$item] + 1 : 1;
		}
		$output[] = '<form action="cart.php?action=update" method="post" id="cart">';
		$output[] = '<table>';
		foreach ($contents as $id=>$qty) {
			$sql = 'SELECT * FROM books WHERE id = '.$id;
			$result = $db->query($sql);
			$row = $result->fetch();
			extract($row);
			$output[] = '<tr>';
			$output[] = '<td><a href="cart.php?action=delete&id='.$id.'" class="r">Remove</a></td>';
			$output[] = '<td>'.$title.' by '.$author.'</td>';
			$output[] = '<td>&pound;'.$price.'</td>';
			$output[] = '<td><input type="text" name="qty'.$id.'" value="'.$qty.'" size="3" maxlength="3" /></td>';
			$output[] = '<td>&pound;'.($price * $qty).'</td>';
			$total += $price * $qty;
			$output[] = '</tr>';
		}
		$output[] = '</table>';
		$output[] = '<p>Grand total: <strong>&pound;'.$total.'</strong></p>';
		$output[] = '<div><button type="submit">Update cart</button></div>';
		$output[] = '</form>';
		$output[] = '<form action="https://www.paypal.co.uk/cgi-bin/webscr" id="add" method="post">
<fieldset>
<input type="image" src="http://www.blackwidowdesign.co.uk/images/icons/add-basket.gif" 
name="submit" alt="shopping basket" />
<input type="hidden" name="add" value="1" />
<input type="hidden" name="cmd" value="_cart" />
<input type="hidden" name="business" value="webmaster@blackwidowdesign.co.uk" />
<input type="hidden" name="item_name" value="'.$row[title].'" />
<input type="hidden" name="shipping" value="0" />
<input type="hidden" name="no_shipping" value="2" />
<input type="hidden" name="amount" value="'.$row[price].'" />
<input type="hidden" name="return" value="http://www.blackwidowdesign.co.uk/admin" />
<input type="hidden" name="cancel_return" value="http://www.blackwidowdesign.co.uk/admin" />
<input type="hidden" name="currency_code" value="GBP" />
</fieldset>
</form>';
	} else {
		$output[] = '<p>You shopping cart is empty.</p>';
	}
	return join('',$output);
}
?>

any help always appreciated

Mark

    It's been a while since I've had to deal with Paypal so cross reference this with the manual.

    At the moment you are only passing one item_name to Paypal

    From what I remember you have to add each item like:

    <input type="hidden" name="item_name_1" value="First Item" />
    <input type="hidden" name="item_name_2" value="Second Item" />
    

    And the same sort of thing with 'quantity' if you include more than one of an item

      Write a Reply...