sidebar = $sidebar; $this->logger = $logger; $this->jsonHelper = $jsonHelper; $this->resultPageFactory = $resultPageFactory; parent::__construct($context); } /** * @return $this */ public function execute() { if (!$this->getFormKeyValidator()->validate($this->getRequest())) { return $this->resultRedirectFactory->create()->setPath('*/cart/'); } $itemId = (int)$this->getRequest()->getParam('item_id'); try { $this->sidebar->checkQuoteItem($itemId); $this->sidebar->removeQuoteItem($itemId); return $this->jsonResponse(); } catch (\Magento\Framework\Exception\LocalizedException $e) { return $this->jsonResponse($e->getMessage()); } catch (\Exception $e) { $this->logger->critical($e); return $this->jsonResponse($e->getMessage()); } } /** * Compile JSON response * * @param string $error * @return \Magento\Framework\App\Response\Http */ protected function jsonResponse($error = '') { $response = $this->sidebar->getResponseData($error); return $this->getResponse()->representJson( $this->jsonHelper->jsonEncode($response) ); } /** * @return \Magento\Framework\Data\Form\FormKey\Validator * @deprecated 100.0.9 */ private function getFormKeyValidator() { if (!$this->formKeyValidator) { $this->formKeyValidator = \Magento\Framework\App\ObjectManager::getInstance() ->get(\Magento\Framework\Data\Form\FormKey\Validator::class); } return $this->formKeyValidator; } }