I have to show the total quantity of the items in the cart. I'm doing this now with:

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$cart = $objectManager->get('\Magento\Checkout\Model\Cart');

$totalItems = $cart->getQuote()->getItemsCount();
$totalQuantity = $cart->getQuote()->getItemsQty();

echo $totalQuantity;

I have 5 items in the cart and the $totalQuantity will show 5.0000 Why is that? And how can I just display 5?

Regards, Robert

echo round($totalQuantity); 

PHP built in function round() will do the job.

  • AWESOOOOOMEEEEE! :) – n00bly Mar 6 '18 at 9:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.