CodeIgniter Forums
Cart class problem - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: Cart class problem (/thread-47589.html)



Cart class problem - El Forum - 12-14-2011

[eluser]Perkin5[/eluser]
i am designing a website with a shopping cart and it works perfectly on my wamp server locally. Unfortunately it throws an error when uploaded onto an online server.

Fatal error: Call to undefined method CI_Cart::total_quantity() etc


You can see the error if you go to:

http://www.historystore.co.uk/new/shop/ephemera

and click Add to Cart for any item. The session cookie is definitely created and seems to be fine but the error goes if I delete the cookie.

The database seems to be fine as the test items on the page are all generated from a model query.

Add to Cart links to a method called add which looks like this:

Code:
function add() {

  $this->load->model('Products_model');
  
  $product = $this->Products_model->get_item($this->input->post('id'));
  
  $insert = array(
   'id' => $this->input->post('id'),
   'qty' => 1,
   'name' => $product->name,
   'price' => $product->price
  );
  
  $this->cart->insert($insert);

  redirect('shop/ephemera');
}

The actual error is thown by the telltale cart panel in the page header and the code looks like this:

Code:
<?php if ($cart = $this->cart->contents()): ?>
<table>
  <tr>
    <td class="mycart">My Shopping Cart</td>
  </tr>
  <tr>
    <td class="items">&lt;?php echo $this->cart->total_quantity(); ?&gt; Items in cart</td>
  </tr>
  <tr>
    <td><span>Total:</span> £&lt;?php echo $this->cart->total(); ?&gt;</td>
  </tr>
</table>
&lt;?php else: ?&gt;
  <h3>Shopping Cart is empty</h3>
&lt;?php endif; ?&gt;

total_quantity() is my own method to deliver the total number of items allowing for multiple quantities.

Like I say, it all works fine locally. I would be very grateful if amyone could suggest where it might be going wrong online.