Count products in cart with certain template

I need a snippet wich loops through the cart and detects products with a specific template and return the quantity and pagetitle of these products.
I can get the producttitles but I can’t figure out how to get the quantity of each product. This is what I got so far:

if (!($sc instanceof SimpleCart)) return '';
$controller = $sc->loadController('Cart', 'ContentsController');
$controller->initialize();
$controller->loadProducts();
foreach ($controller->getProducts() as $product) {
  $productid = $product->id;
  $resource = $modx->getObject('modResource',$productid);
  $template = $resource->get('template');
    if($template == 11){
    $title = $resource->get('pagetitle');
    }


}

In your loop it would just be $product->totals['quantity']

1 Like