cancel
Showing results for 
Search instead for 
Did you mean: 

checkoutSession collectTotals returning 'null'

   Did you know you can see the translated content as per your choice?

Translation is in progress. Please check again after few minutes.

checkoutSession collectTotals returning 'null'

Hi,

 

 

I am having issues with updating totals after an ajax call:

 

  $this->_checkoutSession->getQuote()->collectTotals()->save();

 

The module enables a customer to tick/untick custom options.

 

protected function _getTotalsHtml()
{
$lfactory = $this->resultFactory->create(ResultFactory::TYPE_PAGE);
$layout = $lfactory->addHandle('checkout_cart_index')->getLayout();
$response['cartcontent'] = $this->_view->getLayout()->getBlock('checkout.cart.form')->toHtml();
$response['checkout_method'] = $this->_view->getLayout()->getBlock('checkout.cart.methods.bottom')->toHtml();
$response['page_messages'] = $this->_view->getLayout()->getBlock('checkout.cart.validationmessages')->toHtml();
$response['content'] = $layout->renderNonCachedElement('checkout.cart.empty');

$cartQuote= $this->cart->getQuote()->setTotalsCollectedFlag(false)->collectTotals();
 
$response['subtotaldata'] = $this->_objectManager->create('Magento\Checkout\Model\DefaultConfigProvider')->getConfig();    

$this->_checkoutSession->getQuote()->collectTotals()->save();
$resultJson = $this->resultFactory->create(ResultFactory::TYPE_JSON);
$resultJson->setData($response);

return $resultJson; }

 

The response I receive:

* total_segments: Array(4)

        * area: null
code: "subtotal"
title: "Subtotal"value: null
__proto__: Object* area: null
code: "shipping"
title: "Shipping & Handling"value: null
__proto__: Object* area: null
code: "tax"
extension_attributes: {tax_grandtotal_details: Array(0)}
title: "Tax"value: 0
__proto__: Object* area: "footer"
code: "grand_total"
title: "Grand Total"value: null
__proto__: Object