_formKeyValidator->validate($this->getRequest())) { return $this->resultRedirectFactory->create()->setPath('*/*/'); } $id = (int)$this->getRequest()->getParam('id'); if ($id) { try { $this->cart->removeItem($id); // We should set Totals to be recollected once more because of Cart model as usually is loading // before action executing and in case when triggerRecollect setted as true recollecting will // executed and the flag will be true already. $this->cart->getQuote()->setTotalsCollectedFlag(false); $this->cart->save(); } catch (\Exception $e) { $this->messageManager->addErrorMessage(__('We can\'t remove the item.')); $this->_objectManager->get(\Psr\Log\LoggerInterface::class)->critical($e); } } $defaultUrl = $this->_objectManager->create(\Magento\Framework\UrlInterface::class)->getUrl('*/*'); return $this->resultRedirectFactory->create()->setUrl($this->_redirect->getRedirectUrl($defaultUrl)); } }