PHP - Update & Checkout Buttons For Cart
Hi, I have set up a simple shopping cart with a coupon code function.
I am having an issue with the Update basket and Checkout buttons, when you click update basket it loads the /checkout/ page but then redirects back to the /cart/ after a couple of seconds when it should just load a new page saying 'Shopping basket successfully updated' - also, when you click the proceed to checkout button it does the same, loads the /checkout/ page (which is correct) but then redirects back to /cart/. Here is the php code I have setup: // View Shopping Basket if (!isset($_GET['action']) || $_GET['action'] == 'products') { // Check if the shopping basket is empty if ($cart->get_num_products(session_id()) <= 0) { output('Your shopping basket contains no products!'); } else { if (!isset($_POST['submit'])) { $tpl->set('body', $body->fetch('index.tpl.php')); } else { $cart->update_contents(session_id()); output('Shopping basket successfully updated!'); redirect('/cart/', 2); } } } // Add Product to Cart if (isset($_GET['action']) && $_GET['action'] == 'add_product') { $product_id = isset($_GET['product_id']) && is_numeric($_GET['product_id']) ? (int) $_GET['product_id'] : 0; $cart->add_product(session_id(), $product_id, 1); output('Product successfully added! Please wait while we redirect you to your shopping basket.'); redirect('/cart/', 2); } if (isset($_SESSION['coupon_code'])){ unset($_SESSION['coupon_code']); } if (isset($_POST['go']) && $_POST['go'] != ''){ $_SESSION['coupon_code'] = $_POST['coupon_code']; header("location:/checkout/"); } Here is the HTML for the form: Code: [Select] <h1>My Basket</h1> <form method="post" action="/cart/"> <input type="hidden" name="submit" value="Update" /> <input type="hidden" name="go" value="true" /> <table class="tableGrid"> <tr> <th width="10%"><strong>Remove:</strong></th> <th width="60%"><strong>Product Name:</strong></th> <th width="10%"><strong>Price:</strong></th> <th width="10%"><strong>Qty:</strong></th> <th width="10%"><strong>Total:</strong></th> </tr> <?php foreach ($GLOBALS['cart']->get_contents(session_id()) as $product) { ?> <tr> <td align="center" width="10%"><input type="checkbox" name="delete<?php echo $product['cart_id']; ?>" value="yes" /></td> <td width="60%"><a href="<?php echo get_url('/products/', $product['category_id'], $product['product_id'], $product['product_name']); ?>"><?php echo $product['product_name']; ?></a> <span class="important">* <?php echo $product['stock'] >= $product['quantity'] ? 'Available' : 'Not Enough In Stock'; ?></span></td> <td width="10%" align="center"><?php echo get_price($product['price']); ?></td> <td width="10%" align="center"><input type="text" name="quantity<?php echo $product['cart_id']; ?>" value="<?php echo $product['quantity']; ?>" maxlength="10" style="width: 30px;" /></td> <td width="10%" align="center"><?php echo get_price($product['price'] * $product['quantity']); ?></td> </tr> <?php } ?> </table><br /> <div class="main_box" style="height: 26px;"> <div style="float: right;">Subtotal: <strong><?php echo get_price($GLOBALS['cart']->get_cart_total(session_id())); ?></strong></div> <div style="float: left;"> <label><strong>If you have a promotion voucher code please enter it he </strong></label> <input type="text" name="coupon_code" id="coupon_code" value="" /> </div> </div><br /> <div align="center"><input type="image" src="<?php echo '/' . $config['image_path']; ?>button_cart_update.gif" border="0" alt="Update Shopping Basket" /> <a href="/shop-11/"><img src="<?php echo '/' . $config['image_path']; ?>button_continue.gif" border="0" alt="Continue Shopping" /></a> <input type="image" name="checkout" src="<?php echo '/' . $config['image_path']; ?>button_checkout.gif" border="0" alt="Proceed to Checkout" /></div> </form> If anybody can spot whats wrong I would really appreciate it. - It is probably something so simple but I am finding ti quite frustrating. Thanks, Paul Similar TutorialsHi, I'm building a webshop and im stuck at the checkout. I'm using this Shopping Cart class http://www.webforcecart.com/manual.html The cart is stored as an object in $_SESSION[cart]. This method Code: [Select] print_r($cart->get_contents());would get this as output: Array ( => Array ( [id] => 7 [qty] => 1 [price] => 11.00 [info] => Test [subtotal] => 11 ) [1] => Array ( [id] => 6 [qty] => 2 [price] => 19.00 [info] => White 0 [subtotal] => 38 ) ) In the table Order I would like to store order-id customer-id total products total quantity total price date In the table Orderrow I would like to sto order-id, product-id, product-name, quantity, price, subtotal I know i can get the order-id with the function mysql_insert_id() but how can i store each product in the array with their info in the table Orderrow? Or is there a better way to do this? please advice me, thank you. I am trying to create a registration form for upcoming events, and would like to have an "Add-to-Cart" button next to each choice like this... Code: [Select] Car Show *Add-to-Cart* Oct, 1, 2011 $20 Craft Show *Add-to-Cart* Oct 2, 2011 $30 Fishing Show *Add-to-Cart* Oct 8, 2011 $25 I think I have the HTML/CSS figured out, but am unsure of how to get the buttons working?! Do I need an HTML Form? How do I have having several "Add-to-Cart" buttons? The idea is that whichever button the user clicks, that will then tell my PHP to store the "Event ID" and "Quantity" in either a Cookie, Session, or Database record. So I'm not even sure that I need an HTML Form... Sincerely, Debbie everything seems to b working correctly...except 'update cart' where if i click on update cart button it redirects me to d previous page...instead of calculating the input.. i m not able 2 figure out what d problem is.. here's d cart.php: <?php require_once 'library/config.php'; require_once 'library/cart-functions.php'; $action = (isset($_GET['action']) && $_GET['action'] != '') ? $_GET['action'] : 'view'; switch ($action) { case 'add' : addToCart(); break; case 'update' : updateCart(); break; case 'delete' : deleteFromCart(); break; case 'view' : } $cartContent = getCartContent(); $numItem = count($cartContent); $pageTitle = 'Shopping Cart'; require_once 'include/header.php'; // show the error message ( if we have any ) displayError(); if ($numItem > 0 ) { ?> <form action="<?php echo $_SERVER['PHP_SELF'] .'?action=update'; ?>" method="POST" name="frmCart" id="frmCart"> <table width="780" border="0" align="center" cellpadding="5" cellspacing="1" class="entryTable"> <tr class="entryTableHeader"> <td colspan="2" align="center">Item</td> <td align="center">Unit Price</td> <td width="75" align="center">Quantity</td> <td align="center">Total</td> <td width="75" align="center"> </td> </tr> <?php $subTotal = 0; for ($i = 0; $i < $numItem; $i++) { extract($cartContent[$i]); $productUrl = "index.php?c=$cat_id&p=$pd_id"; $subTotal += $pd_price * $ct_qty; ?> <tr class="content"> <td width="80" align="center"><a href="<?php echo $productUrl; ?>"><img src="<?php echo $pd_thumbnail; ?>" border="0"></a></td> <td><a href="<?php echo $productUrl; ?>"><?php echo $pd_name; ?></a></td> <td align="right"><?php echo displayAmount($pd_price); ?></td> <td width="75"><input name="txtQty[]" type="text" id="txtQty[]" size="5" value="<?php echo $ct_qty; ?>" class="box" onKeyUp="checkNumber(this);"> <input name="hidCartId[]" type="hidden" value="<?php echo $ct_id; ?>"> <input name="hidProductId[]" type="hidden" value="<?php echo $pd_id; ?>"> </td> <td align="right"><?php echo displayAmount($pd_price * $ct_qty); ?></td> <td width="75" align="center"> <input name="btnDelete" type="button" id="btnDelete" value="Delete" onClick="window.location.href='<?php echo $_SERVER['PHP_SELF'] . "?action=delete&cid=$ct_id"; ?>';" class="box"> </td> </tr> <?php } ?> <tr class="content"> <td colspan="4" align="right">Sub-total</td> <td align="right"><?php echo displayAmount($subTotal); ?></td> <td width="75" align="center"> </td> </tr> <tr class="content"> <td colspan="4" align="right">Shipping </td> <td align="right"><?php echo displayAmount($shopConfig['shippingCost']); ?></td> <td width="75" align="center"> </td> </tr> <tr class="content"> <td colspan="4" align="right">Total </td> <td align="right"><?php echo displayAmount($subTotal + $shopConfig['shippingCost']); ?></td> <td width="75" align="center"> </td> </tr> <tr class="content"> <td colspan="5" align="right"> </td> <td width="75" align="center"> <input name="btnUpdate" type="submit" id="btnUpdate" value="Update Cart" class="box"></td> </tr> </table> </form> <?php } else { ?> <p> </p><table width="550" border="0" align="center" cellpadding="10" cellspacing="0"> <tr> <td><p align="center">You shopping cart is empty</p> <p>If you find you are unable to add anything to your cart, please ensure that your internet browser has cookies enabled and that any other security software is not blocking your shopping session.</p></td> </tr> </table> <?php } $shoppingReturnUrl = isset($_SESSION['shop_return_url']) ? $_SESSION['shop_return_url'] : 'index.php'; ?> <table width="550" border="0" align="center" cellpadding="10" cellspacing="0"> <tr align="center"> <td><input name="btnContinue" type="button" id="btnContinue" value="<< Continue Shopping" onClick="window.location.href='<?php echo $shoppingReturnUrl; ?>';" class="box"></td> <?php if ($numItem > 0) { ?> <td><input name="btnCheckout" type="button" id="btnCheckout" value="Proceed To Checkout >>" onClick="window.location.href='checkout.php?step=1';" class="box"></td> <?php } ?> </tr> </table> <?php require_once 'include/footer.php'; ?> and here is update cart function: function updateCart() { $cartId = $_POST['hidCartId']; $productId = $_POST['hidProductId']; $itemQty = $_POST['txtQty']; $numItem = count($itemQty); $numDeleted = 0; $notice = ''; for ($i = 0; $i < $numItem; $i++) { $newQty = (int)$itemQty[$i]; if ($newQty < 1) { // remove this item from shopping cart deleteFromCart($cartId[$i]); $numDeleted += 1; } else { // check current stock $sql = "SELECT pd_name, pd_qty FROM tbl_product WHERE pd_id = {$productId[$i]}"; $result = dbQuery($sql); $row = dbFetchAssoc($result); if ($newQty > $row['pd_qty']) { // we only have this much in stock $newQty = $row['pd_qty']; // if the customer put more than // we have in stock, give a notice if ($row['pd_qty'] > 0) { setError('The quantity you have requested is more than we currently have in stock. The number available is indicated in the "Quantity" box. '); } else { // the product is no longer in stock setError('Sorry, but the product you want (' . $row['pd_name'] . ') is no longer in stock'); // remove this item from shopping cart deleteFromCart($cartId[$i]); $numDeleted += 1; } } // update product quantity $sql = "UPDATE tbl_cart SET ct_qty = $newQty WHERE ct_id = {$cartId[$i]}"; dbQuery($sql); } } if ($numDeleted == $numItem) { // if all item deleted return to the last page that // the customer visited before going to shopping cart header("Location: $returnUrl" . $_SESSION['shop_return_url']); } else { header('Location: cart.php'); } exit; } Hi, Im trying to make a shopping cart. Here is an extract while ($shoppingbasket = mysql_fetch_array($shoppingbasket2, MYSQL_ASSOC)) { echo " <form action='?' method='post'> <td><input type='text' value='$shoppingbasket[qty]' name='qty' /></td> </form> "; } The problem is if there are more than two entries in the cart so I have more than one textbox. I need each textbox assigned to the shopping cart ID to include in the WHERE cause to update the qty otherwise they all get updated the same qty. I hope this makes sences If you were working on a PHP shopping cart using SESSION variables for the cart item's product id and quantity, how would you update the cart if the same product were chosen? If the same product id was posted, how would you add the quantities and show just the same product? Hello. I'm trying to figure out the most logical way to update my shopping cart (table). When my checkout.php script loads, I need to run some checks on all cart items and take appropriate action. For example, a "Trial Offer" is only available to non-Members, so if a Member somehow has a "Trial Offer" in his/her shopping cart then I'd like my checkout.php script to remove that automatically from the Member's cart. So when checkout.php loads, one of the first things I do is to read the user's shopping cart items from the database. But what is the most logical way to update the shopping cart table? Do I load the shopping cart records into an array, then iterate through them, remove any non-applicable "Trial Offers" and then write things back to the shopping cart table? (If so, then how do I merge things? This is what is confusing me...) Or do I somehow iterate through the shopping cart records for the user and update each record at a time and avoid loading things into memory like using an array? Again, this seems like a simple enough task, but I'm not sure the smartest way to do things?!
Hi all I am having troubles integrating a shopping cart. $action = (isset($_GET['action']) && $_GET['action'] != '') ? $_GET['action'] : 'view'; switch ($action) { case 'add' : addToCart(); break; case 'update' : updateCart(); break; case 'delete' : deleteFromCart(); break; case 'view' : } Allows me to Delete and Update but not Add an item. [php]$action = (isset($_POST['action']) && $_POST['action'] != '') ? $_POST['action'] : 'view'; Allows me to ADD an item to the cart(add action passed from previous page via form) but not Delete or UPDATE Im not sure if I should have attached the pages or just pasted them but heres the code cart.php <?php require_once 'config.php'; require_once 'cart-functions2.php'; require_once 'functions.php'; require_once 'database.php'; $ID = $_POST["ID"]; $pSize = $_POST["size"]; $pcolour = $_POST["colour"]; ?> <?php $action = (isset($_GET['action']) && $_GET['action'] != '') ? $_GET['action'] : 'view'; switch ($action) { case 'add' : addToCart(); break; case 'update' : updateCart(); break; case 'delete' : deleteFromCart(); break; case 'view' : } $ID = $_POST["ID"]; $cartContent = getCartContent(); $numItem = count($cartContent); $pageTitle = 'Shopping Cart'; // show the error message ( if we have any ) displayError(); if ($numItem > 0 ) { ?> <form action="<?php echo $_SERVER['PHP_SELF'] . "?action=update"; ?>" method="post" name="frmCart" id="frmCart"> <table width="780" border="0" align="center" cellpadding="5" cellspacing="1" class="entryTable"> <tr class="entryTableHeader"> <td colspan="2" align="center">Item</td> <td align="center">Unit Price</td> <td width="75" align="center">Quantity</td> <td align="center">Total</td> <td width="75" align="center"> </td> </tr> <?php $subTotal = 0; for ($i = 0; $i < $numItem; $i++) { extract($cartContent[$i]); $productUrl = "index.php"; $subTotal += $price * $ct_qty; ?> <tr class="content"> <td width="80" align="center"></td> <td><?php echo $pDesc; ?></td> <td align="right"><?php echo displayAmount($price); ?></td> <td width="75"><input name="txtQty[]" type="text" id="txtQty[]" size="5" value="<?php echo $ct_qty; ?>" class="box" onKeyUp="checkNumber(this);"> <input name="hidCartId[]" type="hidden" value="<?php echo $ct_id; ?>"> <input name="hidProductId[]" type="hidden" value="<?php echo $ID; ?>"> </td> <td align="right"><?php echo displayAmount($price * $ct_qty); ?></td> <td width="75" align="center"> <input name="btnDelete" type="button" id="btnDelete" value="Delete" onClick="window.location.href='<?php echo $_SERVER['PHP_SELF'] . "?action=delete&cid=$ct_id"; ?>';" class="box"> </td> </tr> <?php } ?> cart-functions <?php require_once 'config.php'; /********************************************************* * SHOPPING CART FUNCTIONS *********************************************************/ function addToCart() { $sid = session_id(); $ID = $_GET["ID"]; $pSize = $_GET["size"]; $pcolour = $_GET["colour"]; // current session id // check if the product is already // in cart table for this session $sql = "SELECT ID FROM cart WHERE ID = '$ID' AND ct_session_id = '$sid'"; $result = dbQuery($sql); if (dbNumRows($result) == 0) { // put the product in cart table $sql = "INSERT INTO cart (ID, ct_qty, ct_session_id, ct_date) VALUES ('$ID', 1, '$sid', NOW())"; $result = dbQuery($sql); } else { // update product quantity in cart table $sql = "UPDATE cart SET ct_qty = ct_qty + 1 WHERE ct_session_id = '$sid' AND ID = '$ID'"; $result = dbQuery($sql); } header('Location: cart2.php'); } /* Get all item in current session from shopping cart table */ function getCartContent() { $cartContent = array(); $sid = session_id(); $sql = "SELECT ct.ct_id, ct.ID, ct.ct_size, ct.ct_colour, ct.ct_qty, pd.pDesc, pd.price, pd.ID FROM cart ct, products pd WHERE ct_session_id = '$sid' AND ct.ID = pd.ID"; $result = dbQuery($sql); while ($row = dbFetchAssoc($result)) { $cartContent[] = $row; } return $cartContent; } /* Remove an item from the cart */ function deleteFromCart($cartId = 0) { if (!$cartId && isset($_GET['cid']) && (int)$_GET['cid'] > 0) { $cartId = (int)$_GET['cid']; } if ($cartId) { $sql = "DELETE FROM cart WHERE ct_id = $cartId"; $result = dbQuery($sql); } header('Location: cart2.php'); } /* Update item quantity in shopping cart */ function updateCart() { $cartId = $_POST['hidCartId']; $productId = $_POST['hidProductId']; $itemQty = $_POST['txtQty']; $numItem = count($itemQty); $numDeleted = 0; $notice = ''; for ($i = 0; $i < $numItem; $i++) { $newQty = (int)$itemQty[$i]; if ($newQty < 1) { // remove this item from shopping cart deleteFromCart($cartId[$i]); $numDeleted += 1; } // update product quantity $sql = "UPDATE cart SET ct_qty = $newQty WHERE ct_id = {$cartId[$i]}"; dbQuery($sql); } exit; } function isCartEmpty() { $isEmpty = false; $sid = session_id(); $sql = "SELECT ct_id FROM cart ct WHERE ct_session_id = '$sid'"; $result = dbQuery($sql); if (dbNumRows($result) == 0) { $isEmpty = true; } return $isEmpty; } /* Delete all cart entries older than one day */ function deleteAbandonedCart() { $yesterday = date('Y-m-d H:i:s', mktime(0,0,0, date('m'), date('d') - 1, date('Y'))); $sql = "DELETE FROM cart WHERE ct_date < '$yesterday'"; dbQuery($sql); } ?> Thanks in advance Hey guys, Lovely forum. So I'm building a simple shopping cart from php and mysql. Whenever I update the quantity of the item that I want, I don't want it to duplicate all of the information but instead want it to merge the quantity together. Below is an example of what happens. Note that Test Item has been added to the cart 3 separate times with different quantities (2, 1, and 1). How can I merge this information to show Test Item once with the total quantity? I know it's some kind of merge, but I'm a coding noob. Thanks! Here is some (maybe) relevant information: Code: [Select] $insert = "INSERT INTO new_cart (sku, quantity, username) VALUES ('".$ssku."', '".$squantity."', '".$username."')"; mysql_query($insert); } echo "<table>"; $select = "SELECT * FROM new_cart JOIN products ON new_cart.sku = products.sku where '".$username."' = new_cart.username"; What needs to be changed or updated? EDIT: If you need more information, feel free to let me know and I'll post it. This is the code that I'm using for a shopping cart in order to update the quantity if the same product id is chosen. $cart_items is a two-dimensional session array composed of the id session array and the quantity session array. While looping through $cart_items, I create a temporary array $temp_array so that I can execute some logic on the array without changing the normal output. $temp_array is the $cart_items array without the last items which would be the $_REQUEST id and the $_REQUEST quantity. So the two $_REQUESTs are popped off with array_pop and then the remaining $_SESSIONs are compared to the $_REQUEST id with
$j = array_search($_REQUEST["element_id_$i"], $temp_array); if( $j==$temp_array[$i]) If $j is the key of the item in $temp_array, then the $_REQUEST is unset and the quantities for the item are added together.
There are two problems with this code. First of all the var_dump of the $temp_array is always an empty array but I am expecting to get an array with just the last element popped off. Secondly, foreach($cart_items as $item) { foreach($item["id"] as $key => $val) { foreach($item["quantity"] as $i => $value) { if ($key == $i){ $temp_array = $cart_items; $array = array_pop($temp_array); var_dump($temp_array); if (isset($_REQUEST["element_id_$i"]) && isset($_REQUEST["quantity_$i"])&& isset($value)){ $j = array_search($_REQUEST["element_id_$i"], $temp_array); if( $j==$temp_array[$i]) { echo "<b>SAME PRODUCT ADDED</b>"; $value += $_REQUEST["quantity_$i"]; unset($_REQUEST["element_id_$i"]); }}}}}}
I have a table that shows all the users in my table. Each user is either a user or an admin. I have radio buttons for each user determining if they are a user or an admin Right now I have each RB group named userlevel0, userlevel1, userlevel2 etc.. How can I get all the groups dynamically? I attempted an html array but failed. Hey again, Still on the same project but now doing the cart page. I've been bringing my skills up to date a lot doing this project, however, having said that I now can't figure out why my cart is not adding the items to the cart, i've checked the post data and the quantity is set to 1. Would really appreciate someone having a look at it and hopefully can see what i'm missing. you can see what it should look like (well so far lol) at here in my sandbox site. thanks again. (p.s. The parts are all over the place on the page, so thought better put whole page, sorry if shouldn't have done that) <?php // Initialize the session session_start(); // Include config file require_once "dbcontroller.php"; $db_handle = new DBController(); if(!empty($_GET["action"])) { switch($_GET["action"]) { case "add": if(!empty($_POST["quantity"])) { $productByCode = $db_handle->runQuery("SELECT * FROM products WHERE product_code='" . $_GET["product_code"] . "'"); $itemArray = array($productByCode[0]["product_code"]=>array('product_name'=>$productByCode[0]["product_name"], 'product_code'=>$productByCode[0]["product_code"], 'quantity'=>$_POST["quantity"], 'price'=>$productByCode[0]["price"], 'image'=>$productByCode[0]["img1"])); if(!empty($_SESSION["cart_item"])) { if(in_array($productByCode[0]["product_code"],array_keys($_SESSION["cart_item"]))) { foreach($_SESSION["cart_item"] as $k => $v) { if($productByCode[0]["product_code"] == $k) { if(empty($_SESSION["cart_item"][$k]["quantity"])) { $_SESSION["cart_item"][$k]["quantity"] = 0; } $_SESSION["cart_item"][$k]["quantity"] += $_POST["quantity"]; } } } else { $_SESSION["cart_item"] = array_merge($_SESSION["cart_item"],$itemArray); } } else { $_SESSION["cart_item"] = $itemArray; } } break; case "remove": if(!empty($_SESSION["cart_item"])) { foreach($_SESSION["cart_item"] as $k => $v) { if($_GET["product_code"] == $k) unset($_SESSION["cart_item"][$k]); if(empty($_SESSION["cart_item"])) unset($_SESSION["cart_item"]); } } break; case "empty": unset($_SESSION["cart_item"]); break; } } ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>LeaversHoodies.ie</title> <!-- Bootstrap --> <link href="css/bootstrap-4.4.1.css" rel="stylesheet"> <link href="css/accordian.css" rel="stylesheet"> </head> <body> <?php include 'header_student.php'; ?> <br /> <?php $school_page = "ravenswell"; $sql = "SELECT * FROM schools WHERE school_page = '$school_page'"; if($result = mysqli_query($conn, $sql)) while($row = mysqli_fetch_array($result)) { ?> <h3 class="text-center">Student Ordering Page For</h3> <h2 class="text-center" style="text-transform:uppercase;"><?php echo $row['school_name']; ?></h2> <hr style="width: 50%; text-align:center; border: 2px solid #00aeef; border-radius: 5px; margin: 0 auto;"> <br /> <div class="container"> <div class="row"> <div class="col"> <?php $path = "images/schools/"; $file = $row["logo"]; if(!empty($row['logo'])) { echo '<img src="'.$path.$file.'" style="width:95%; height:auto; margin-top:-130px;"><br /><br />'; } else { echo '<img src="images/schools/140x140.gif" style="width:95%; height:auto; margin-top:-130px;"><br /><br />'; } ?></div> <div class="col-6"> <h5>These are the garments your school has choosen :</h5><br /> <?php $school_id = $row["school_id"]; } var_dump($_SESSION); var_dump($_POST); $product_array = $db_handle->runQuery("SELECT * FROM choices INNER JOIN products USING (product_code) INNER JOIN colours USING (colour_id) WHERE school_id = '$school_id'"); if (!empty($product_array)) { foreach($product_array as $key=>$value){ ?> <div class="container"> <div class="row"> <div class="col-5" style="text-align:left;"> <img src="images/products/<?php echo $product_array[$key]["img1"]; ?>" alt="<?php echo $product_array[$key]["product_code"]; ?>" style="position:relative; top:0; width:200px; display:block;"> </div> <div class="col-7"> <h5><?php echo $product_array[$key]["product_name"]; ?></h5><p> in <?php echo $product_array[$key]["colour_name"]; ?></p> <p style="font-size:12px;"><?php echo $product_array[$key]["description"]; ?></p> <?php $comment = $product_array[$key]["comment"]; if (empty($comment)) { echo ""; } else { ?> <p style="font-size:12px;"><b>A note from your teacher:</b> <br /> <?php echo $product_array[$key]["comment"]; ?></p> <?php }; ?> <form action="student_order.php?schoolname=<?php echo $school_page; ?>?action=add&product_code=<?php echo $product_array[$key]["product_code"]; ?>" method="post"> <?php $product = $product_array[$key]["product_code"]; ?> Please select your size : <select id="size" name="size"> <?php $sql1 = "SELECT DISTINCT * FROM sizes WHERE product_code = '$product'"; if($result1 = mysqli_query($conn, $sql1)) while($row3 = mysqli_fetch_array($result1)){ echo "<option value='" . $row3['size'] . "'>" . $row3['size'] . "</option>"; } else { echo "nothing to see here"; } ?> </select> <br /><br /> <div class="number">How many do you want: <input type="number" style="font-size:12px;" id="quantity" name="quantity" value="1" min="1" max="5"><br /> Price : <?php echo "€".$product_array[$key]["price"]; ?> </div> <input type="hidden" id="product_code" value="<?php echo $product; ?>"><br /> <input type="submit" style="font-size:12px;" value="Add to Order" class="btnAddAction"> </form> </div> </div> <br /><hr style="width: 90%; text-align:center; border: 1px solid #00aeef; border-radius: 5px; margin: 0 auto;"><br /> </div> <?php } } else { echo "No Schools by that name registered."; } ?> </div> <div class="col-3"> <div style="border: 1px solid #d3d3d3; padding: 10px; border-radius: 5px; margin-top:30px;"> Your Order: </div> </div> </div> <div class="txt-heading">Shopping Cart</div> <a id="btnEmpty" href="student_order.php?schoolname=<?php echo $school_page; ?>?action=empty">Empty Cart</a> <?php if(isset($_SESSION["cart_item"])){ $total_quantity = 0; $total_price = 0; ?> <table class="tbl-cart" cellpadding="10" cellspacing="1"> <tbody> <tr> <th style="text-align:left;">Name</th> <th style="text-align:left;">Code</th> <th style="text-align:right;" width="5%">Quantity</th> <th style="text-align:right;" width="10%">Unit Price</th> <th style="text-align:right;" width="10%">Price</th> <th style="text-align:center;" width="5%">Remove</th> </tr> <?php foreach ($_SESSION["cart_item"] as $item){ $item_price = $item["quantity"]*$item["price"]; ?> <tr> <td><img src="images/products/<?php echo $item["img1"]; ?>" class="cart-item-image" /><?php echo $item["product_name"]; ?></td> <td><?php echo $item["product_code"]; ?></td> <td style="text-align:right;"><?php echo $item["quantity"]; ?></td> <td style="text-align:right;"><?php echo "$ ".$item["price"]; ?></td> <td style="text-align:right;"><?php echo "$ ". number_format($item_price,2); ?></td> <td style="text-align:center;"><a href="student_order.php?schoolname=<?php echo $school_page; ?>?action=remove&product_code=<?php echo $item["product_code"]; ?>" class="btnRemoveAction"><img src="icon-delete.png" alt="Remove Item" /></a></td> </tr> <?php $total_quantity += $item["quantity"]; $total_price += ($item["price"]*$item["quantity"]); } ?> <tr> <td colspan="2" align="right">Total:</td> <td align="right"><?php echo $total_quantity; ?></td> <td align="right" colspan="2"><strong><?php echo "$ ".number_format($total_price, 2); ?></strong></td> <td></td> </tr> </tbody> </table> <?php } else { ?> <div class="no-records">Your Cart is Empty</div> <?php } ?> </div> </div> <br /><br /> <?php include 'footer_student.php'; ?> <!-- jQuery (necessary for Bootstrap's JavaScript plugins) --> <script src="js/jquery-3.4.1.min.js"></script> <!-- Include all compiled plugins (below), or include individual files as needed --> <script src="js/popper.min.js"></script> <script src="js/bootstrap-4.4.1.js"></script> </body> </html>
How can I make index.php?view=cart work in place of cart.php in the following code? Works: header("Location: cart.php?msg=Thank you. Check your e-mail for Login details."); die; } else header("Location: cart.php?msg=Account with given email does not exist."); die; Doesn't work: header("Location: index.php?view=cart?msg=Thank you. Check your e-mail for Login details."); die; } else header("Location: index.php?view=cart?msg=Account with given email does not exist."); die; This is part PHP, part MySQL question, but since I'm more interested in the process-flow, I'll ask here. I am ready to start coding the e-commerce module of my website, which features mostly paid subscriptions.
Do the below steps sound like the correct sequence to do things in...
- Anonymous shopper adds subscription to Shopping Cart - Shopper goes to check out - Shopper completes checkout form which includes setting up the account and entering payment details Now for the important stuff... - System takes Shopping Cart details - which include the PHPSessionID - System creates Member record - System takes Shopping Cart details associated with PHPSessionID and links them to the new Member record - System creates Order and Order Details records - System runs the payment - System hopefully gets back a "success" message from Payment Processor - System activates the Member's account
How does that sound at a high-level?
Really what I'm trying to validate is if I should create the Member record 1st, then create the Order records 2nd, and worry about the payment last. (Originally I was going to run the payment first, but I'm thinking it's better to capture the anonymous shopper's details in a Member record and Order records first, because even if the paymnt fails, you want something to work off of - like reaching out to the person and getting another valid payment.)
Thoughts?
hi, I'm integrating google checkout on my website using php. anyone have any idea if google checkout take payment on website just like paypal payment pro??? Looking forward. Best regards Hi, I was wondering if someone can help. I am trying to implement a server to server Google checkout system on my website. I have built my own custom shopping basket which meets my needs however I need to get my data in the correct format to send off for the payment to be taken by Google checkout. At present I have a sql table called basket which stores all of the items that a user adds to thier basket. The google checkout examle requires the data in the below format: Code: [Select] $item_1 = new GoogleItem("product name ", // Item name "With S/N", // Item description $total_count, // Quantity 10.99); // Unit price $item_1->SetURLDigitalContent('http://example.com/download.php?id=15', 'S/N: 123.123123-3213', "Download Item1"); $cart->AddItem($item_1); The above code is obviously for just the one item. Is it best to store the basket in a sql database and if so how would I go about retrieving the information from the database and then sending it to google in the above format bearing in mind there can be multiple items in the cart? Thanks in advance Edd I could use some suggestion on how to model the Checkout Process for my e-commerce site. As I see it, when a person "checks out" there are 5 steps... 1.) Create an Account/Log-In 2.) Enter Addresses 3.) Choose Shipping Options 4.) Enter Payment Details 5.) Review & Place Order I'm trying to avoid having gigantic "God classes" and struggling to figure out how to abstract things in good OOP terms. My Head First: Design Patterns book talked about the "State Pattern" and I'm wondering if that might be a good approach? Maybe each of the 5 steps above could be a "state" in the Checkout Process? What do you think? TomTees Hi all, I am looking to integrate Paypal Express checkout on my site and have been working with the API today. I have got the code working in a static state with predefined payment amounts but I am having trouble making this dynamic. When you first submit a request to set up an express checkout you send the payment amount along with it. The paypal server then makes the checkout and the user is redirected to the paypal site to login and authenticate. From here they click to be redirected back to my site where I have a pay button which when clicked submits the final request to confirm the payment. I am sure there must be a simple solution to this because so many people use paypal already but when you submit the final confirmation request, you have to send the payment amount again, but because the page redirects onto the paypal page inbetween, I can't use a session variable to store the amount. How have other people overcome this? Thanks Hey guys! I need your help with some issues. Firstly, I have an own website with a database filled with products, and also a template page(template.php) for each product. Problem is that I don't know how to generate each product from the database in the template.php file using their id from the database. How can I do this? Second problem, I got an own checkout and I don't know how to redirect the customer to a "thank you for buying" page after clicking "Finish Order". It sends the customer to a white page where it says: "Thanks for buying!". Third and last thing, do you guys know where can I find a php checkout template to follow? Thanks in advance for your answers! Cheers! |