0

In my ui form I have added 2 ui form tabs (general and general1) To display the tabs I have added the layout code, and changed the dataprovider to display the data

        <layout>
        <navContainerName>left</navContainerName>
        <type>tabs</type>
    </layout>

All data are displayed, but I can not save my data. This is my save class

namespace Mcas\PdfOrder\Controller\Adminhtml\Invoice;

class Save extends \Mcas\PdfOrder\Controller\Adminhtml\Invoice {

/**
 * Invoice factory
 * 
 * @var \Mcas\PdfOrder\Api\Data\InvoiceInterfaceFactory
 */
protected $invoiceFactory;

/**
 * Data Object Processor
 * 
 * @var \Magento\Framework\Reflection\DataObjectProcessor
 */
protected $dataObjectProcessor;

/**
 * Data Object Helper
 * 
 * @var \Magento\Framework\Api\DataObjectHelper
 */
protected $dataObjectHelper;

/**
 * Uploader pool
 * 
 * @var \Mcas\PdfOrder\Model\UploaderPool
 */
protected $uploaderPool;

/**
 * Data Persistor
 * 
 * @var \Magento\Framework\App\Request\DataPersistorInterface
 */
protected $dataPersistor;

/**
 * constructor
 * 
 * @param \Magento\Backend\App\Action\Context $context
 * @param \Magento\Framework\Registry $coreRegistry
 * @param \Mcas\PdfOrder\Api\InvoiceRepositoryInterface $invoiceRepository
 * @param \Magento\Framework\View\Result\PageFactory $resultPageFactory
 * @param \Mcas\PdfOrder\Api\Data\InvoiceInterfaceFactory $invoiceFactory
 * @param \Magento\Framework\Reflection\DataObjectProcessor $dataObjectProcessor
 * @param \Magento\Framework\Api\DataObjectHelper $dataObjectHelper
 * @param \Mcas\PdfOrder\Model\UploaderPool $uploaderPool
 * @param \Magento\Framework\App\Request\DataPersistorInterface $dataPersistor
 */
public function __construct(
    \Magento\Backend\App\Action\Context $context,
    \Magento\Framework\Registry $coreRegistry,
    \Mcas\PdfOrder\Api\InvoiceRepositoryInterface $invoiceRepository,
    \Magento\Framework\View\Result\PageFactory $resultPageFactory,
    \Mcas\PdfOrder\Api\Data\InvoiceInterfaceFactory $invoiceFactory,
    \Magento\Framework\Reflection\DataObjectProcessor $dataObjectProcessor,
    \Magento\Framework\Api\DataObjectHelper $dataObjectHelper,
    \Mcas\PdfOrder\Model\UploaderPool $uploaderPool,
    \Magento\Framework\App\Request\DataPersistorInterface $dataPersistor
) {
    $this->invoiceFactory      = $invoiceFactory;
    $this->dataObjectProcessor = $dataObjectProcessor;
    $this->dataObjectHelper    = $dataObjectHelper;
    $this->uploaderPool        = $uploaderPool;
    $this->dataPersistor       = $dataPersistor;
    parent::__construct($context, $coreRegistry, $invoiceRepository, $resultPageFactory);
}

/**
 * run the action
 *
 * @return \Magento\Framework\Controller\Result\Redirect
 */
public function execute()
{
    /** @var \Mcas\PdfOrder\Api\Data\InvoiceInterface $invoice */
    $invoice = null;
    $postData = $this->getRequest()->getPostValue();
    $data = $postData;
    $id = !empty($data['invoice_id']) ? $data['invoice_id'] : null;
    $resultRedirect = $this->resultRedirectFactory->create();
    try {
        if ($id) {
            $invoice = $this->invoiceRepository->getById((int)$id);
        } else {
            unset($data['invoice_id']);
            $invoice = $this->invoiceFactory->create();
        }
        $img = $this->getUploader('image')->uploadFileAndGetName('img', $data);
        $data['img'] = $img;
        $this->dataObjectHelper->populateWithArray($invoice, $data, \Mcas\PdfOrder\Api\Data\InvoiceInterface::class);
        $this->invoiceRepository->save($invoice);
        $this->messageManager->addSuccessMessage(__('You saved the Invoice'));
        $this->dataPersistor->clear('mcas_pdforder_invoice');
        if ($this->getRequest()->getParam('back')) {
            $resultRedirect->setPath('mcas_pdforder/invoice/edit', ['invoice_id' => $invoice->getId()]);
        } else {
            $resultRedirect->setPath('mcas_pdforder/invoice');
        }
    } catch (\Magento\Framework\Exception\LocalizedException $e) {
        $this->messageManager->addErrorMessage($e->getMessage());
        $this->dataPersistor->set('mcas_pdforder_invoice', $postData);
        $resultRedirect->setPath('mcas_pdforder/invoice/edit', ['invoice_id' => $id]);
    } catch (\Exception $e) {
        $this->messageManager->addErrorMessage(__('There was a problem saving the Invoice'));
        $this->dataPersistor->set('mcas_pdforder_invoice', $postData);
        $resultRedirect->setPath('mcas_pdforder/invoice/edit', ['invoice_id' => $id]);
    }
    return $resultRedirect;
}

/**
 * @param string $type
 * @return \Mcas\PdfOrder\Model\Uploader
 * @throws \Exception
 */
protected function getUploader($type)
{
    return $this->uploaderPool->getUploader($type);
}

}

Please help, I dont find a solution to save my data

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.