Jump to content

Search the Community

Showing results for tags 'cart'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Welcome to PHP Freaks
    • Announcements
    • Introductions
  • PHP Coding
    • PHP Coding Help
    • Regex Help
    • Third Party Scripts
    • FAQ/Code Snippet Repository
  • SQL / Database
    • MySQL Help
    • PostgreSQL
    • Microsoft SQL - MSSQL
    • Other RDBMS and SQL dialects
  • Client Side
    • HTML Help
    • CSS Help
    • Javascript Help
    • Other
  • Applications and Frameworks
    • Applications
    • Frameworks
    • Other Libraries
  • Web Server Administration
    • PHP Installation and Configuration
    • Linux
    • Apache HTTP Server
    • Microsoft IIS
    • Other Web Server Software
  • Other
    • Application Design
    • Other Programming Languages
    • Editor Help (PhpStorm, VS Code, etc)
    • Website Critique
    • Beta Test Your Stuff!
  • Freelance, Contracts, Employment, etc.
    • Services Offered
    • Job Offerings
  • General Discussion
    • PHPFreaks.com Website Feedback
    • Miscellaneous

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


AIM


MSN


Website URL


ICQ


Yahoo


Jabber


Skype


Location


Interests


Age


Donation Link

Found 13 results

  1. 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>
  2. Say I have this link where I've added a product to the cart. https://www.adidas.ca/on/demandware.store/Sites-adidas-CA-Site/en_CA/Cart-Show You will see the cart empty because you're on a different computer and the cookies are unique only to the browser I'm browsing on. Basically what I'm trying to do is have products on my own site and when a user goes to buy them, it will link them directly to the cart/checkout page of that said product on that site(eg. adidas). Is something like that possible to do?
  3. $subtotal = $row[0]; $delivery = $row[1]; $discount = $row[2]; $vatrate = $row[3]; $totalex = str_replace(",","",$subtotal) + str_replace(",","",$delivery); $vatamount = ($totalex - $discount) * ($vatrate/100); $vatamount = number_format($vatamount, 2, '.', ','); $total = $row[4]; $centinel_total = $total * 100; $centinel_delivery = $delivery * 100; $centinel_vatamount = $vatamount * 100; I've got a custom written cart system which for some reason is not passing the correct amounts to our 3D secure processor (Cardinel commerce). I'm not a programmer but looking at how it seems to work I think the issue is with this code. From the processor logs we are passing the tax value with a negative amount and the total is always £1 when the total is above £1000. It all works fine as it should if the total amount is LESS than £1000! Anyone got any ideas what's going on? I'm more than happy to pay someone to fix this!!
  4. Hello everyone, Let me first say that I am a PHP beginner. With the use of online video tutorials I have setup a shopping cart for my online store that sells stainless steel jewelry. Everything is working well, but I want to add something and even though I know what needs to e done - I don't know how to go about it. Can someone please help me out? So I have a product page that gets the product's name, code, price and details from the database. This is the page's code: <?php // Script Error Reporting error_reporting(E_ALL); ini_set('display_errors', '1'); ?> <?php // Check to see the URL variable is set and that it exists in the database if (isset($_GET['id'])) { // Connect to the MySQL database include "storescripts/connect_to_mysql.php"; $id = preg_replace('#[^0-9]#i', '', $_GET['id']); // Use this var to check to see if this ID exists, if yes then get the product // details, if no then exit this script and give message why $sql = mysql_query("SELECT * FROM products WHERE id='$id' LIMIT 1"); $productCount = mysql_num_rows($sql); // count the output amount if ($productCount > 0) { // get all the product details while($row = mysql_fetch_array($sql)){ $product_code = $row["product_code"]; $product_name = $row["product_name"]; $price = $row["price"]; $details = $row["details"]; $category = $row["category"]; $date_added = strftime("%b %d, %Y", strtotime($row["date_added"])); } } else { echo "The item does not exist."; exit(); } } else { echo "Data to render this page is missing."; exit(); } mysql_close(); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title><?php echo $product_code; ?></title> <meta http-equiv="Content-type" content="text/html; charset=us-ascii" /> <meta http-equiv="Content-Language" content="en-us" /> <meta http-equiv="imagetoolbar" content="no" /> <meta name="MSSmartTagsPreventParsing" content="true" /> <meta name="description" content="" /> <meta name="keywords" content="" /> <meta name="author" content="Susan Wiese" /> <link rel="stylesheet" href="css/style.css" type="text/css" /> </head> <body> <div id="page-container"> <div id="header"> <?php include "storescripts/header.php"; ?> </div> <div id="center-panel"> <div class="box1"> <?php include "storescripts/menu.php"; ?> </div> <div class="box1"> <table width="100%" border="0" cellspacing="0" cellpadding="15" align="center"> <tr> <td width="25%" valign="top"> <img src="inventory_images/<?php echo $id; ?>.jpg" width="200" height="200" alt="<?php echo $product_name; ?>" /><br /> <a href="inventory_images/<?php echo $id; ?>.jpg">View full size</a></td> <td width="75%" valign="top"> <h3><?php echo $product_code; ?></h3> <?php echo $product_name; ?><br /> <br /> <?php echo $details; ?><br /> <br /> <?php echo "R".$price; ?><br /> <br /> <form id="form1" name="form1" method="post" action="cart.php"> <label for="engraving">Engraving</label><br /> <input type="text" name="engraving" id="engraving" size="35" /><br /> <input type="hidden" name="pid" id="pid" value="<?php echo $id; ?>" /><br /> <input type="submit" name="button" id="button" class="submit" value="Add to cart" /> </form> </td> </tr> </table> </div> <div class="box1"> <?php include "storescripts/order.php"; ?> </div> </div> <div id="footer"> <?php include "storescripts/footer.php"; ?> </div> </div> </body> </html> The product page looks like this: http://www.personalizedjewellery.co.za/store/product.php?id=3 You'll notice I've added an "Engraving" label to the form. I want a visitor to be able to add the engraving they want to be done on this product. This information should then be sent to the cart with all the other details when the person adds the item to their cart. I want the text to be engraved to be displayed in the cart's table with the image, price, etc. This output should be in the //Create the product array section of cart.php (where I have added $engraving) Cart.php <?php session_start(); // Start session first thing in script // Script Error Reporting error_reporting(E_ALL); ini_set('display_errors', '1'); // Connect to the MySQL database include "storescripts/connect_to_mysql.php"; ?> <?php /////////////////////////////////////////////////////////////////////////////////// //Section 1 (if user attempts to add something to the cart from the product page)// /////////////////////////////////////////////////////////////////////////////////// if (isset($_POST['pid'])) { $pid = $_POST['pid']; $wasFound = false; $i = 0; // If the cart session variable is not set or cart array is empty if (!isset($_SESSION["cart_array"]) || count($_SESSION["cart_array"]) < 1) { // RUN IF THE CART IS EMPTY OR NOT SET $_SESSION["cart_array"] = array(0 => array("item_id" => $pid, "quantity" => 1)); } else { // RUN IF THE CART HAS AT LEAST ONE ITEM IN IT foreach ($_SESSION["cart_array"] as $each_item) { $i++; while (list($key, $value) = each($each_item)) { if ($key == "item_id" && $value == $pid) { // That item is in cart already so let's adjust its quantity using array_splice() array_splice($_SESSION["cart_array"], $i-1, 1, array(array("item_id" => $pid, "quantity" => $each_item['quantity'] + 1))); $wasFound = true; } // close if condition } // close while loop } // close foreach loop if ($wasFound == false) { array_push($_SESSION["cart_array"], array("item_id" => $pid, "quantity" => 1)); } } header("location: cart.php"); exit(); } ?> <?php //////////////////////////////////////////////////////////// //Section 2 (if user chooses to empty their shopping cart)// //////////////////////////////////////////////////////////// if (isset($_GET['cmd']) && $_GET['cmd'] == "emptycart") { unset($_SESSION["cart_array"]); } ?> <?php /////////////////////////////////////////////////////// //Section 3 (if user chooses to adjust item quantity)// /////////////////////////////////////////////////////// if (isset($_POST['item_to_adjust']) && $_POST['item_to_adjust'] != "") { // execute some code $item_to_adjust = $_POST['item_to_adjust']; $quantity = $_POST['quantity']; $quantity = preg_replace('#[^0-9]#i', '', $quantity); // filter everything but numbers if ($quantity >= 100) { $quantity = 99; } if ($quantity < 1) { $quantity = 1; } if ($quantity == "") { $quantity = 1; } $i = 0; foreach ($_SESSION["cart_array"] as $each_item) { $i++; while (list($key, $value) = each($each_item)) { if ($key == "item_id" && $value == $item_to_adjust) { // That item is in cart already so let's adjust its quantity using array_splice() array_splice($_SESSION["cart_array"], $i-1, 1, array(array("item_id" => $item_to_adjust, "quantity" => $quantity))); } // close if condition } // close while loop } // close foreach loop } ?> <?php ///////////////////////////////////////////////////////// //Section 4 (if user wants to remove an item from cart)// ///////////////////////////////////////////////////////// if (isset($_POST['index_to_remove']) && $_POST['index_to_remove'] != "") { // Access the array and run code to remove that array index $key_to_remove = $_POST['index_to_remove']; if (count($_SESSION["cart_array"]) <= 1) { unset($_SESSION["cart_array"]); } else { unset($_SESSION["cart_array"]["$key_to_remove"]); sort($_SESSION["cart_array"]); } } ?> <?php ///////////////////////////////////////////////////////////////// //Section 5 (render the cart for the user to view on the page)// ///////////////////////////////////////////////////////////////// $cartOutput = ""; $cartTotal = ""; $pp_checkout_btn = ''; $product_id_array = ''; if (!isset($_SESSION["cart_array"]) || count($_SESSION["cart_array"]) < 1) { $cartOutput = "<h3 align='center'>Your shopping cart is empty</h3>"; } else { // Start the For Each loop $i = 0; foreach ($_SESSION["cart_array"] as $each_item) { $item_id = $each_item['item_id']; $sql = mysql_query("SELECT * FROM products WHERE id='$item_id' LIMIT 1"); while ($row = mysql_fetch_array($sql)) { $product_code = $row["product_code"]; $product_name = $row["product_name"]; $price = $row["price"]; } $pricetotal = $price * $each_item['quantity']; $cartTotal = $pricetotal + $cartTotal; $pricetotal = money_format("%.2n", $pricetotal); // Create the product array variable $product_id_array .= "$item_id-".$each_item['quantity'].", "; // Dynamic table row assembly $cartOutput .= "<tr>"; $cartOutput .= '<td><a href="product.php?id=' . $item_id . '">' . $product_code . '</a><br /><img src="inventory_images/' . $item_id . '.jpg" alt="' . $product_code. '" width="75" height="75" border="1" /></td>'; $cartOutput .= '<td>R' . $engraving . '</td>'; $cartOutput .= '<td>R' . $price . '</td>'; $cartOutput .= '<td><form action="cart.php" method="post"> <input name="quantity" type="text" value="' . $each_item['quantity'] . '" size="1" maxlength="2" /><br /> <br /> <input name="adjustBtn' . $item_id . '" type="submit" class="submit" value="Change" /> <input name="item_to_adjust" type="hidden" value="' . $item_id . '" /> </form></td>'; //$cartOutput .= '<td>' . $each_item['quantity'] . '</td>'; $cartOutput .= '<td>R' . $pricetotal . '</td>'; $cartOutput .= '<td><form action="cart.php" method="post"><input name="deleteBtn' . $item_id . '" type="submit" class="submit" value="X" /><input name="index_to_remove" type="hidden" value="' . $i . '" /></form></td>'; $cartOutput .= '</tr>'; $i++; } $cartTotal = money_format("%.2n", $cartTotal); $cartTotal = "R".$cartTotal." "; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Your Cart</title> <link rel="stylesheet" href="css/style.css" type="text/css" /> </head> <body> <?php include_once("storescripts/analyticstracking.php") ?> <div id="page-container"> <div id="header"> <?php include "storescripts/header.php"; ?> </div> <div id="center-panel"> <div class="box1"> <?php include "storescripts/menu.php"; ?> </div> <div class="box1"> <center> <img src="images/cart.png" alt="Cart" title="Cart" border="0" /> <h3>Your Cart</h3> </center> <div style="margin:24px; text-align:left;"> <table width="80%" border="1" cellspacing="0" cellpadding="6" align="center"> <tr> <td width="20%" bgcolor="#FFFFFF"><strong>Product</strong></td> <td width="35%" bgcolor="#FFFFFF"><strong>Engraving</strong></td> <td width="10%" bgcolor="#FFFFFF"><strong>Price</strong></td> <td width="10%" bgcolor="#FFFFFF"><strong>Quantity</strong></td> <td width="10%" bgcolor="#FFFFFF"><strong>Total</strong></td> <td width="10%" bgcolor="#FFFFFF"><strong>Remove</strong></td> </tr> <?php echo $cartOutput; ?> </table> <br /> Cart Total: <?php echo $cartTotal; ?> | <a href="cart.php?cmd=emptycart">Empty your cart</a><br /> <br /> <h3>If you buy 6 items, you will receive the 6th item for free</h3> This adjustment will be made on your invoice before we send it to you.<br /> <br /> <h3>Postage</h3> The postage cost is to be added to the total above.<br /> • Post Office Registered Mail: R50<br /> • Fastway Couriers (Limited Service): R55<br /> • Speed Services: R90<br /> • Aramex Couriers (Full Service): R105<br /> </div> </div> </div> <div id="footer"> <?php include "storescripts/footer.php"; ?> </div> </div> </body> </html> Could someone please help me get the text to be engraved added to the cart? I would really appreciate it. It is probably very simple, but I'm completely stuck. Thanks Susan
  5. Hi Team. Please help me out to create a small script. i have made a jpeg image(See Below), how i want the script and what the script have to do... Basically i wanted two php script. but currently will tell you the First one. 1.- I would like to create a list of players eg. name1, name 2, name 3, and wanted a drop down list for the Names. and same for the teams, List of teams eg team1,team2,team3 and so on... once the user / admin choose the player (for eg name2) and the team as team1 and click the button (ADD PLAYER), the Player Name should to the choosen Team column in the same page or even in the next page ( By refresh its should not get clear) and also required a remove button Next to the Players incase if we wish to remove.. can any one create a Php script for the same.. please help
  6. Hi guys, i'm developing a simple shopping cart for a website. Everythings worked great, until i decided to make a mod in order to switch type of article token from db. Now here's the bug: every time i try to delete an item from cart, it deletes every item but the first one in the cart. Even if the quantity is more than 1... Please, help me to find this bug.. it's about 4 days that i try to solve it. Sorry for my bad english, and thank you for your help. You can't find the website here and check the bug -> http://www.pizzainncasa.com/SitoGennaio/Sito/ordinaonline.php?&request=Pizza This is my code: ordinaonline.php (shoponline.php in english) <?php session_start(); include_once("config.php"); $request = $_GET['request']; ?> ||HTML.............|| <h1>Articoli </h1><hr><h4>Seleziona una categoria dal menù in alto per visualizzare i prodotti!</h4><br><br> <div class="products"> <?php //current URL of the Page. cart_update.php redirects back to this URL $current_url = base64_encode($url="http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']); $results = $mysqli->query("SELECT * FROM Articoli WHERE Tipo = '$request' ORDER BY ID ASC"); if ($results) { //risultati dal db while($obj = $results->fetch_object()) { echo '<div class="product">'; echo '<form method="post" action="cart_update.php">'; //<img src="images/'.$obj->product_img_name.'" ></div>'; if($obj->product_img_name!=""){echo '<div class="product-thumb"><img width="200" height="100" src="images/'.$obj->product_img_name.'" ></div>';} echo '<div class="product-content"><h4>'.$obj->Nome.'</h4>'; echo '<div class="product-info">Prezzo '.$currency.$obj->Prezzo.' <button class="add_to_cart">Aggiungi al carrello</button></div>'; echo '</div>'; echo '<input type="hidden" name="product_code" value="'.$obj->ID.'" />'; echo '<input type="hidden" name="type" value="add" />'; echo '<input type="hidden" name="return_url" value="'.$current_url.'" />'; echo '</form>'; echo '</div>'; } } ?> </div> <div class="shopping-cart"> <h2>Il tuo carrello</h2> <?php if(isset($_SESSION["products"])) { $total = 0; echo '<ol>'; foreach ($_SESSION["products"] as $cart_itm) { echo ("removing ".$_SESSION['removing']); echo '<li class="cart-itm">'; echo '<span class="remove-itm"><a href="cart_update.php?removep='.$cart_itm["code"].'&return_url='.$current_url.'">×</a></span>'; echo '<h3>'.$cart_itm["name"].'</h3>'; echo $cart_itm['code']; echo ('added -> '.$_SESSION['test']); echo '<div class="p-qty">Quantita : '.$cart_itm["qty"].'</div>'; echo '<div class="p-price">Prezzo € :' .$cart_itm["price"].'</div>'; echo '</li>'; $subtotal = ($cart_itm["price"]*$cart_itm["qty"]); $total = ($total + $subtotal); } echo '</ol>'; echo '<span class="check-out-txt"><strong>Totale € : '.$total.'</strong> <a href="view_cart.php">Invia l\'ordine!</a></span>'; }else{ echo 'Il tuo carrello è vuoto'; } ?> </div> </div> [html............] and this is the cart_update.php [php]<?php session_start(); include_once("config.php"); //aggiunge un articolo al carrello if(isset($_POST["type"]) && $_POST["type"]=='add') { $product_code = filter_var($_POST["product_code"], FILTER_SANITIZE_STRING); //salva il product code $return_url = base64_decode($_POST["return_url"]); // salva il return url $_SESSION['test'] = $product_code; //MySqli query - prende le informazioni sull'oggetto dal db utilizzando il product_code $results = $mysqli->query("SELECT Nome,Prezzo FROM Articoli WHERE ID='$product_code' LIMIT 1"); $obj = $results->fetch_object(); if ($results) { //abbiamo le informazioni sugli articoli //prepara l'array per la sessione $new_product = array(array('name'=>$obj->Nome, 'code'=>$product_code, 'qty'=>1, 'price'=>$obj->Prezzo)); if(isset($_SESSION["products"])) //se la sessione esiste { $found = false; //setta found a false foreach ($_SESSION["products"] as $cart_itm) //scorre tutto l'array della sessione { if($cart_itm["code"] == $product_code){ //allora l'articolo è nell'array della sessione $qty = $cart_itm["qty"]+1; //aumenta la quantità dell'articolo $product[] = array('name'=>$cart_itm["name"], 'code'=>$cart_itm["code"], 'qty'=>$qty, 'price'=>$cart_itm["price"]); $found = true; }else{ //l'articolo non esiste, prendi le info vecchie e prepara l'array per la sessione $product[] = array('name'=>$cart_itm["name"], 'code'=>$cart_itm["code"], 'qty'=>$cart_itm["qty"], 'price'=>$cart_itm["price"]); } } if($found == false) //allora non abbiamo trovato l'articolo nell'array della sessione { //aggiungi un nuovo articolo nell'array della sessione $_SESSION["products"] = array_merge($product, $new_product); }else{ //abbiamo trovato l'articolo e abbiamo aumentato la quantità $_SESSION["products"] = $product; } }else{ //crea una nuova variabile sessione se non esiste $_SESSION["products"] = $new_product; } } //ritorna indietro alla pagina iniziale header('Location:'.$return_url); } //rimuovi un articolo dallo shopping cart if(isset($_GET["removep"]) && isset($_GET["return_url"]) && isset($_SESSION["products"])) { $product_code = $_GET["removep"]; //ottieni il codice prodotto dell'articolo da rimuovere $return_url = base64_decode($_GET["return_url"]); //ottieni l'url di ritorno foreach ($_SESSION["products"] as $cart_itm) //scorre tutto l'array della sessione { if($cart_itm["code"]==$product_code) //forse l'errore è qui { //allora l'articolo è nell'array della sessione $_SESSION['removing']=$cart_itm["code"]." ".$product_code; //continua solo se la quantità è >1 //rimuovendo quello che ha quantità 0 if($cart_itm['qty']>1) { $cart_itm['qty']-=1; } }else{ $product[] = array('name'=>$cart_itm["name"], 'code'=>$cart_itm["code"], 'qty'=>$cart_itm["qty"], 'price'=>$cart_itm["price"]); } //setta la sessione con i valori nuovi ----> PROBABILE ERRORE IN QUESTA SEZIONE <------ $_SESSION["products"] = $product; $product= array(); } //ritorna indietro header('Location:'.$return_url); } ?>
  7. Hi. I'm a php newbie and I just want to ask something. I have this simple Shopping Website, and I'm already done with the shopping cart which I learned from the phpacademy.org. Whenever the customer entered the final phase in ordering, I want all her orders to go to a table in my phpmyadmin database called 'transactions' so I can put up all the transactions made in one table. The problem is I cannot think of a way on how can I enter each item she ordered in the table. For example, she ordered 1 dress and 1 pants. Then these will be treated as 1 transaction right? But I want to save these to the table as 2. One row for pants and another for the dress. Can somebody help me? I'm really having a hard time. Thanks in advance!
  8. Hi All, I'm creating a shopping cart from following a tutorial online from TheTutSpace: http://www.youtube.com/watch?v=AKSkvZHJIEw&list=PLBA98B91CBF08F3A2 I have gotten up to the page where the cart should be displaying the products that have been added to the cart, and "Go To Cart" has been clicked. The page loads up correctly, however doesn't display any of the products that have been added to the cart. I know its storing them correctly as they are visible in the sidebar, they just aren't echoing out properly it seems. I have also ran var_dump on $sql and $query, both returning the results that are expected of them. The cart connects to the DB via a require_once which is located on my index.php so theres no issues there. I have attached the cart.php page (which seems to be the only issue) If you require more information, please do ask and i'll provide as much as i can! The section i THINK is the issue is: if(!empty($query)){ while($row = mysql_fetch_array($query)){ $subtotal = $_SESSION['cart'][$row['SKU']]['quantity']*$row['price']; $total_price += $subtotal; ?> <tr> <td><?php echo $row['name']; ?></td> <td><input type="text" name="quantity-<?php echo $row['SKU']; ?>" size="5" value="<?php echo $_SESSION['cart'][$row['SKU']]['quantity']; ?>" /></td> <td><?php echo "£" . $row['price']; ?></td> <td><?php echo "£" . $_SESSION['cart'][$row['SKU']]['quantity']*$row['price']; ?></td> </tr> <?php } }else { echo "<i>No Items founds to display!</i> "; } ?> I am new to PHP as you may have guessed, so please be kind cart.php
  9. Here is a snippet of the code for an assignment for my web programming class. I have to use PHP and JQuery to read a delimited text file and display the products in one row of a table. I have to use JQuery's toggle function to be able to show/hide details (price, image, and name) of a few products. Everything seemed to work until I started entering the JQuery code in the division. I have to use $productId as the id for the <div> and I seem to be having some trouble passing the variables to JQuery. I would appreciate any help anyone could offer as I'm at an impasse. I've attached a screenshot of the desired outcome. Thank you. echo "<h3>OUR PRODUCTS</h3>"; echo "<form name=\"shoppingCart\" action=\"checkOut.php\" method=\"post\"> <input type=\"button\" value=\"CHECK OUT\" onclick=\"document.shoppingCart.submit()\"> <input type=\"button\" value=\"MAIN MENU\" onclick=\"location='/'\"> <!--For aesthetic purposes only--> <button type=\"button\">INSTRUCTIONS</button> </form>"; echo "<p>Click a product name for details and to order it. After selecting products click CHECK OUT.</p>"; echo "<table>"; echo "<tr>";// open data file in read only mode $productsData = fopen("products.txt","r");// parse file in while loop and generate product info while(!feof($productsData)) { $row=fgets($productsData); $row=trim($row); $productArray = explode("^",$row); $productId = $productArray[0]; $productName = $productArray[1]; $productPrice = $productArray[2]; $productImageUrl = $productArray[3]; echo "<td width=\"220\" valign='top'>"; echo "<span style=\"font-weight: bold; font-size: 20px;\" onclick=\"$('#$productId').animate({height: 'toggle'}, 'slow' );\">$productName</span>"; echo "</td>"; echo "<td valign='top'> <div id=\"<?php echo($productId); ?>\" style=\"padding: 10px; display: none; font-weight: bold;\"> <img style=\"width: 200px;\" src=\"<?php echo($productImageUrl); ?>\"> <br> Send me: <select name=\"<?php echo($productId); ?>\"> <option value=\"0\">None</option> <option value=\"1\">1</option> <option value=\"2\">2</option> <option value=\"3\">3</option> </select> </div>"; echo "</td>"; };// close data file fclose($productsData);echo "</tr>"; echo "</table>";
  10. Hey guys and girls, I am currently following a book to create a PHP shopping cart and I am having trouble passing the data from a form to my cart script that add's the product to the cart. This is the products.php file which contains the form & action which is posting the data from the input forms 'product_qty', 'product_id', and 'req=add': <table width="100%" border="0" cellspacing="0" cellpadding="4"> <tr> <td colspan="2"> <a href="/newagedclothing/content/products.php?req=view&product_id=<?php echo $product_id; ?>"> <?php echo $product_title; ?> </a> </td> </tr> <tr> <td width="16%" align="left" valign="top"> <strong>Description:</strong></td> <td width="84%"> <?php echo $caption; ?> </td> </tr> <tr> <td align="left" valign="top"><strong>Price:</strong></td> <td> <?php echo $product_price; ?> </td><?php echo $product_id; ?> </tr> <tr> <td> </td> <td><form method="post" action="index.php?content=cart"> <strong>Add To Cart</strong> <input name="product_qty" type="text" value="1" size="2" /> <input type="hidden" name="req" value="add" /> <input type="hidden" name="product_id" value="<?php echo $product_id; ?>" /> <input type="submit" name="Submit" value="Go!" /> </form> </td> </tr> </table> <hr size="1"> This is the cart.php file: <?php $cart = &new ShoppingCart; $cart_id = $cart->get_cart_id(); switch($_REQUEST['req']){ case "add": $add2cart = $cart->cart_add($_REQUEST['product_id'], $_REQUEST['product_qty']); if(!$add2cart){ echo "<center>The product could not be ". "to your shopping cart. You may ". "have entered an invalid quantity. </center>" . $add2cart; } else { echo "<center>Item added to your shopping cart!<br />". "<a href=\"/cart.php\">View ". "your cart</a></center>"; } break; case "update": while(list($product_id, $qty) = each($_POST[qty])){ $sql = mysql_query("SELECT * FROM shopping_products WHERE product_id='$product_id'"); $row = mysql_fetch_assoc($sql); if($qty == 0){ mysql_query("DELETE FROM shopping_cart WHERE cart_identifier='$cart_id' AND product_id='$product_id'"); } if($qty > $row[product_qty]){ mysql_query("UPDATE shopping_cart SET product_qty='{$row[product_qty]}' WHERE cart_identifier='$cart_id' AND product_id='$product_id'"); $error = TRUE; $products[$product_id] = stripslashes($row[product_title]); } else { mysql_query("UPDATE shopping_cart SET product_qty='$qty' WHERE cart_identifier='$cart_id' AND product_id='$product_id'"); } } if($error){ echo "<center>You have selected more than our current stock for the following product(s): <br />"; while(list($product_id, $product_title) = each($products)){ echo "<a href=\"/products.php?req=view&product_id=$product_id\">$product_title</a><br />"; } echo "<br />"; echo "We have updated your quantity to the maximum value that we have in stock.</center><br />"; echo "<center><a href=\"/cart.php\">Back to cart</a></center>"; } else { header ("Location: /cart.php"); } break; case "remove": $sql = mysql_query("DELETE FROM shopping_cart WHERE cart_identifier='$cart_id' AND product_id='{$_REQUEST['product_id']}'"); header("Location: /cart.php"); break; case "empty_confirm": echo "<center>Are you sure you want to empty your cart?<br />". "<a href=\"cart.php?req=empty\">Yes</a>". " | ". "<a href=\"/cart.php\">No</a></center>"; break; case "empty": $cart->empty_cart(); echo "<center>Your cart has been emptied!</center>"; break; default: if($cart_id){ $num_items = mysql_result(mysql_query("SELECT COUNT(*) as items FROM shopping_cart WHERE cart_identifier='$cart_id'"),0); if($num_items == 0){ echo "<center>Your shopping cart is empty!</center>"; exit(); } } else { echo "<center>Your shopping cart is empty</center>"; exit; } ?> <p>Your shopping cart</p> <p>This page allows you to modify or empty your shopping cart contents. Simply change the number of each product you wish to purchase and select the "update cart" link at the bottom.</p> <form name="update" method="post" action="/cart.php"> <table> <tr> <td>Qty</td> <td>Product</td> <td align="right">Price</td> <td align="right">Product Total</td> </tr> <?php $total = mysql_result(mysql_query("SELECT sum(product_qty * product_price) AS subtotal FROM shopping_cart WHERE cart_identifier='$cart_id'"), 0); $total = number_format($total, 2); $sql = mysql_query("SELECT * FROM shopping_cart WHERE cart_identifier='$cart_id'"); while ($row = mysql_fetch_array($sql)) { $product_total = number_format(($row[product_qty] * $row[product_price]), 2); echo "<tr><td><input type=\"text\" " . "name=\"qty[$row[product_id]]\" " . "size=\"2\" value=\"$row[product_qty]\" />" . "<br /><a href=\"/cart.php?req=remove&" . "product_id=$row[product_id]\">" . "Remove</a>" . "</td>" . "<td><a href=\"/products.php?req=view&product_id=$row[product_id]\">" . stripslashes($row[product_title]) . "</a></td>" . "<td align=\"right\">\$$row[product_price]</td>" . "<td align=\"right\">\$$product_total</td>" . "</tr>"; } ?> <tr> <td colspan="2"> </td> <td align="right">Total:</td> <td align="right">$<?=$total ?>< /td> </tr> <tr> <td colspan="4" align="center"> <a href="javascript:void(document.update.submit())">Update Cart</a> | <a href="/cart.php?req=empty_confirm">Empty Cart</a> | <a href="/products.php">Continue shopping</a> | <a href="/checkout.php">Checkout</a> </td> </tr> </table> </form> <?php break; } ?> Here is the add_cart function: function cart_add($product_id, $product_qty){ $cart_id = $this->get_cart_id(); if(!$cart_id){ //if no cart id found, generate one $unique_cid = md5(uniqid(rand(),1)); //set cart id into cookie setcookie('cid', $unique_cid, time()+24*3600*60); //Register session with cart id value $_SESSION['cid'] = $unique_cid; //if persion is a member //modify their profile with //cart id in the database if($_SESSION['login']){ $_SESSION['cid'] = $unique_cid; @mysql_query("UPDATE members SET cart_id='$unique_cid' WHERE id='".$_SESSION['userid']."'"); } }//end generate unique id $sql_get_product = mysql_query("SELECT * FROM shopping_products WHERE product_id='$product_id'"); $sql_check = mysql_query("SELECT * FROM shopping_cart WHERE cart_identifier='{$_SESSION['cid']}' AND product_id='$product_id'"); while($row = mysql_fetch_array($sql_check)){ $products = mysql_fetch_assoc($sql_get_product); if(($product_qty + $products[product_qty]) > $products[product_qty]){ $new_qty = $products[product_qty]; } else { $new_qty = ($product_qty + $row[product_qty]); } $sql = mysql_query("UPDATE shopping_cart SET product_qty='$new_qty', date = now() WHERE id='{$row['id']}'"); $skip = TRUE; } if(!$skip){ $products = mysql_fetch_assoc($sql_get_product); if($products[product_qty] < $product_qty){ $product_qty = $products[product_qty]; } if($product_qty > 0){ $sql = mysql_query("INSERT INTO shopping_cart (cart_identifier, product_id, product_title, product_qty, product_price, date) VALUES ('{$_SESSION['cid']}', '$product_id', '{$products['product_title']}', '$product_qty','{$products['product_price']}', now())"); } else { $sql = FALSE; } } if(!$sql){ return FALSE; } else { return TRUE; } }//end cart_add() My problem is that whenever I click the 'add' button to send the data across it seems like it isn't being sent correctly. I'm am a bit unsure on how to structure the url for the submit button and I think it's to do with that. These pages are being controlled around my index.php file and the products page url looks like this, 'index.php?content=products'. All my content files are in a folder named 'content'. Please ask for any other questions to aid my assistance. Much appreciated ! Sam
  11. Hi guys, I am working on e-commerce application design project for my university assignment and I need some help with pseudocode to get me started. Here is the diagram: upload foto If someone can help would be great! Raddy
  12. Trying to create a shopping cart that allows user to select not only the product, but the condition of the item (poor condition, good condition, excellent condition), and additional accessories based on the form data submitted. Basically, I'd like to use the same ID for a product with different conditions and accessories. Just not sure how to get there. Any help, advice, or resources is much appreciated! Thank you. Here is the form data I'm collecting from the user: // Phone Type $field_Phone = $_POST['field_Phone'] = $_SESSION['field_Phone']; // Accessories $field_Charger = $_POST['field_Charger'] = $_SESSION['field_Charger']; $field_Case = $_POST['field_Case'] = $_SESSION['field_Case']; $field_Manual = $_POST['field_Manual'] = $_SESSION['field_Manual']; $field_Box = $_POST['field_Box'] = $_SESSION['field_Box']; // Item Condition $field_Condition = $_POST['field_Condition'] = $_SESSION['field_Condition']; Here's the item from the database: <?php // DB Query $query = "SELECT * FROM phones WHERE name = '{$field_Phone}'"; $result = mysql_query($query); while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $output[] = '<a href="cart-demo/cart.php?action=add&id='.$row['id'].'">Add to cart</a>'; } ?> Here's the functions that output the product selected: <?php function writeShoppingCart() { $cart = $_SESSION['cart']; if (!$cart) { return 'Cart (Empty)'; } else { // Parse the cart session variable $items = explode(',',$cart); $s = (count($items) > 1) ? 's':''; return 'Cart (<a href="cart-demo/cart.php">'.count($items).'</a>)'; } } 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 phones 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>" .$name. "</td>"; $output[] = "<td><img src=\"../images/catalog-images/" .$photo_image. "\" width=\"50\"/></td>"; $output[] = "<td> ".$_SESSION['accessories']." </td>"; $output[] = '<td> $ '.$price.'</td>'; $output[] = '<td><input type="text" name="qty'.$id.'" value="'.$qty.'" size="3" maxlength="3" /></td>'; $output[] = '<td> $'.($base_price * $qty).'</td>'; $total += $base_price * $qty; $output[] = '</tr>'; } $output[] = '</table>'; $output[] = '<p>Grand total: <strong>$ '.$total.'</strong></p>'; $output[] = '<div><button type="submit">Update cart</button></div>'; $output[] = '</form>'; } else { $output[] = '<p>You shopping cart is empty.</p>'; } return join('',$output); } ?> Here's the cart code: $cart = $_SESSION['cart']; $action = $_GET['action']; $_SESSION['accessories']; switch ($action) { case 'add': if ($cart) { $cart .= ','.$_GET['id']; } else { $cart = $_GET['id']; } break; case 'delete': if ($cart) { $items = explode(',',$cart); $newcart = ''; foreach ($items as $item) { if ($_GET['id'] != $item) { if ($newcart != '') { $newcart .= ','.$item; } else { $newcart = $item; } } } $cart = $newcart; } break; case 'update': if ($cart) { $newcart = ''; foreach ($_POST as $key=>$value) { if (stristr($key,'qty')) { $id = str_replace('qty','',$key); $items = ($newcart != '') ? explode(',',$newcart) : explode(',',$cart); $newcart = ''; foreach ($items as $item) { if ($id != $item) { if ($newcart != '') { $newcart .= ','.$item; } else { $newcart = $item; } } } for ($i=1;$i<=$value;$i++) { if ($newcart != '') { $newcart .= ','.$id; } else { $newcart = $id; } } } } } $cart = $newcart; break; } $_SESSION['cart'] = $cart;
  13. I am mid install on ZenCart for one of my clients, but I have to admit that this is my first time installing an eCommerce shopping system. That having been said, I am having serious doubts about my choice. ZenCart appears to be very common, but I thought I would call on a much more experienced community (YOU!!!! yay!) for some guidance: - I need a scripted site where I can add products, prices, descriptions, etc - The site template needs to be easily customizable - I need to be able to integrate PayPal payments (credit cards) - Users are able to purchase products using a credit card WITHOUT registering any accounts Is ZenCart the right choice? If there is something much better, at a reasonable price, I am willing to pay ... TIA!
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.