Wrox Programmer Forums
|
BOOK: Professional CodeIgniter ISBN: 978-0-470-28245-8
This is the forum to discuss the Wrox book Professional CodeIgniter by Thomas Myer; ISBN: 9780470282458
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional CodeIgniter ISBN: 978-0-470-28245-8 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 3rd, 2008, 07:36 AM
Registered User
 
Join Date: Nov 2008
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Adding products to a shoping cart

When I try to add a product jumps: Fatal error: Call to a member function updateCart() on a non-object in C:\Program Files\VertrigoServ\www\tutor\system\application\co ntrollers\tutor.php on line 65
Controleer:
Code:
function cart($productid){
      if ($productid > 0){

      $fullproduct = $this->Mproducts_model->getProduct($productid);
65    $this->Morders_model->updateCart($productid,$fullproduct);
      redirect('tutor/product/'.$productid, 'refresh');
      }else{
        $dadta['title'] = "lol | Shopping Cart";
        if(count($_SESSION['cart']) == true){
          $data['main'] = '';
          $nav['navlist'] = $this->Mcats_model->getCategoriesNav();
          $this->load->vars($data);
          $this->load->view('template');
        }else{
          redirect('tutor/index','refresh');
        }
      }
    }

Model:
Code:
<?php
Class Morders_model extends Model{
  function Morders_model(){
    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.");
        }
   }
}
?>
Help Me Please.

 
Old November 8th, 2008, 07:57 AM
Friend of Wrox
 
Join Date: Oct 2007
Posts: 130
Thanks: 0
Thanked 3 Times in 3 Posts
Send a message via AIM to urtrivedi
Default

Have you declared object for you class

$myobj=new Morders_model()
$myobj.updatecart();

are you doing in above manner. if you are calling updatecart directly then it may not work.

urt

Help yourself by helping someone.
 
Old November 27th, 2008, 08:36 AM
Registered User
 
Join Date: Nov 2008
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

could you please explain more what you mean by comment above as its not in the book and i'm quite new to code igniter

 
Old December 18th, 2008, 07:04 AM
Registered User
 
Join Date: Dec 2008
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Check that you have loaded the model

Hi,

Perhaps you haven't loaded the Morders model properly. Did you add it to the autoload.php config (as the book says) or you could use the $this->load function in the constructor of the controller.

Steve
 
Old March 16th, 2009, 10:15 AM
Wrox Author
 
Join Date: May 2008
Posts: 53
Thanks: 0
Thanked 5 Times in 5 Posts
Default

I believe the class is MOrders (case sensitive!), not Morders. That's where the problem is.
__________________
Thomas Myer
Author, Professional CodeIgniter
http://www.tripledogs.com





Similar Threads
Thread Thread Starter Forum Replies Last Post
Adding products to webshop not working. mcarol44 BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6 21 July 28th, 2011 09:09 AM
My own shoping cart Lofa PHP Databases 1 June 1st, 2008 08:04 AM
Adding Color and Size parameters to WEBSHOP Cart. DJPrice BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6 3 March 10th, 2008 01:39 PM
problem whit shoping card mbcreator PHP How-To 0 February 17th, 2006 05:51 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.