Hello all.
I don’t even know where to start with this one.
I’m in process of finishing a cart script and I am having trouble figuring out how to get the "add to cart" script to check to see if an item exist before adding a new item to an array.
Currently the item is passed through variables to the add_cart.php page. The add cart page then sets and adds a variable for quantity to 1, adds all of the variable to an array that is placed into the session, before moving on to the show cart page.
What I need to do is have to script search for a existing ID that matches what the new item is and only increment the qty variable of the array.
Here are the variables being passed
$id
$item_name
$price
And here is my code for adding to the basket array.
if ($add_item)
{
$qty = 1;
$t_price = ($qty * $price);
$_SESSION['basket'][] = array ( id => "$id",
item_name => "$item_name",
price => "$price",
qty => "1",
t_price => "$t_price");
}
As I said I don’t know where to start with this one. I haven’t found anything relating editing arrays yet but answering this should help me figure out on my own on how to delete a line from the array by id, and changing a quantity. Both of those being accessible by the basket view page.
Any help is greatly appreciated.
G