Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Clear.php
Go to the documentation of this file.
1 <?php
8 
9 use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface;
11 
12 class Clear extends \Magento\Catalog\Controller\Product\Compare implements HttpPostActionInterface
13 {
19  public function execute()
20  {
22  $items = $this->_itemCollectionFactory->create();
23 
24  if ($this->_customerSession->isLoggedIn()) {
25  $items->setCustomerId($this->_customerSession->getCustomerId());
26  } elseif ($this->_customerId) {
27  $items->setCustomerId($this->_customerId);
28  } else {
29  $items->setVisitorId($this->_customerVisitor->getId());
30  }
31 
32  try {
33  $items->clear();
34  $this->messageManager->addSuccessMessage(__('You cleared the comparison list.'));
35  $this->_objectManager->get(\Magento\Catalog\Helper\Product\Compare::class)->calculate();
36  } catch (\Magento\Framework\Exception\LocalizedException $e) {
37  $this->messageManager->addErrorMessage($e->getMessage());
38  } catch (\Exception $e) {
39  $this->messageManager->addExceptionMessage($e, __('Something went wrong clearing the comparison list.'));
40  }
41 
43  $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
44  return $resultRedirect->setRefererOrBaseUrl();
45  }
46 }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
__()
Definition: __.php:13
$items