Kindly give me an example about how to set GrandTotal via the controller in magento 2.3. I am new to Magento.
1 Answer
Please try with below code in controller :
protected $_checkoutSession;
protected $quoteRepository;
public function __construct(
...
\Magento\Checkout\Model\Session $checkoutSession,
\Magento\Quote\Api\CartRepositoryInterface $quoteRepository
...
) {
$this->_checkoutSession = $checkoutSession;
$this->quoteRepository = $quoteRepository;
}
public function execute()
{
$this->quoteRepository->get($this->_checkoutSession->getQuoteId());
$quote = $this->_checkoutSession->getQuote();
$grandTotal = "200"; // Set your grand total
$this->_checkoutSession->getQuote()->setGrandTotal($grandTotal);
$this->quoteRepository->save($quote->collectTotals());
echo $quote->getGrandTotal();
}
-
can you please tell me which observer/plugin will work to setGrandTotal() to order. Mar 17, 2020 at 10:46
-
-
i want to setGrandTotal() at order level. if i use checkout_cart_product_add_after it will trigger after adding each product to the cart. Mar 17, 2020 at 11:02