I am trying to create a shopping cart application. My cart is a class, registered as a session variable. The class has a variable $items which is a multidimensional array containing the productid and another array containing the detail info about the item. It works fine adding an item. However, when I add additional items, each one just overwrites the array instead of appending a new element.
Here's the basic code:
Class Cart
{
var $items;
var $product_total;
var $shipping_total;
var $tax_total;
var $cart_id;
function add($sell_price,$qty,$shipping,$tax,$productid,$short_desc,$note)
{
if (isset($this->items[$productid])) //if it is already in the cart, don't add a new occurence, just update the total quantity
{
$this->items[$productid]["quantity"] += $qty;
}
else
{
$this->items[$productid]=array(
"price"=>$sell_price,
"quantity"=>$qty,
"shipping"=>$shipping,
"tax"=>$tax,
"desc"=>$short_desc,
"note"=>$note);
$this->product_total = $this->product_total += $sell_price;
$this->shipping_total = $this->shipping_total += $shipping;
}
} //end add
This whole multidimensional array has been giving me fits, but I think it's the best solution to this problem (if I can get it to work!)
Any thoughts on the subject?
Thanks,
Sheila