CodeIgniter Forums
Cart Class - 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 Class (/showthread.php?tid=51561)

Pages: 1 2


Cart Class - El Forum - 05-09-2012

[eluser]craig.hoog[/eluser]
[quote author="the_unforgiven" date="1336572233"]Apologise, i had put it in the view file: after putting it in the controller i get this:

array(1) { [1]=> array(2) { ["rowid"]=> string(32) "a5bfc9e07964f8dddeb95fc584cd965d" ["qty"]=> string(1) "2" } } [/quote]

That is exactly what I expected to see.
You have an Array of posts.

Change your original code to this (for testing, not necessarily the most robust or efficient code):

Code:
if(isset($_POST) && $_POST != null)
{
foreach($_POST as $p)
{
  $update = array(
   'rowid' => $p['rowid'],
   'qty'   => $p['qty']
  );

  $this->cart->update($update);
}
$this->session->set_flashdata('message','Your shopping cart has been updated!');
}
redirect('home/cart','refresh');



Cart Class - El Forum - 05-09-2012

[eluser]the_unforgiven[/eluser]
You absolute legend!!!!

It works i know you shouldn't use $_POST and stuff but if thats the only way to get it working then so be it...


Thanks a million!!


Cart Class - El Forum - 05-09-2012

[eluser]craig.hoog[/eluser]
[quote author="the_unforgiven" date="1336572658"]You absolute legend!!!!

It works i know you shouldn't use $_POST and stuff but if thats the only way to get it working then so be it...


Thanks a million!![/quote]

It won't be necessary. Try swapping this in (I've never done a foreach through the this->input

Code:
if(isset($_POST) && $_POST != null)
{
$post = $this->input->post();
foreach($post as $p)
{
  $update = array(
   'rowid' => $p['rowid'],
   'qty'   => $p['qty']
  );

  $this->cart->update($update);
}
$this->session->set_flashdata('message','Your shopping cart has been updated!');
}
redirect('home/cart','refresh');

If that works, you might as well leave it. It will loop through all your cart contents and update each one's quantity one at a time. Would be more efficient to build one array and do one global update, but I'll leave that up to you.


Cart Class - El Forum - 05-09-2012

[eluser]the_unforgiven[/eluser]
$this->input works too, thanks a billion!!!!