Assuming the entity is named Product:
// Your model, you can use it to fetch products
$productRepository = $em->getRepository('ShopBundle:Product');
// Retrieve all products as an array of objects
$products = $productRepository->findAll();
// Retrieve a specific product as object from its reference (id)
$product = $productRepository->find(1); // Returns product with 'id' = 1
// Retrieve a specific product based on condition(s)
$product = $productRepository->findOneBy(['price' => 10]);
// Retrieve many products based on condition(s)
$products = $productRepository->findBy(['price' => 10]);
To check if a specific product is in your UserCart object:
$cartRepository = $em->getRepository('ShopBundle:UserCart');
// Fetches the cart by its owner (the current authenticated user)
// assuming UserCart has a $user property that represents an association to your User entity
$cart = $cartRepository->findOneBy(['user' => $this->getUser()]);
// Check if a specific product is in the cart,
// assuming $product is a Product object retrieved like shown above
if ($cart->contains($product)) {
// Do something
}
For the whole reference, see Working with objects from Doctrine documentation.
I hope that will help you.
Do not hesitate to post a comment if you need more precisions or any other information.
EDIT
To access properties of an object, use its getters:
$cartView = array(
'products' => $cart->getProducts(), // return the property $products
'user' => $cart->getUser(), // return the property $user
);
That is possible only if the methods exist and have public access.
Note You should really look more at OOP and practice it before use a framework like Symfony.