Simplest way to create a Commerce shopping cart icon showing the number of items
The way I would do it, is that I would make the total number of products in the shopping cart available in the page.tpl.php file, and print it there directly.

Here's example code:

function YOUR_THEME_preprocess_page(&amp;$variables) {
  $cart_count = 0;
  $order = commerce_cart_order_load($variables['user']-&gt;uid);
  if ($order) {
    $wrapper    = entity_metadata_wrapper('commerce_order', $order);
    $line_items = $wrapper-&gt;commerce_line_items;
    $cart_count = commerce_line_items_quantity($line_items, commerce_product_line_item_types());
  }
  // Make the number of products in the shopping cart available to our template.
  $variables['products_in_shopping_cart'] = $cart_count;
}


Then in your page.tpl.php you would use this code to show the number of products in current user's cart:

&lt;?php print $products_in_shopping_cart; ?&gt;


Note: second argument passed to the commerce_line_items_quantity() is updated per Clive's note.