Skip to content

Magento 2 – How can I update the cart summary totals when quote grand total is modified

I have a controller that is called by ajax in the cart page. A gift card amount is passed to the controller and a function then updates the quote grand total based on that amount.

    protected function applyGiftCard($giftCardCode, $giftCardSecurityCode, $giftCardAmount): array
    {
        $quote = $this->checkoutSession->getQuote();
        $grand_total = $quote->getGrandTotal();
        $new_grand_total = $grand_total - $giftCardAmount;
        $quote->setGrandTotal($new_grand_total);
        $quote->setBaseGrandTotal($new_grand_total);
        $quote->save();

        $this->checkoutSession->getQuote()->collectTotals()->save();
        return array();
    }

I can see that the Grand total has been updated in the quote data.

In the success function of the ajax I call

let deferred = $.Deferred();
getTotalsAction([], deferred);

The loading mask is shown but on complete the total has not updated.

Can anyone help to get the front end totals to update?