cafegirl Posted December 16, 2008 Share Posted December 16, 2008 Hi there, I have this code, which was written by someone else, but I have customised it slightly. I have the following files: the shop front, called index.php, the cart, called cart.php and all the functions are in an include file, named functions. The cart page displays the cart, then has a form, in which customers can enter shipping details, etc. All of the above works fine. I then have an additional file, called sendorder.php, which is MEANT to send the contents of the shopping cart and the customer's details in an email to the shop owner, who can then process the order. The idea is payment is taken on delivery, as opposed to by Paypal or any other kind of online payment. The shopping cart is shown as follows (in the functions file) <?php //function writeCart() goes here 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 table1 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>'.$Category.' : '.$Item.'</td>'; $output[] = '<td>£'.$Price.'</td>'; $output[] = '<td><input type="text" name="qty'.$id.'" value="'.$qty.'" size="3" maxlength="3" /></td>'; $output[] = '<td>£'.($Price * $qty).'</td>'; $total += $Price * $qty; $output[] = '</tr>'; } $output[] = '</table>'; $output[] = '<p>Grand total: <strong>£'.$total.'</strong></p>'; $output[] = '<div><button type="submit" action="" method="POST">Confirm Order</button></div>'; $output[] = '</form>'; } else { $output[] = '<p>Your shopping cart is empty.</p>'; } return join('',$output); } ?> Here is my mail script: <?php //Includes etc // Start the session session_start(); $cart = $_SESSION['cart']; $action = $_GET['action']; //Code to post form data goes here $Subtotal = ($Price * $qty); $to = "my email address"; $headers = "FROM: $Firstname $Surname <$Email>"; $subject = "ORDER"; $cart = $items = explode(',',$cart); $contents = array(); foreach ($items as $item) { $contents[$item] = (isset($contents[$item])) ? $contents[$item] + 1 : 1; } foreach ($contents as $id=>$qty) { $sql = 'SELECT * FROM menu WHERE Id = '.$id; $result = $db->query($sql); $row = $result->fetch(); extract($row); $Order = "$Category $Item £$Price QTY: $qty Subtotal: $Subtotal Grand Total: $total"; } $body = "A new order has been submitted via your website: ORDER: //This is where I need to display the contents of the shopping cart $Order //Shipping details go here //Customer contact details go here mail($to, $subject, $body, $headers); echo "Thank you."; echo "Your order has been submitted. ?> This is the latest version of the code I have. Obviously it does not work properly!! The code above displays the first row only, nothing else. In previous 'editions' of this code I have managed t print the whole cart in the form of id numbers relating to each product, for example 1,1,1,2,2,2,2 meaning 3 of item one and 4 of item 2. I can post more details if needed, such as he code for cart.php and the rest of functions.inc.php Also, I dont know if it is relevant but the items are stored in a table called table1 and thats where id, category, item and price are pulled from. Quantity is typed in my the user in the shopping cart page, as is the customer and shipping info. Any help would be greatly appreciated! Thanks! Quote Link to comment Share on other sites More sharing options...
ashton321 Posted December 17, 2008 Share Posted December 17, 2008 Have you tried making it an HTML email and just placing the show cart function renamed as something else without the remove buttons? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.