I am working on creating a shopping cart. This is a good learning experience (I am a novice) for me regarding oop but I have ran into a road block, "brain fart" or just plain stymied and need some help.
I have a Cart and Cart_Item class. I create a Cart object using a Cart_Item object. I am now working on the code to display the cart contents. I am confused on how to call the attributes of the Cart_Item object inside the Cart object. (If I am not saying this right please correct me.)
I know about accessor or mutator methods but how do I write them to get an attribute of the Cart_Item out of the Cart object?
Here are parts of both classes.
class Cart_Item
{
var $inumber;
var $name;
var $quant;
var $price;
var $descr;
var $gtotprice;
function Cart_Item(&$inumber,&$name,&$quant,&$price,&$descr)
{
$this->_init();
$this->inumber = $inumber;
$this->name = $name;
$this->quant = sprintf("%d", $quant);
$this->price = sprintf("%0.4f", $price);
$this->descr = $descr;
$this->_calc();
}
class CART
{
var $items;
var $gtotprice;
function CART()
{
$this->_init();
}
function add($inumber,$name,$quant,$price,$descr)
{
if(!is_object($this->items[$inumber]))
{
$this->items[$inumber] = new Cart_Item($inumber,$name,$quant,$price,$descr);
$this->_refresh();
}
}
Your help would be greatly appreciated.
Thanks in advance,
Alex 😕