[eluser]clintonbeattie[/eluser]
Hi,
I have run into another error while building a shopping cart. Apologies for these posts but I think once I get a good grounding in what these errors mean they will help in future projects.
Code:
A PHP Error was encountered
Severity: Notice
Message: Undefined property: Welcome::$MOrders
Filename: controllers/welcome.php
Line Number: 67
Fatal error: Call to a member function updateCart() on a non-object in C:\xampp\htdocs\codeigniter\system\application\controllers\welcome.php on line 67
Line 67 is referring to this "$this->MOrders->updateCart($productid,$fullproduct);"
Here is my updatecart model...
Code:
class MOrders extends Model {
function MOrders() {
parent::Model();
}
function updateCart($productid,$fullproduct) {
//pull in existing cart first!
$cart = $_SESSION['cart'];//$this->session->userdata('cart');
$totalprice = 0;
if (count($fullproduct)){
if (isset($cart[$productid])){
$prevct = $cart[$productid]['count'];
$prevname = $cart[$productid]['name'];
$prevprice = $cart[$productid]['price'];
$cart[$productid] = array(
'name' => $prevname,
'price' => $prevprice,
'count' => $prevct + 1
);
} else {
$cart[$productid] = array(
'name' => $fullproduct['name'],
'price' => $fullproduct['price'],
'count' => 1
);
}
foreach ($cart as $id => $product){
$totalprice += $product['price'] * $product['count'];
}
$_SESSION['totalprice'] = ($totalprice);
//$this->session->set_userdata('totalprice', $totalprice);
$_SESSION['cart'] = $cart;
//$this->session->set_userdata('cart',true);
$this->session->set_flashdata('conf_msg', "We've added this product to your cart.");
}
}
}
and this is my updatecart function in my 'welcome' controller...
Code:
function cart($productid=0){
if ($productid > 0){
//$productid = $this->uri->segment(3);
$fullproduct = $this->MProducts->getProduct($productid);
$this->MOrders->updateCart($productid,$fullproduct);
redirect('welcome/product/'.$productid, 'refresh');
} else {
$data['title'] = "Claudia's Kids | Shopping Cart";
if (count($_SESSION['cart'])){
$data['main'] = 'shoppingcart';
$data['navlist'] = $this->MCats->getCategoriesNav();
$this->load->vars($data);
$this->load->view('template');
} else {
redirect('welcome/index','refresh');
}
}
}
The session library has been autoloaded and the session_start() implemented. Can anyone shed any light on this?
Thanks again. You've been great so far.
C