I am trying to blend 2 different shopping carts scripts into one script ( neither one was totally what i wanted to start with, and had totally different functionality ), and am stumped on adding the carts session values for the items into a Paypal form.
The basic cart getting and displaying the items....
PHP Code:
function showCart () { global $db ; $cart = $_SESSION [ 'cart' ]; $zipcode = $_SESSION [ 'zipcode' ]; 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 class="producttable">' ; $output [] = '<tr>' ; $output [] = '<td class="productinfo" width="30%">Product</td>' ; $output [] = '<td class="productinfo" width="10%">Price</td>' ; $output [] = '<td class="productinfo" width="10%">Shipping</td>' ; $output [] = '<td class="productinfo" width="10%">Remove Item</td>' ; $output [] = '<td class="productinfo" width="5%">Qty.</td>' ; $output [] = '<td class="productinfo" width="10%">Total</td>' ; $output [] = '</tr>' ; foreach ( $contents as $id => $qty ) { $sql = 'SELECT * FROM product_details WHERE id = ' . $id ; $result = $db -> query ( $sql ); $row = $result -> fetch (); extract ( $row ); $output [] = '<tr>' ; $output [] = '<td class="productinfo">' . $part . ' <br/> ' . $name . '<br />Shipping Weight: ' . $weight . ' lbs.<br/> Package Dimensions:<br/> ' . $length . '" x ' . $width . '" x ' . $height . '"</td>' ; $output [] = '<td class="productinfo">$ ' . $price . '</td>' ; $service = '03' ; $length = $length ; $width = $width ; $height = $height ; $weight = $weight ; $dest_zip = $zipcode ; $rate = ups ( $dest_zip , $service , $weight , $length , $width , $height ); $rate = number_format ( $rate , 2 , '.' , ',' ); $output [] = '<td class="productinfo">$ ' . $rate . ' ea</td>' ; $output [] = '<td class="productinfo"><a href="cart.php?action=delete&id=' . $id . '">Remove</a></td>' ; $output [] = '<td class="productinfo"><input type="text" name="qty' . $id . '" value="' . $qty . '" size="3" maxlength="3" /></td>' ; $product_rate = $price + $rate ; $product_price = ( float ) $product_rate * ( int ) $qty ; $product_price = number_format ( $product_price , 2 , '.' , ',' ); $output [] = '<td class="productinfo">$' . $product_price . '</td>' ; $total_price += ( float ) $product_price ; $total_price = number_format ( $total_price , 2 , '.' , ',' ); $output [] = '</tr>' ; } $output [] = '<tr>' ; $output [] = '<td colspan="6" class="producttotal">Total Product + Shipping: <strong>$' . $total_price . '</strong><br/><br/></td>' ; $output [] = '</tr></table>' ;
and the Paypal form ...
Any suggestions are appreciated. Can post additional information if needed.