here is all the code
<?php
class product / PRODUCT CLASS /
{
private $product_name;
private $description;
private $price;
public function __construct($name, $desc, $price)
{
$this->product_name = $name;
$this->description = $desc;
$this->price = $price;
}
public function get_product_name()
{
return $this->product_name;
}
public function get_price()
{
return $this->price;
}
}/ PRODUCT CLASS END/
class product_config extends product / PRODUCT CONFIG CLASS /
{
private $storage = array();
// overwrite the parent's constructor
public function __construct()
{
}
function set_product($name, $desc, $price)
{
$this->storage[] = new product($name, $desc, $price);
}
function test()
{
echo $this->storage[0]->get_product_name();
}
function render_products()
{
if(!$this->storage)
{
return 'There are no products in storage!';
}
else
{
foreach($this->storage as $value)
{
echo $value->get_product_name()." ".$value->get_price()."</br>";
}
echo $total = $value->get_product_name() + $value->get_price();
}
}
}/ PRODUCT CONFIG CLASS END /
class cart_manager { / CART MANAGER /
private $sql_con;
private $cart = array();
private $total;
function __construct($products)
{
$this->total = 0;
foreach($products as $value)
{
$this->total += $value->price;
}
}
function get_total() {
return $this->total;
}
function cart_insert($products){
$this->total = 0;
foreach($products as $value){
$this->total += $value->price;
}
}
function display_cart(){
foreach ($this->cart as $product){
echo $product."<br/>";
}
}
}
?>
here are a few values to display
<?php
$insert->set_product('candy','tasty',10.99);
$insert->set_product('ice cream,'tasty!!',10.99);
echo $insert->render_products();
$cart = new cart_manager($insert);
?>
<?php echo $cart->get_total(); ?>
I still get the outcome of 0.