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:
Code: Select all
$_SESSION['cart']['itemNumber'] = $itemNumber;
$_SESSION['cart']['itemQty'] = $itemQty;
$_SESSION['cart']['itemDesc'] = $itemDesc;
$_SESSION['cart']['itemPrice'] = $itemPrice;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:
Code: Select all
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'];Thanks!