0

I have a simple module when I save data then this error : Magepow\Importexport\Controller\Adminhtml\Allimports\Save\Interceptor does not exist [] []

here is save file

<?php

namespace Magepow\Importexport\Controller\Adminhtml\Allimports;

use Magento\Backend\App\Action; use Magepow\Importexport\Model\Allimports; use Magento\Framework\App\Request\DataPersistorInterface; use Magento\Framework\Exception\LocalizedException;

class Save extends \Magento\Backend\App\Action {

protected $dataPersistor;

protected $allimportsFactory;


protected $allimportsRepository;

public function __construct(
    Action\Context $context,
    DataPersistorInterface $dataPersistor,
    \Magepow\Importexport\Model\allimportsFactory $allimportsFactory = null,
    \Magepow\Importexport\Api\AllimportsRepositoryInterface $allimportsRepository = null
) {
    $this->dataPersistor = $dataPersistor;
    $this->allimportsFactory = $allimportsFactory
        ?: \Magento\Framework\App\ObjectManager::getInstance()->get(\Magepow\Importexport\Model\AllimportsFactory::class);
    $this->allimportsRepository = $allimportsRepository
        ?: \Magento\Framework\App\ObjectManager::getInstance()->get(\Magepow\Importexport\Api\AllimportsRepositoryInterface::class);
    parent::__construct($context);
}

/**
 * Authorization level
 *
 * @see _isAllowed()
 */
protected function _isAllowed()
{
    return $this->_authorization->isAllowed('Magepow_Importexport::save');
}

/**
 * Save action
 *
 * @SuppressWarnings(PHPMD.CyclomaticComplexity)
 * @return \Magento\Framework\Controller\ResultInterface
 */
public function execute()
{

    $data = $this->getRequest()->getPostValue();
    /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
    $resultRedirect = $this->resultRedirectFactory->create();
    if ($data) {
        if (empty($data['import_id'])) {
            $data['import_id'] = null;
        }

        $model = $this->allimportsFactory->create();

        $id = $this->getRequest()->getParam('import_id');
        if ($id) {
            try {
                $model = $this->allimportsRepository->getById($id);
            } catch (LocalizedException $e) {
                $this->messageManager->addErrorMessage(__('This job no longer exists.'));
                return $resultRedirect->setPath('*/*/');
            }
        }
        $data['config'] = serialize($data);
        $model->setData($data);

        $this->_eventManager->dispatch(
            'imports_allimports_prepare_save',
            ['allimports' => $model, 'request' => $this->getRequest()]
        );

        try {
            $this->allimportsRepository->save($model);
            $this->messageManager->addSuccessMessage(__('You saved the job.'));
            $this->dataPersistor->clear('imports_allimports');
            if ($this->getRequest()->getParam('back')) {
                return $resultRedirect->setPath('*/*/edit', ['import_id' => $model->getId(), '_current' => true]);
            }
            return $resultRedirect->setPath('*/*/');
        } catch (LocalizedException $e) {
            $this->messageManager->addExceptionMessage($e->getPrevious() ?:$e);
        } catch (\Exception $e) {
            $this->messageManager->addExceptionMessage($e, __('Something went wrong while saving the job.'));
        }

        $this->dataPersistor->set('imports_allimports', $data);
        return $resultRedirect->setPath('*/*/edit', ['import_id' => $this->getRequest()->getParam('import_id')]);
    }
    return $resultRedirect->setPath('*/*/');
}

}

I know running the command di:compile will fix, but I don't want to use it. Hope anyone help me. Thank in advance.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.