Hi all,
I'm strugling a bit here to get this sessions based shopping cart code to work. I have looked at and installed zencart as an option, but it was way overkill (IMHO) for what I need. Basically, I'm looking to have items added to a user's session and keep track of the info in a db as well (the db part isn't an issue for me).
Here's what I'm looking to track and be able to display in the user's 'cart' page:
$_SESSION['cart']['itemNumber'] = $itemNumber;
$_SESSION['cart']['itemQty'] = $itemQty;
$_SESSION['cart']['itemDesc'] = $itemDesc;
$_SESSION['cart']['itemPrice'] = $itemPrice;
What i'm having an issue with is when more than one item is added, or existing item(s) updated. I can only get 1 item and it's info there to be displayed.
the code snippet below is total junk, and has been hacked at for some time now...but this is the sort of thing I've been trying:
session_start();
if ($cartAction == "add" && ($_SESSION['cart']['c_itemNumber'])) {
$tempCartItemNumber = "";
foreach ($_SESSION['cart']['c_itemNumber'] as $cItNu) {
if ($cItNu != $itemNumber) {
$tempCartItemNumber = ",".$itemNumber;
} else {
$tempCartItemNumber .= $cItNu;
}
}
} else {
$_SESSION['cart']['c_itemNumber'] = $itemNumber;
}
echo $_SESSION['cart']['c_itemNumber'];
So, at this point, what I would like to do is find a straight forward tutorial on how to build a 'basic' shopping cart that would mimic (if possible) the $_SESSION['cart']['items'] method. Once I can get the add,update,delete session stuff to work....I'll be able to integrate the db part into it. Googling this sort of thing returns thousands of results that i've tried to check out, but haven't found anything besides the complex session cart stuff (like zencart) or the super basic stuff like how to start and destroy a session. Would anyone be able to provide a link to such a tutorial for like what I'm trying to do? It would be greatly appreciated.
Thanks!