I am integrating the custom module of custom payment gateway. I need the cart total on the checkout page for the price conversion before the payment.

How can I get the Cart total in JS or in the custom controller? Thanks in advance.


Try this:

$objectManager = \Magento\Framework\App\ObjectManager::getInstance(); 
$cart = $objectManager->get('\Magento\Checkout\Model\Cart');    
$totalItems = $cart->getQuote()->getItemsCount(); 
$totalQuantity = $cart->getQuote()->getItemsQty();
$grandTotal = $cart->getQuote()->getGrandTotal();

Hope it works for you..!!

  • with this code, no need to add object manager, because I already defined OM in above code. – temper Nov 11 at 8:16
  • Thanks, this function get the total. $grandTotal = $cart->getQuote()->getGrandTotal(); – Garry Nov 11 at 10:32

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.