The_Dude_1978 Posted July 25, 2012 Share Posted July 25, 2012 Hi There, Would someone please help me out with disabling my quantity function and let me be able to add the same product twice each on a new row (item)? These are my first 2 functions: function createCart() { //Create a new cart as a session variable with the value being an array $_SESSION['paypalCart'] = array(); } function insertToCart($productID, $username, $thumbnail, $title, $price, $qty = 1) { //Function is run when a user presses an add to cart button //Check if the product ID exists in the paypal cart array if(array_key_exists($productID, $_SESSION['paypalCart'])) { //Calculate new total based on current quantity $newTotal = $_SESSION['paypalCart'][$productID]['qty'] + $qty; //Update the product quantity with the new total of products $_SESSION['paypalCart'][$productID]['qty'] = $newTotal; } else { //If the product doesn't exist in the cart array then add the product $_SESSION['paypalCart'][$productID]['item'] = $productID; $_SESSION['paypalCart'][$productID]['username'] = $username; $_SESSION['paypalCart'][$productID]['thumbnail'] = $thumbnail; $_SESSION['paypalCart'][$productID]['name'] = $title; $_SESSION['paypalCart'][$productID]['price'] = $price; $_SESSION['paypalCart'][$productID]['qty'] = $qty; } } And this is my function to get the shopping cart but with Toevoegen/Verwijderen (read add/delete) the quantity items. function getShoppingCart() { //Function creates the display for the cart //If the cart exists then follow on if(cartExists()) { //Check if there are any products in the cart by counting the array keys if(count($_SESSION['paypalCart']) > 0) { //The table header html $html = ' <table cellpadding="0" cellspacing="0" border="0"> <tr> <th>Thumbnail</th> <th>Item naam</th> <th>Prijs</th> <th>Hoeveelheid</th> <th></th> </tr> '; $count = 1; //Loop through the items in the paypal cart foreach($_SESSION['paypalCart'] as $product) { $html .= ' <tr> <td width="250"><img src='.$product['username'].'/pics/thumbs/'.$product['thumbnail'].'></td> <td width="200">'.$product['name'].'</td> <td width="200">€'.number_format($product['price'], 2).'</td> <td width="250">'.$product['qty'].'</td> <td width="200"><a href="addToCart.php?item='.$product['item'].'">Toevoegen</a> / <a href="removeFromCart.php?item='.$product['item'].'">Verwijderen</a></td> <input type="hidden" name="amount_'.$count.'" value="'.$product['price'].'" /> <input type="hidden" name="quantity_'.$count.'" value="'.$product['qty'].'" /> <input type="hidden" name="tax_rate_'.$count.'" value="'.TAX.'" /> <input type="hidden" name="item_name_'.$count.'" value="'.stripslashes($product['name']).'" /> <input type="hidden" name="item_number_'.$count.'" value="'.$product['item'].'" /> </tr> '; $count++; } //HTML for the subrows such as the subtotal, tax and total $html .= ' <tr class="empty"> <td></td> <td></td> <td></td> <td></td> <td></td> </tr> <tr> <td></td> <td></td> <td></td> <td class="bold">Subtotaal</td> <td>'.calculateSubtotal().'</td> </tr> <tr> <td></td> <td></td> <td></td> <td class="bold">'.TAX.'% BTW</td> <td>'.calculateTax().'</td> </tr> <tr> <td></td> <td></td> <td></td> <td class="bold">Totaal</td> <td>'.calculateTotal().'</td> </tr> </table> '; echo $html; } else { //If there are no products then print out a message saying there are no products echo '<p>Er zijn momenteel geen producten in uw winkelwagen.</p>'; unset($_SESSION['paypalCart']); } } else { //If there are no products then print out a message saying there are no products echo '<p>Er zijn momenteel geen producten in uw winkelwagen.</p>'; unset($_SESSION['paypalCart']); } } I hope you can help me out, because i'm really stuck here. Kind regards, Martijn Quote Link to comment https://forums.phpfreaks.com/topic/266248-how-do-i-remove-my-quantity-function-and-add-same-product-twice-with-options/ 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.