b374k
m1n1 1.01
Apache/2.4.41 (Ubuntu)
Linux vmi616275.contaboserver.net 5.4.0-84-generic #94-Ubuntu SMP Thu Aug 26 20:27:37 UTC 2021 x86_64
uid=33(www-data) gid=33(www-data) groups=33(www-data)
server ip : 62.171.164.128 | your ip : 127.0.0.1
safemode OFF
 >  / home / dev2.destoffenstraat.com / app / code / Amasty / OrderExport / Controller / Adminhtml / Connection /
Filename/home/dev2.destoffenstraat.com/app/code/Amasty/OrderExport/Controller/Adminhtml/Connection/Save.php
Size3.19 kb
Permissionrw-r--r--
Ownerroot : root
Create time17-Aug-2025 10:26
Last modified14-Jun-2025 23:42
Last accessed22-Aug-2025 19:53
Actionsedit | rename | delete | download (gzip)
Viewtext | code | image
<?php

declare(strict_types=1);

/**
* @author Amasty Team
* @copyright Copyright (c) Amasty (https://www.amasty.com)
* @package Export Orders for Magento 2
*/

namespace Amasty\OrderExport\Controller\Adminhtml\Connection;

use Amasty\OrderExport\Api\ConnectionRepositoryInterface;
use Amasty\OrderExport\Api\Data\ConnectionInterfaceFactory;
use Amasty\OrderExport\Model\Connection\Connection;
use Amasty\OrderExport\Ui\DataProvider\Connection\Form;
use Magento\Backend\App\Action;
use Magento\Framework\App\Request\DataPersistorInterface;
use Magento\Framework\Exception\LocalizedException;
use Psr\Log\LoggerInterface;

class Save extends Action
{
public const ADMIN_RESOURCE = 'Amasty_OrderExport::order_export_connections';

/**
* @var LoggerInterface
*/
private $logger;

/**
* @var ConnectionRepositoryInterface
*/
private $connectionRepository;

/**
* @var ConnectionInterfaceFactory
*/
private $connectionFactory;

/**
* @var DataPersistorInterface
*/
private $dataPersistor;

public function __construct(
Action\Context $context,
ConnectionRepositoryInterface $connectionRepository,
ConnectionInterfaceFactory $connectionFactory,
LoggerInterface $logger,
DataPersistorInterface $dataPersistor
) {
parent::__construct($context);
$this->logger = $logger;
$this->connectionRepository = $connectionRepository;
$this->connectionFactory = $connectionFactory;
$this->dataPersistor = $dataPersistor;
}

public function execute()
{
try {
if ($data = $this->getRequest()->getPostValue()) {
if ($connectionId = (int)$this->getRequest()->getParam(Connection::ID)) {
$model = $this->connectionRepository->getById($connectionId);
} else {
$model = $this->connectionRepository->getEmptyConnectionModel();
}
$model->addData($data);
$this->connectionRepository->save($model);

$this->messageManager->addSuccessMessage(__('You saved the connection.'));

if ($this->getRequest()->getParam('back')) {
return $this->resultRedirectFactory->create()
->setPath('*/*/edit', [Connection::ID => $model->getConnectionId()]);
}
}
} catch (LocalizedException $e) {
$this->messageManager->addErrorMessage($e->getMessage());
$this->dataPersistor->set(Form::CONNECTION_DATA, $data);

if (isset($model) && $model->getConnectionId()) {
return $this->resultRedirectFactory->create()
->setPath('*/*/edit', [Connection::ID => $model->getConnectionId()]);
} else {
return $this->resultRedirectFactory->create()->setPath('*/*/edit');
}
} catch (\Exception $e) {
$this->messageManager->addErrorMessage(__('An error has occurred'));
$this->logger->critical($e);

return $this->resultRedirectFactory->create()->setPath('*/*');
}

return $this->resultRedirectFactory->create()->setPath('*/*');
}
}