Welcome Guest, Not a member yet? Register   Sign In
Can't Update Cart Option Item
#1

[eluser]B3ll4triX[/eluser]
i have code like this
Code:
function add_to_cart($id){
    
  $d = $this->_cart_data($id);
  $discount = ($d->discount/100)*$d->price;
  $new_price = $d->price-$discount;
    
  $data = array(
    'id'      => $d->id,
    'qty'     => 1,
    'price'   => $new_price,
    'name'    => $d->catalogue_title,
    'options' => array(
        'weight' => db_clean($d->weight),
        'summary' => db_clean($d->catalogue_summary),
        'currency' => 'rupiah',
        'image'    => $d->image,
        'discount' => $d->discount,
        'priceb4' => $d->price,
        'color'    => $d->color,
        'size' => $d->size,
        'color_choice'    => 0,
        'size_choice'    => 0
    )
   );

   $this->cart->insert($data);
    
}

But, i want to update $data['qty'], $data['options']['color_choice'] and $data['options']['color_choice'], update $data['qty'] success, but $data['options']['color_choice'] and $data['options']['color_choice'] failed...

I've check the variables in post, all went as it should. Here's the script that I use:
Code:
function update_cart(){
   if(empty($_POST['qty'])){redirect('');}
        
   $t = count($_POST['qty']);
   for($i = 1; $i <= $t; $i++){
    $data = array(
            'rowid'         => $_POST['rowid'][$i],
            'qty'           => $_POST['qty'][$i],
            'options' => array(
                'color_choice'    => $_POST['color_choice'][$i],
                'size_choice'    => $_POST['size_choice'][$i]
            )
            );
    $this->cart->update($data);
   }
}

how to fix this problem.
thanks b4.
#2

[eluser]skunkbad[/eluser]
How about this:

Code:
public function update_cart()
{
    for ($i = 1; $i <= $this->cart->total_items(); $i++)
    {
        $item = $this->input->post($i);
        $data = array(
                'rowid'    => $item['rowid'],
                'qty'    => $item['qty'],
                'options' => array(
                    'color_choice' => $item['color_choice'],
                    'size_choice' => $item['size_choice']
                )
        );
        $this->cart->update($data);
    }
}
#3

[eluser]B3ll4triX[/eluser]
I open the cart CodeIgniter libraries, seems to only update to qty, but not for the options. Did anyone ever write a script to fix this.
#4

[eluser]skunkbad[/eluser]
I don't think you can consider it broken. Simply extend the cart class to suit your needs.




Theme © iAndrew 2016 - Forum software by © MyBB