Welcome Guest, Not a member yet? Register   Sign In
Cart insert not working
#1

[eluser]NachoLabs[/eluser]
Code:
$this->db->where('id',$this->input->post('id'));
$q = $this->db->get('items')->row();
$item = array(
    'id'      => (string) $q->id,
    'qty'     => (int) 1,
    'price'   => (float) $q->precio,
    'name'    => (string) $q->nombre);
$this->cart->insert($item);

This is not working, the cart remains empty every time. Why?
#2

[eluser]Clooner[/eluser]
Could be several things. Are you able to retrieve normal cookies and sessions? Do you get any errors? Is the item array filled correctly?
#3

[eluser]NachoLabs[/eluser]
Sessions work fine. There aren't any errors. Running this:
Code:
print_r($item); print_r($this->cart->contents());
i get this:
Code:
Array ( [id] => 15 [qty] => 1 [price] => 8 [name] => Artà culo Ejemplo ) Array ( )
#4

[eluser]Clooner[/eluser]
Have you set the sessions to work with the database? Do you try to access the cart contents on the same page as you save it into the cart?
#5

[eluser]NachoLabs[/eluser]
Yes and yes. I checked the database, and sessions are being stored properly. The code from before was written immediatley below the cart->insert().
#6

[eluser]Clooner[/eluser]
[quote author="NachoLabs" date="1255554755"]Yes and yes. I checked the database, and sessions are being stored properly. The code from before was written immediatley below the cart->insert().[/quote] That could be the problem. Session data can't be accessed on the same page on which it is being stored. Al though a good cart class should account for that
#7

[eluser]NachoLabs[/eluser]
Even if I don't access it on the same page, the page to where I redirect still lists 0 cart items.
#8

[eluser]markup2go[/eluser]
Enable logging and check to see if the cart class is logging any errors. My guess is you have disallowed characters in your product name.
#9

[eluser]NachoLabs[/eluser]
You're right, it's the disallowed characters. How do I fix this?
#10

[eluser]markup2go[/eluser]
Search the cart class for the error message. That's a good start Wink




Theme © iAndrew 2016 - Forum software by © MyBB