After controller_action_predispatch_checkout_cart_index event dispatcher i am trying to update quote in cart page.All working fine except price.The price is not getting updated quote and quoteitem database table and in summary also.Can anyone help me.
<?php
namespace Vender\Module\Observer;
use Magento\Framework\Event\ObserverInterface;
class PredispatchCheckoutCart implements ObserverInterface{
public function __construct(
\Magento\Framework\ObjectManagerInterface $_objectManager,
\Magento\Framework\App\Request\Http $_request,
\Magento\Framework\Message\ManagerInterface $_messangeManager,
\Magento\Checkout\Helper\Cart $_cartHelper
) {
$this->_objectManager = $_objectManager;
$this->_request = $_request;
$this->_messangeManager = $_messangeManager;
$this->_cartHelper = $_cartHelper;
}
public function execute(\Magento\Framework\Event\Observer $observer){
$quoteId = intval($this->_request->getParam('quoteId'));
$cartsess = $this->_objectManager->get('Magento\Checkout\Model\Session');
$cartsess->setQuoteId($quoteId);
$cartsess->setLoadInactive(true);
$quote = $cartsess->getQuote();
$quote->setIsActive(true);
$quote->save();
$quote->setTotalsCollectedFlag(false)->collectTotals();
$this->_messangeManager->addSuccess('Product is successfully added in to cart.');
$redirectUrl = $this->_cartHelper->getCartUrl();
$observer->getControllerAction()->getResponse()->setRedirect($redirectUrl);
}
}
}