Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Delete.php
Go to the documentation of this file.
1 <?php
8 
9 use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface;
10 
12 {
18  public function execute()
19  {
20  if (!$this->_formKeyValidator->validate($this->getRequest())) {
21  return $this->resultRedirectFactory->create()->setPath('*/*/');
22  }
23 
24  $id = (int)$this->getRequest()->getParam('id');
25  if ($id) {
26  try {
27  $this->cart->removeItem($id)->save();
28  } catch (\Exception $e) {
29  $this->messageManager->addErrorMessage(__('We can\'t remove the item.'));
30  $this->_objectManager->get(\Psr\Log\LoggerInterface::class)->critical($e);
31  }
32  }
33  $defaultUrl = $this->_objectManager->create(\Magento\Framework\UrlInterface::class)->getUrl('*/*');
34  return $this->resultRedirectFactory->create()->setUrl($this->_redirect->getRedirectUrl($defaultUrl));
35  }
36 }
_redirect($path, $arguments=[])
Definition: Action.php:167
$id
Definition: fieldset.phtml:14
__()
Definition: __.php:13