StockAll.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\ProductAlert\Controller\Unsubscribe;
  7. use Magento\ProductAlert\Controller\Unsubscribe as UnsubscribeController;
  8. use Magento\Framework\Controller\ResultFactory;
  9. class StockAll extends UnsubscribeController
  10. {
  11. /**
  12. * @return \Magento\Framework\Controller\Result\Redirect
  13. */
  14. public function execute()
  15. {
  16. try {
  17. $this->_objectManager->create(\Magento\ProductAlert\Model\Stock::class)
  18. ->deleteCustomer(
  19. $this->customerSession->getCustomerId(),
  20. $this->_objectManager->get(\Magento\Store\Model\StoreManagerInterface::class)
  21. ->getStore()
  22. ->getWebsiteId()
  23. );
  24. $this->messageManager->addSuccess(__('You will no longer receive stock alerts.'));
  25. } catch (\Exception $e) {
  26. $this->messageManager->addException($e, __('Unable to update the alert subscription.'));
  27. }
  28. /** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */
  29. $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
  30. return $resultRedirect->setPath('customer/account/');
  31. }
  32. }