Spamworldpro Mini Shell
Spamworldpro


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/Label/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/corals/old/vendor/extmag/shiplab/Controller/Adminhtml/Label/Delete.php
<?php
/**
 * Copyright © Extmag. All rights reserved.
 */

namespace Extmag\Shiplab\Controller\Adminhtml\Label;

use Extmag\Shiplab\Controller\Adminhtml\Label;
use Exception;
use Magento\Backend\Model\View\Result\Redirect;
use Magento\Framework\Exception\NoSuchEntityException;

class Delete extends Label
{
    /**
     * Authorization level of a basic admin session
     *
     * @see _isAllowed()
     */
    public const ADMIN_RESOURCE = 'Extmag_Shiplab::shiplab_labels_delete';

    /**
     * @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 {
                $model = $this->labelRepository->getById($id);
                if ($this->isCanVoid($model)) {
                    $title = $model->getMasterId();

                    $voidLabel = $this->requestToAPI->create($model->getCarrierCode(), 'void');

                    if (!$voidLabel) {
                        throw new NoSuchEntityException(__('Carrier class is not found'));
                    }

                    $voidLabel->setData(
                        json_decode($model->getRequest(), true) + [
                            'master_id' => $model->getMasterId(),
                            'tracking_number' => $model->getTrackingNumber(),
                        ]
                    );
                    $voidLabel->addRequest();
                    $void = $voidLabel->send();

                    if (!empty($void['result']['Status'])) {
                        // display success message
                        $this->messageManager->addSuccessMessage(__('The label(s) has been deleted.'));

                        $this->_eventManager->dispatch(
                            'adminhtml_extmag_shiplab_label_on_delete',
                            [
                                'title' => $title,
                                'status' => 'success',
                            ]
                        );
                    } else {
                        $this->messageManager->addSuccessMessage(
                            __(
                                'The label(s) has been deleted on this store but has been not deleted on Carrier account.'
                            )
                        );
                        $this->_eventManager->dispatch(
                            'adminhtml_extmag_shiplab_label_on_delete',
                            [
                                'title' => $title,
                                'status' => 'partial_success',
                            ]
                        );
                    }
                } else {
                    $this->messageManager->addSuccessMessage(
                        __(
                            'The label(s) has been deleted.'
                        )
                    );
                }

                $this->labelRepository->deleteWithData($model);

                return $resultRedirect->setPath('extmag_shiplab/label/index');
            } catch (Exception $e) {
                $this->_eventManager->dispatch(
                    'adminhtml_extmag_shiplab_label_on_delete',
                    ['title' => $title, 'status' => 'fail']
                );
                // display error message
                $this->messageManager->addErrorMessage($e->getMessage());
                // go back to edit form
                return $resultRedirect->setPath('*/*/details', ['entity_id' => $id]);
            }
        }

        // display error message
        $this->messageManager->addErrorMessage(__('We can\'t find a label to delete.'));

        // go to grid
        return $resultRedirect->setPath('extmag_shiplab/label/index');
    }
}

Spamworldpro Mini