Welcome Guest, Not a member yet? Register   Sign In
Update Cart item quantity
#1

[eluser]Ngulo[/eluser]
guys,i can't understand how can i update a qty value into $this->cart->contents() ?

i'm using this code:
Code:
foreach($this->cart->contents() as $cart)
                    {
                     //if product is just in cart we update that
                        if($cart['id'] == $populateProduct->id)
                        {
                          $id_product = $populateProduct->id;
                          $newqty = (int)$cart['qty'] +1;
                          $dataUpdate = array('id'=>$id_product,'qty'=>$newqty);
                          $this->cart->update($dataUpdate);
                          
                        
                        }

really can't find how to update quantities keys in cart items Sad

var_dump($this->cart->contents()) says always:
Code:
array(7) {
    ["rowid"]=>
    string(32) "f7177163c833dff4b38fc8d2872f1ec6"
    ["id"]=>
    string(2) "44"
    ["qty"]=>
    string(1) "1"
etc.........

//quantity doesn't update to new qty value ($newqty = (int)$cart['qty'] +1;)

any suggestion guys? Sad

thanks Wink
#2

[eluser]pbreit[/eluser]
According to:
http://ellislab.com/codeigniter/user-gui.../cart.html

It would be something like this:
Code:
$data = array(
               'rowid' => 'b99ccdf16028f015540f341130b6d8ec',
               'qty'   => 3
            );

$this->cart->update($data);

You need to first determine the rowid of the item you want to adjust quantity.
#3

[eluser]Ngulo[/eluser]
yep man you've fixed it Smile

really thanks!!
#4

[eluser]dysko[/eluser]
I have similar problem... Smile
I know that I can update Qty with:
Code:
$data = array(
               'rowid' => 'b99ccdf16028f015540f341130b6d8ec',
               'qty'   => 3
            );
$this->cart->update($data);
BUT Smile
If I try something like this:

Code:
$data = array(
               'rowid' => 'b99ccdf16028f015540f341130b6d8ec',
               'qty'   => 3,
               'name'   => 'this is new fancy name'
            );
$this->cart->update($data);
It doesn't work for me... Any ideas or something? Smile
#5

[eluser]StevenSokulski[/eluser]
[quote author="dysko" date="1332205778"]I have similar problem... Smile
I know that I can update Qty with:
Code:
$data = array(
               'rowid' => 'b99ccdf16028f015540f341130b6d8ec',
               'qty'   => 3
            );
$this->cart->update($data);
BUT Smile
If I try something like this:

Code:
$data = array(
               'rowid' => 'b99ccdf16028f015540f341130b6d8ec',
               'qty'   => 3,
               'name'   => 'this is new fancy name'
            );
$this->cart->update($data);
It doesn't work for me... Any ideas or something? Smile[/quote]

I have the same question. It doesn't seem like anything beyond the quantity can be updated. Sad
#6

[eluser]StevenSokulski[/eluser]
Did some digging in the Cart library's source and found that, in fact, the qty is the only thing setup to be updated by the $this->cart->update() method. Doh!

I think in the short term I'm going to modify the data using the Session class. Kinda kludgy, but I think it'll get me past this roadblock until I have time to extend the core functionality of Cart.
#7

[eluser]dysko[/eluser]
I've solved my problem by rewriting that class...
Now I can update anything Smile
#8

[eluser]StevenSokulski[/eluser]
Any chance you'd be willing to share your modifications? I used the Session class to get around the limitations this time, but would love to have more flexibility in the future.




Theme © iAndrew 2016 - Forum software by © MyBB