0

I am creating functionality for additional donation. I am trying to add donation amount in quote total but it will not reflect.

This my code portion of that part :

    <?php 

    namespace Yogesh\Donation\Controller\Index;
    class Index extends \Yogesh\Donation\Controller\Index
    {
      public function execute()
      {
         $post = $this->getRequest()->getPostValue();
         $quote = $this->checkoutSession->getQuote();

         $donation = $post['donation_amount'];
         $grand_total = $quote->getGrandTotal();
         $new_grand_total = $grand_total + $donation;
         $quote->setGrandTotal($new_grand_total);
         $quote->save();

         $this->_redirect('checkout/cart');

    }
}

?>

Addition of donation amount not display or reflect on front side. How can I update quote total ? Please any one have idea about that.

Thanks

0

You can update current checkout or quote total like this :

    namespace Yogesh\Donation\Controller\Index;
    class Index extends \Yogesh\Donation\Controller\Index
    {
      public function execute()
      {
         $post = $this->getRequest()->getPostValue();
         $quote = $this->checkoutSession->getQuote();

         $donation = $post['donation_amount'];
         $grand_total = $quote->getGrandTotal();
         $new_grand_total = $grand_total + $donation;
         $quote->setGrandTotal($new_grand_total);
         $quote->save();

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

         $this->_redirect('checkout/cart');
    }
}
  • Its not working... Changes are not reflect on front Total. – Yogesh Apr 18 '17 at 14:34
  • you need to add this too - $quote->setBaseGrandTotal($new_grand_total); – user4536 May 31 at 5:04

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.