hi people...
i've been playing with php, and we have a huge shopping cart system happening at the moment.
i was wondering how good the session is in php?
because...
we have in the session an order object.
in the order object is a cart array, which is an associative array of product objects, all the products in the order.
however, the product objects don't seem to persist through the session, ie the products only exist on the page when they are added.
here is some of the code, if you are interested:
code:
// constructor
function Order ($id=0,$status="",$cart="",$cust_firstname="None",$cust_lastname="",$cust_id="",$address="",$suburb="", $postcode="",$state="",$comment="",$card_name="",$card_num="", $card_exp="") {
$this->id = $id;
$this->status=$status;
$this->cart = array();
$this->cust_firstname = $cust_firstname;
$this->cust_lastname = $cust_lastname;
$this->cust_id = $cust_id;
$this->address = $address;
$this->suburb = $suburb;
$this->postcode = $postcode;
$this->state = $state;
$this->comment = $comment;
$this->card_name = $card_name;
$this->card_num = $card_num;
$this->card_exp = $card_exp;
return true;
}
/* Adds a product to the shopping cart */
function add_product ($id, $qty) {
$new_product = false;
if (Update_res_qty($id,$qty)) {
global $Product;
$prod = product_search_by_id($id);
$name = $prod[$Product[name]] . " " . $prod[$Product[colour]] . " " . $prod[$Product[size]];
$new_product = new Product($id,$qty,$prod[$Product[brand]], $prod[$Product[sale_price]],$name);
$this->cart[$new_product->id] = $new_product;
}
return $new_product;
}
/* product class - This classtakes care of the
* individual products in each order
*/
class Product {
var $id;
var $qty;
var $brand;
var $sale_price; // Price each product is sold for after discount applied.
var $name;
function Product($_id, $_qty = 1, $_brand, $_sale_price = 0, $_name = "") {
$this->id = $_id;
$this->qty = $_qty;
$this->brand = $_brand;
$this->sale_price = $_sale_price;
$this->name = $_name;
return true;
}
/* function show() {
$str = "<td>$this->id</td>
<td>$this->name</td>
<td>$this->sale_price</td>
<td>$this->qty</td>";
return $str;
}*/
function set_id ($id) {
$this->id = $id;
return true;
}
function set_qty ($qty) {
$this->qty = $qty;
return true;
}
function set_sale_price($price) {
$this->sale_price = $price;
return true;
}
function set_name($name) {
$this->name = $name;
return true;
}
function amount() {
$tmp = number_format($this->qty * $this->sale_price,2);
return $tmp;
}
}
if anyone has any ideas as to why this doesn't work, that would be muchly appreciated!
cheers.
___________________
b u n c h a p i x e l s