Welcome Guest, Not a member yet? Register   Sign In
code igniter sessions not working with cart class
#11

[eluser]dazamate[/eluser]

Code:
$return = $this->cart->insert($item);

This is just some stray code left behind, I just wanted to see what value that was being returned after the item was added. I do nothing with the $return value now, I just printed it before.

$this->cart->contents() is meant to return the carts contents...

I've
Code:
print_r($this->cart->contents());
in the Addtocart function to check if the item was added to the cart properly, it is I get the item returned back to me.

Now when I go to the Showcart page and the Showcart function is called I do the same thing. I should get the item returned back to me... but all I am getting is an empty array. Why isn't the cart holding any data?
#12

[eluser]DarkManX[/eluser]
Post the cart library pls - well, just contents() and insert() needed.
#13

[eluser]alvaroeesti[/eluser]
on watching the video I can see that he has another table for Products also already built, to and from he was inserting and selecting the values. While yes, using the cart class was directly doing it bypassing the model, you haven't built your products table, have you ?
#14

[eluser]dazamate[/eluser]
No I haven't made the products table, but I can't make sense on why I need to. I don't need to get any data out of the db yet, I've just manually inserted my own cart item in the code as you can see which mimics what a db model would of returned anyway.

He has already pre build a Products table but at this stage the code doesn't need a Db, he has just done that in preparation for the video right?

Are you going to tell me if I make a product table everything will work lol?
#15

[eluser]DarkManX[/eluser]
-
#16

[eluser]dazamate[/eluser]
Sorry DarkManX, I didn't see your post.

Here is the code you've requested.

Code:
function insert($items = array())
{
  // Was any cart data passed? No? Bah...
  if ( ! is_array($items) OR count($items) == 0)
  {
   log_message('error', 'The insert method must be passed an array containing data.');
   return FALSE;
  }

  // You can either insert a single product using a one-dimensional array,
  // or multiple products using a multi-dimensional one. The way we
  // determine the array type is by looking for a required array key named "id"
  // at the top level. If it's not found, we will assume it's a multi-dimensional array.

  $save_cart = FALSE;
  if (isset($items['id']))
  {
   if (($rowid = $this->_insert($items)))
   {
    $save_cart = TRUE;
   }
  }
  else
  {
   foreach ($items as $val)
   {
    if (is_array($val) AND isset($val['id']))
    {
     if ($this->_insert($val))
     {
      $save_cart = TRUE;
     }
    }
   }
  }

  // Save the cart data if the insert was successful
  if ($save_cart == TRUE)
  {
   $this->_save_cart();
   return isset($rowid) ? $rowid : TRUE;
  }

  return FALSE;
}

// --------------------------------------------------------------------

/**
  * Cart Contents
  *
  * Returns the entire cart array
  *
  * @access public
  * @return array
  */
function contents()
{
  $cart = $this->_cart_contents;

  // Remove these so they don't create a problem when showing the cart table
  unset($cart['total_items']);
  unset($cart['cart_total']);

  return $cart;
}

I haven't touched any of this code Darkman, this is a fresh install from the codeigniter.org site.

Looking forward to hearing back what you find.
#17

[eluser]DarkManX[/eluser]
Well, didnt know there is an internal cart library. oO Now i do! Wink
Did you try to just save values in the session? Does it work?

Try this:
Code:
echo "<pre>",print_r($this->cart->_cart_contents),"</pre>";
#18

[eluser]dazamate[/eluser]
Hey Darkman

I still get an empty results

when I print cart_contents I get

Array ( [cart_total] => 0 [total_items] => 0 )
1

Seriously this is the straight out of the box setup, this should work. Such a basic thing causing me so much problems.
#19

[eluser]dazamate[/eluser]
Hey guys I fixed it.

I uninstalled xampp and reinstalled the latest version. Downloaded CI again and started from scratch and now it's working.

Might of been a bad xampp install on my computer, very frustrating. Thanks for your time and efforts though guys.




Theme © iAndrew 2016 - Forum software by © MyBB