How to show cart with number of items in Ubercart?
As for D8 latest version, it looks like uc_cart_get_contents is not working anymore.  So here is how I managed to do it : 

/** @var \Drupal\uc_cart\CartManager $cartManager */
$cartManager = \Drupal::service('uc_cart.manager');
$items = $cartManager-&gt;get()-&gt;getContents();
$variables['nbr_cart_items'] = count($items);