Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
DeleteStorePost.php
Go to the documentation of this file.
1 <?php
7 
10 
14 class DeleteStorePost extends \Magento\Backend\Controller\Adminhtml\System\Store implements HttpPostActionInterface
15 {
21  public function execute()
22  {
23  $itemId = $this->getRequest()->getParam('item_id');
24 
26  $redirectResult = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
27  if (!($model = $this->_objectManager->create(\Magento\Store\Model\Store::class)->load($itemId))) {
28  $this->messageManager->addErrorMessage(__('Something went wrong. Please try again.'));
29  return $redirectResult->setPath('adminhtml/*/');
30  }
31  if (!$model->isCanDelete()) {
32  $this->messageManager->addErrorMessage(__('This store view cannot be deleted.'));
33  return $redirectResult->setPath('adminhtml/*/editStore', ['store_id' => $model->getId()]);
34  }
35 
36  if (!$this->_backupDatabase()) {
37  return $redirectResult->setPath('*/*/editStore', ['store_id' => $itemId]);
38  }
39 
40  try {
41  $model->delete();
42 
43  $this->messageManager->addSuccessMessage(__('You deleted the store view.'));
44  return $redirectResult->setPath('adminhtml/*/');
45  } catch (\Magento\Framework\Exception\LocalizedException $e) {
46  $this->messageManager->addErrorMessage($e->getMessage());
47  } catch (\Exception $e) {
48  $this->messageManager
49  ->addExceptionMessage($e, __('Unable to delete the store view. Please try again later.'));
50  }
51  return $redirectResult->setPath('adminhtml/*/editStore', ['store_id' => $itemId]);
52  }
53 }
__()
Definition: __.php:13