I am trying to update the order's grand total via a controller.
Here is my controller's code:
<?php
namespace Company\Vendor\Controller\Index;
use Magento\Framework\App\Action\Action;
use Magento\Framework\App\Action\Context;
class Index extends Action
{
protected $_checkoutSession;
/**
* @var \Magento\Quote\Api\CartRepositoryInterface
*/
protected $_quoteRepository;
public function __construct(
Context $context,
\Magento\Checkout\Model\Session $checkoutSession,
\Magento\Quote\Api\CartRepositoryInterface $quoteRepository
) {
parent::__construct($context);
$this->_checkoutSession = $checkoutSession;
$this->_quoteRepository = $quoteRepository;
}
public function execute()
{
$this->_quoteRepository->get($this->_checkoutSession->getQuoteId());
$quote = $this->_checkoutSession->getQuote();
$grand_total = $quote->getGrandTotal(); // It contains correct order grand total
$new_grand_total = $grand_total + 100; // Adding 100 to order total
$quote->setGrandTotal($new_grand_total);
$quote->collectTotals();
$this->_quoteRepository->save($quote);
echo $quote->getGrandTotal();
}
}
Above code is not updating the grand total.