[eluser]Kency[/eluser]
Hi experts!
I got problem when trying update cart with Size and Color, i cant update it
My code to insert to cart
Code:
function validate_add_cart_item(){
$id = $this->input->post('idproduct'); // Assign posted product_id to $id
$qty = $this->input->post('quantity'); // Assign posted quantity to $qty
$color = $this->input->post('colorproduct');
$size = $this->input->post('sizecart');
$this->db->where('idproduct', $id); // Select where id matches the posted id
$query = $this->db->get('product', 1); // Select the products where a match is found and limit the query by 1
// Check if a row has matched our product id
if($query->num_rows > 0){
// We have a match!
foreach ($query->result() as $row)
{
// Create an array with product information
$data = array(
'id' => $id,
'qty' => $qty,
'price' => $row->price,
'name' => $row->productname,
'size' => $size,
'color' => $color
);
$CI =& get_instance();
$CI->cart->product_name_rules = '^.';
//echo $this->cart->destroy();
$this->cart->insert($data);
// print_r($data);
//print_r($this->cart->contents());
return TRUE; // Finally return TRUE
}
}else{
// Nothing found! Return FALSE!
return FALSE;
}
}
and my code to use to update cart
Code:
function validate_update_cart(){
// Get the total number of items in cart
$total = $this->cart->total_items();
// Retrieve the posted information
$item = $this->input->post('rowid');
$qty = $this->input->post('qty');
$size = $this->input->post('size');
$color = $this->input->post('color');
print_r($color);
// Cycle true all items and update them
for($i=0;$i < count($item);$i++)
{
// Create an array with the products rowid's and quantities.
$data = array(
'rowid' => $item[$i],
'qty' => $qty[$i],
'size' => $size[$i],
'color' => $color[$i]
);
// Update the cart with the new information
$this->cart->update($data);
}
}
but it cant update size and color ( it can update quantity )
How can i update size and color?