Welcome Guest, Not a member yet? Register   Sign In
Cart Class insert and update
#1

[eluser]Ngulo[/eluser]
hi all guys i've to update or insert data into cart class.
so i've write down this code:
Code:
/////////////IF (YES) EXIST CART IN SESSION///////////////////////

                if($this->cart->contents())
                {
                    foreach($this->cart->contents() as $cart)
                    {
                     //if product is just in cart we update that
                        if($cart->id == $populateProduct->id)
                        {
                          $cart->quantity =  $cart->quantity+1;
                          echo ' product exist and i put +1 qty of that ';
                        }
                       //if product is not just inside the cart we insert them
                        else
                        {
                           $dataNew = array(
                            'id'      => $populateProduct->id,
                            'qty'     => 1,
                            'price'=> $populateProduct->price,
                            'name'=>$populateProduct->name,
                            'status'=>$populateProduct->status
                           );
                          
                            $this->cart->insert($dataNew);
                            echo ' cart exist but product is not in cart';
                        }
                    }
                }
               /////////////////////////////////////////////////////////////////
                   //////////////////IF (NOT) EXIST CART IN SESSION//////////////////
                if(!$this->cart->contents())
                {
                  $dataSet = array(
                   'id'      => $populateProduct->id,
                   'qty'     => 1,
                   'price'=> $populateProduct->price,
                   'name'=>$populateProduct->name,
                   'status'=>$populateProduct->status

                   );
                

                $this->cart->insert($dataSet);
                echo 'cart doesn't exist';
                }
               /////////////////////////////////////////////////////////////////

the problem is that CI can't tell me if $this->cart->contents() exist or not....or right he says to me that Cart always is not in session so this code is always true on
Code:
if(!$this->cart->contents()){ always true :/ !! }

so everytime he recharge cart array instead :/

i'm wondering how to control if exist or not cart? :/

really thanks guys Wink
#2

[eluser]Ngulo[/eluser]
ok sorry guys i just fixed this problem

just using if(count($this->cart->contents()))

thanks anyway. Wink




Theme © iAndrew 2016 - Forum software by © MyBB