Jump to content

PHP Shopping cart, 19 item limit!!


Andy2024

Recommended Posts

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

Link to comment
Share on other sites

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"];

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.