CodeIgniter Forums
Cart insert not working - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Cart insert not working (/showthread.php?tid=23530)

Pages: 1 2


Cart insert not working - El Forum - 10-13-2009

[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?


Cart insert not working - El Forum - 10-14-2009

[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?


Cart insert not working - El Forum - 10-14-2009

[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 ( )



Cart insert not working - El Forum - 10-14-2009

[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?


Cart insert not working - El Forum - 10-14-2009

[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().


Cart insert not working - El Forum - 10-14-2009

[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


Cart insert not working - El Forum - 10-14-2009

[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.


Cart insert not working - El Forum - 10-15-2009

[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.


Cart insert not working - El Forum - 10-15-2009

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


Cart insert not working - El Forum - 10-15-2009

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