Andy2024 Posted April 24 Share Posted April 24 Ive modified the Simple PHP Shopping Cart from the phppot site but for some reason when the cart reaches 19 items it wont add anything else to it and i dont know why. Is their a limit within php how long a session array can be? Here is the code that adds each item to the array $cartItems = Session::get("cart_item"); $itemArray = array( 'ItemDesc' => $_POST["ItemDesc"], 'ItemCode' => $_POST["ItemCode"], 'ItemQty' => $_POST["ItemQty"], 'ItemAmount' => $_POST["ItemAmount"], 'ItemTotalAmount' => ($_POST["ItemQty"] * $_POST["ItemAmount"]), 'IdSupplier' => $_POST["IdSupplier"]); if(!empty($cartItems)) { if(in_array($itemArray["ItemCode"],array_keys($cartItems))) { foreach($cartItems as $k => $v) { if($itemArray["ItemCode"] == $k) { if(empty($cartItems[$k]["ItemQty"])) { $cartItems[$k]["ItemQty"] = 0; } $cartItems[$k]["ItemQty"] += $_POST["ItemQty"]; } } } else { $cartItems[] = array_merge($cartItems,$itemArray); } } else { $cartItems[] = $itemArray; } Session::set("cart_item", $cartItems); $counter = count(Session::get("cart_item")); Any help or suggestions would be greatly appreciated Quote Link to comment https://forums.phpfreaks.com/topic/320104-php-shopping-cart-19-item-limit/ Share on other sites More sharing options...
mac_gyver Posted April 24 Share Posted April 24 the limitation is probably in the get or set session methods or in the code displaying or processing the cart. this code is overly complicated. the only data that should be stored in the cart is the quantity and the item id (itemCode) should be used as the cart's array index. once you index the data using the id, you can directly find, test, or reference the data. no looping required. the following is the only code needed to add an item to the cart once you do this - // add to cart code if(!isset($cartItems[$_POST['ItemCode']])) { // if an item isn't in the cart, add it with zero quantity $cartItems[$_POST['ItemCode']] = 0; } // add the submitted quaitity to the cart $cartItems[$_POST['ItemCode']] += $_POST["ItemQty"]; Quote Link to comment https://forums.phpfreaks.com/topic/320104-php-shopping-cart-19-item-limit/#findComment-1622369 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.