php - How to update the quantity of all items in the cart with respect to database? -
i doing shopping cart using code-igniter. while can add cart functions, i'm confused how update them regards database. want when change item quantity in cart , click update ,both cart , database must updated particular item.i tried couldn't it.can please enlighten me do?
controller code
$this->load->model('user_m'); $result['query'] = $this->user_m->get($id); // inserts coresponing item foreach ($result['query'] $row) $id = $row->pid; $qty = $a; $quan=$row->quantity; $price = $row->pprice; $name = $row->pname; $q=$quan-$a; // remainig stock i.e total qty-user qty $data = array( 'id' => $id, 'qty' => $qty, 'price' => $price, 'name' => $name, 'stock' =>$q ); $this->cart->insert($data); $this->load->model('user_m'); $result['qry'] = $this->user_m->up_cart($id,$q); redirect($_server['http_referer']); }
just tell me how update pls!
when ever add product in cart, generate uniq row id , unique each , every product , hence need update quantity row id
$data = array( 'rowid' => 'b99ccdf16028f015540f341130b6d8ec', 'qty' => 3 ); $this->cart->update($data);
// or multi-dimensional array
$data = array( array( 'rowid' => 'b99ccdf16028f015540f341130b6d8ec', 'qty' => 3 ), array( 'rowid' => 'xw82g9q3r495893iajdh473990rikw23', 'qty' => 4 ), array( 'rowid' => 'fh4kdkkkaoe30njgoe92rkdkkobec333', 'qty' => 2 ) ); $this->cart->update($data);
now want know how row id.
$cart=$this->cart->contents();
it return whole array of cart , when listing on webpage, please associate row id quantity text box update particular product.
please check following url:
https://ellislab.com/codeigniter/user-guide/libraries/cart.html
Comments
Post a Comment