EllisLab text mark
Advanced Search
     
CI Shopping cart - can’t not update options value (size or color)
Posted: 26 May 2012 02:59 AM   [ Ignore ]
Joined: 2012-05-02
20 posts

Hi experts!

I got problem when trying update cart with Size and Color, i cant update it

My code to insert to cart

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

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?

 

 
Posted: 11 November 2012 03:18 PM   [ Ignore ]   [ # 1 ]   [ Rating: 0 ]
Joined: 2012-11-11
1 posts

I had same problem about updating cart product options, using CI ver 2.1.2

and i got solution from this : codeigniter cart update product options