![]() Server : Apache System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64 User : corals ( 1002) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/corals/old/vendor/extmag/shiplab/Controller/Adminhtml/PriceRules/ |
<?php /** * Copyright © Extmag. All rights reserved. */ namespace Extmag\Shiplab\Controller\Adminhtml\PriceRules; use Extmag\Shiplab\Controller\Adminhtml\PriceRules; use Exception; use Magento\Backend\Model\View\Result\Redirect; class Delete extends PriceRules { /** * Authorization level of a basic admin session * * @see _isAllowed() */ public const ADMIN_RESOURCE = 'Extmag_Shiplab::shiplab_price_rules_delete'; /** * Delete action * * @return Redirect */ public function execute() { // check if we know what should be deleted $id = $this->getRequest()->getParam('entity_id'); /** @var Redirect $resultRedirect */ $resultRedirect = $this->resultRedirectFactory->create(); if ($id) { $title = ""; try { // init model and delete $model = $this->priceRulesRepository->getById($id); $title = $model->getTitle(); $this->priceRulesRepository->delete($model); // display success message $this->messageManager->addSuccessMessage(__('The rule has been deleted.')); // go to grid $this->_eventManager->dispatch('adminhtml_extmag_shiplab_pricerules_on_delete', [ 'title' => $title, 'status' => 'success' ]); return $resultRedirect->setPath('*/*/'); } catch (Exception $e) { $this->_eventManager->dispatch( 'adminhtml_extmag_shiplab_pricerules_on_delete', ['title' => $title, 'status' => 'fail'] ); // display error message $this->messageManager->addErrorMessage($e->getMessage()); // go back to edit form return $resultRedirect->setPath('*/*/edit', ['entity_id' => $id]); } } // display error message $this->messageManager->addErrorMessage(__('We can\'t find a rule to delete.')); // go to grid return $resultRedirect->setPath('*/*/'); } }