You could use PHP's Interface Serializable: http://php.net/manual/de/class.serializable.php
You can use it to convert an instance of your cart into a more efficient value (you define, what exactly is stored), which is in your case a two-dimensional array.
Try something like this:
<?php
class Cart implements Serializable {
// your normal code for the Cart class
public function serialize() {
$cartData = array();
foreach($this->cartItems as $item) {
$cartData[] = array(
'count' => $item->getCount(),
'productId' => $item->getId()
);
}
return serialize($cartData);
}
public function unserialize($cartData) {
$this->cartItem = array();
foreach($cartData as $item) {
// replace this with the appropriate propel code
$product = loadProductWithPropelById($item['id']);
$this->cartItems[] = new CartItem($item['count'], $product);
}
}
}
?>
Then use serialize to store the cart in the session and retrieve it:
<?php
// Store cart to session
$_SESSION['cart'] = serialize($cart);
// get cart from session
$cart = unserialize($_SESSION['cart']);
?>
Good Luck with your Project!