1

Is there a way to get a specified array inside codeigniter's cart session?

for example i have these values

Array
(
    [c81e728d9d4c2f636f067f89cc14862c] => Array
        (
            [rowid] => c81e728d9d4c2f636f067f89cc14862c
            [id] => 2
            [qty] => 1
            [price] => 1000
            [name] => Pin 
            [subtotal] => 1000
        )

    [c4ca4238a0b923820dcc509a6f75849b] => Array
        (
            [rowid] => c4ca4238a0b923820dcc509a6f75849b
            [id] => 1
            [qty] => 3
            [price] => 100
            [name] => Amber
            [subtotal] => 300
        )

)

and i only want to get the values for the array "c4ca4238a0b923820dcc509a6f75849b"

i tried

$this->session->userdata("c81e728d9d4c2f636f067f89cc14862c");

and

$this->cart->contents("c81e728d9d4c2f636f067f89cc14862c");

but it didnt work

2 Answers 2

3

you can get your cart items with $this->cart->contents() to get a specific key, just call like this.

$getCartItem = 'c4ca4238a0b923820dcc509a6f75849b';
$cartItems = $this->cart->contents();

if( isset($cartItems[$getCartItem]) ) 
{
    $item = $cartItems[$getCartItem];
    // do stuff

} else {
    //not found
}
Sign up to request clarification or add additional context in comments.

Comments

0

You can write your own function like that,

 public function getCartInfo($rowId)
    {

        $cart = $this->cart->contents();
        if( isset($cart[$rowId])) //your $rowId="c81e728d9d4c2f636f067f89cc14862c"
        {
            $data = $cart[$rowId];
            echo "<pre>";
            print_r($data); //view specific cart information
        } 
        else 
        {
            echo "not found";
        }
        exit();
    }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.