diff --git a/composer.json b/composer.json
index 6504194..729457a 100644
--- a/composer.json
+++ b/composer.json
@@ -18,6 +18,7 @@
"magento/module-config": "101.2.*",
"magento/module-ui": "101.2.*",
"magento/module-backend": "102.0.*",
+ "eriocnemis/core-exception": "2.4.*",
"eriocnemis/module-region": "2.4.2",
"eriocnemis/module-region-api": "2.4.2",
"eriocnemis/module-region-admin-ui": "2.4.2",
diff --git a/src/Api/SaveRuleDataInterface.php b/src/Api/SaveRuleDataInterface.php
new file mode 100644
index 0000000..a71e39d
--- /dev/null
+++ b/src/Api/SaveRuleDataInterface.php
@@ -0,0 +1,29 @@
+collectionFactory = $collectionFactory;
+ $this->filter = $filter;
+ $this->logger = $logger;
+
+ parent::__construct(
+ $context
+ );
+ }
+
+ /**
+ * Execute action
+ *
+ * @return ResultInterface
+ */
+ public function execute(): ResultInterface
+ {
+ try {
+ $collection = $this->filter->getCollection(
+ $this->collectionFactory->create()
+ );
+
+ if ($collection->getSize()) {
+ return $this->massAction($collection);
+ }
+ $this->messageManager->addErrorMessage(
+ (string)__('Please correct the rules you requested.')
+ );
+ } catch (LocalizedException $e) {
+ $this->messageManager->addErrorMessage(
+ $e->getMessage()
+ );
+ } catch (\Exception $e) {
+ $this->logger->critical($e->getMessage());
+ $this->messageManager->addErrorMessage(
+ (string)__($this->errorMessage)
+ );
+ }
+ return $this->resultRedirectFactory->create()->setPath('*/*/index');
+ }
+
+ /**
+ * Process to collection items
+ *
+ * @param AbstractDb $collection
+ * @return ResultInterface
+ */
+ abstract protected function massAction(AbstractDb $collection);
+}
diff --git a/src/Controller/Adminhtml/Shipping/Rule/Delete.php b/src/Controller/Adminhtml/Shipping/Rule/Delete.php
index e3242cb..983edfa 100644
--- a/src/Controller/Adminhtml/Shipping/Rule/Delete.php
+++ b/src/Controller/Adminhtml/Shipping/Rule/Delete.php
@@ -7,12 +7,11 @@
namespace Eriocnemis\RegionShippingRuleAdminUi\Controller\Adminhtml\Shipping\Rule;
-use Psr\Log\LoggerInterface;
use Magento\Backend\App\Action;
use Magento\Backend\App\Action\Context;
use Magento\Framework\Controller\ResultInterface;
-use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\App\Action\HttpPostActionInterface;
+use Eriocnemis\Core\Exception\ResolveExceptionInterface;
use Eriocnemis\RegionShippingRuleApi\Api\Data\RuleInterface;
use Eriocnemis\RegionShippingRuleApi\Api\DeleteRuleByIdInterface;
@@ -26,30 +25,35 @@ class Delete extends Action implements HttpPostActionInterface
*/
const ADMIN_RESOURCE = 'Eriocnemis_Region::shipping_rule_delete';
+ /**
+ * Action name constant
+ */
+ const ACTION_NAME = 'delete';
+
/**
* @var DeleteRuleByIdInterface
*/
private $deleteRuleById;
/**
- * @var LoggerInterface
+ * @var ResolveExceptionInterface
*/
- private $logger;
+ private $resolveException;
/**
* Initialize controller
*
* @param Context $context
* @param DeleteRuleByIdInterface $deleteRuleById
- * @param LoggerInterface $logger
+ * @param ResolveExceptionInterface $resolveException
*/
public function __construct(
Context $context,
DeleteRuleByIdInterface $deleteRuleById,
- LoggerInterface $logger
+ ResolveExceptionInterface $resolveException
) {
$this->deleteRuleById = $deleteRuleById;
- $this->logger = $logger;
+ $this->resolveException = $resolveException;
parent::__construct(
$context
@@ -63,41 +67,36 @@ public function __construct(
*/
public function execute(): ResultInterface
{
+ $ruleId = (int)$this->getRequest()->getPost(RuleInterface::RULE_ID);
/** @var \Magento\Framework\Controller\Result\Redirect $result */
$result = $this->resultRedirectFactory->create();
- $ruleId = (int)$this->getRequest()->getPost(RuleInterface::RULE_ID);
- if (!$ruleId) {
- $this->messageManager->addErrorMessage(
- (string)__('Wrong request.')
- );
- return $result->setPath('*/*');
+ if ($ruleId) {
+ try {
+ $this->deleteRuleById->execute($ruleId);
+ $this->messageManager->addSuccessMessage(
+ (string)__('The Rule has been deleted.')
+ );
+ return $result->setPath('*/*/index');
+ } catch (\Exception $e) {
+ $this->resolveException->execute($e, self::ACTION_NAME);
+ }
+ return $result->setPath('*/*/edit', $this->getParams($ruleId));
}
+ return $result->setPath('*/*');
+ }
- try {
- $this->deleteRuleById->execute($ruleId);
- $this->messageManager->addSuccessMessage(
- (string)__('The Rule has been deleted.')
- );
- $result->setPath('*/*/index');
- } catch (LocalizedException $e) {
- $this->messageManager->addErrorMessage(
- $e->getMessage()
- );
- $result->setPath('*/*/edit', [
- RuleInterface::RULE_ID => $ruleId,
- '_current' => true,
- ]);
- } catch (\Exception $e) {
- $this->logger->critical($e->getMessage());
- $this->messageManager->addErrorMessage(
- (string)__('We can\'t delete the rule right now. Please review the log and try again.')
- );
- $result->setPath('*/*/edit', [
- RuleInterface::RULE_ID => $ruleId,
- '_current' => true,
- ]);
- }
- return $result;
+ /**
+ * Retrieve params
+ *
+ * @param int $ruleId
+ * @return mixed[]
+ */
+ private function getParams(int $ruleId): array
+ {
+ return [
+ RuleInterface::RULE_ID => $ruleId,
+ '_current' => true
+ ];
}
}
diff --git a/src/Controller/Adminhtml/Shipping/Rule/MassDelete.php b/src/Controller/Adminhtml/Shipping/Rule/MassDelete.php
index d1ef59d..af12350 100644
--- a/src/Controller/Adminhtml/Shipping/Rule/MassDelete.php
+++ b/src/Controller/Adminhtml/Shipping/Rule/MassDelete.php
@@ -7,19 +7,14 @@
namespace Eriocnemis\RegionShippingRuleAdminUi\Controller\Adminhtml\Shipping\Rule;
-use Psr\Log\LoggerInterface;
-use Magento\Backend\App\Action;
-use Magento\Backend\App\Action\Context;
-use Magento\Framework\App\Action\HttpPostActionInterface;
use Magento\Framework\Controller\ResultInterface;
-use Magento\Framework\Exception\LocalizedException;
-use Magento\Ui\Component\MassAction\Filter;
-use Eriocnemis\RegionShippingRule\Model\ResourceModel\Rule\CollectionFactory;
+use Magento\Framework\App\Action\HttpPostActionInterface;
+use Magento\Framework\Data\Collection\AbstractDb;
/**
* Mass delete controller
*/
-class MassDelete extends Action implements HttpPostActionInterface
+class MassDelete extends AbstractMassAction implements HttpPostActionInterface
{
/**
* Authorization level of a basic admin session
@@ -27,83 +22,23 @@ class MassDelete extends Action implements HttpPostActionInterface
const ADMIN_RESOURCE = 'Eriocnemis_Region::shipping_rule_delete';
/**
- * @var Filter
- */
- private $filter;
-
- /**
- * @var CollectionFactory
+ * @var string
*/
- private $collectionFactory;
+ protected $errorMessage = 'We can\'t delete these rules right now. Please review the log and try again.';
/**
- * @var LoggerInterface
- */
- private $logger;
-
- /**
- * Initialize controller
- *
- * @param Context $context
- * @param CollectionFactory $collectionFactory
- * @param Filter $filter
- * @param LoggerInterface $logger
- */
- public function __construct(
- Context $context,
- CollectionFactory $collectionFactory,
- Filter $filter,
- LoggerInterface $logger
- ) {
- $this->collectionFactory = $collectionFactory;
- $this->filter = $filter;
- $this->logger = $logger;
-
- parent::__construct(
- $context
- );
- }
-
- /**
- * Delete specified rules
+ * Process to collection items
*
+ * @param AbstractDb $collection
* @return ResultInterface
*/
- public function execute(): ResultInterface
+ protected function massAction(AbstractDb $collection)
{
- if (true !== $this->getRequest()->isPost()) {
- $this->messageManager->addErrorMessage(
- (string)__('Wrong request.')
- );
- return $this->resultRedirectFactory->create()->setPath('*/*');
- }
+ $collection->walk('delete');
- try {
- $collection = $this->filter->getCollection(
- $this->collectionFactory->create()
- );
-
- $size = $collection->getSize();
- if (!$size) {
- $this->messageManager->addError(
- (string)__('Please correct the rules you requested.')
- );
- return $this->resultRedirectFactory->create()->setPath('*/*');
- }
-
- $collection->walk('delete');
-
- $this->messageManager->addSuccess(
- (string)__('You deleted a total of %1 records.', $size)
- );
- } catch (LocalizedException $e) {
- $this->messageManager->addError($e->getMessage());
- } catch (\Exception $e) {
- $this->messageManager->addError(
- (string)__('We can\'t delete these rules right now. Please review the log and try again.')
- );
- $this->logger->critical($e->getMessage());
- }
- return $this->resultRedirectFactory->create()->setPath('*/*');
+ $this->messageManager->addSuccessMessage(
+ (string)__('You deleted a total of %1 records.', $collection->getSize())
+ );
+ return $this->resultRedirectFactory->create()->setPath('*/*/index');
}
}
diff --git a/src/Controller/Adminhtml/Shipping/Rule/MassStatus.php b/src/Controller/Adminhtml/Shipping/Rule/MassStatus.php
index 95e7cfa..63c8091 100644
--- a/src/Controller/Adminhtml/Shipping/Rule/MassStatus.php
+++ b/src/Controller/Adminhtml/Shipping/Rule/MassStatus.php
@@ -7,19 +7,14 @@
namespace Eriocnemis\RegionShippingRuleAdminUi\Controller\Adminhtml\Shipping\Rule;
-use Psr\Log\LoggerInterface;
-use Magento\Backend\App\Action;
-use Magento\Backend\App\Action\Context;
-use Magento\Framework\App\Action\HttpPostActionInterface;
use Magento\Framework\Controller\ResultInterface;
-use Magento\Framework\Exception\LocalizedException;
-use Magento\Ui\Component\MassAction\Filter;
-use Eriocnemis\RegionShippingRule\Model\ResourceModel\Rule\CollectionFactory;
+use Magento\Framework\App\Action\HttpPostActionInterface;
+use Magento\Framework\Data\Collection\AbstractDb;
/**
* Mass status controller
*/
-class MassStatus extends Action implements HttpPostActionInterface
+class MassStatus extends AbstractMassAction implements HttpPostActionInterface
{
/**
* Authorization level of a basic admin session
@@ -27,87 +22,25 @@ class MassStatus extends Action implements HttpPostActionInterface
const ADMIN_RESOURCE = 'Eriocnemis_Region::shipping_rule_edit';
/**
- * @var Filter
- */
- private $filter;
-
- /**
- * @var CollectionFactory
+ * @var string
*/
- private $collectionFactory;
+ protected $errorMessage = 'We can\'t change status these rules right now. Please review the log and try again.';
/**
- * @var LoggerInterface
- */
- private $logger;
-
- /**
- * Initialize controller
- *
- * @param Context $context
- * @param CollectionFactory $collectionFactory
- * @param Filter $filter
- * @param LoggerInterface $logger
- */
- public function __construct(
- Context $context,
- CollectionFactory $collectionFactory,
- Filter $filter,
- LoggerInterface $logger
- ) {
- $this->collectionFactory = $collectionFactory;
- $this->filter = $filter;
- $this->logger = $logger;
-
- parent::__construct(
- $context
- );
- }
-
- /**
- * Change specified statuses
+ * Process to collection items
*
+ * @param AbstractDb $collection
* @return ResultInterface
*/
- public function execute(): ResultInterface
+ protected function massAction(AbstractDb $collection)
{
- if (true !== $this->getRequest()->isPost()) {
- $this->messageManager->addErrorMessage(
- (string)__('Wrong request.')
- );
- return $this->resultRedirectFactory->create()->setPath('*/*');
- }
+ $status = (int)$this->getRequest()->getParam('status');
+ $collection->setDataToAll('status', $status);
+ $collection->walk('save');
- try {
- $collection = $this->filter->getCollection(
- $this->collectionFactory->create()
- );
-
- $size = $collection->getSize();
- if (!$size) {
- $this->messageManager->addError(
- (string)__('Please correct the rules you requested.')
- );
- return $this->resultRedirectFactory->create()->setPath('*/*/index');
- }
-
- $status = (int)$this->getRequest()->getParam('status');
- $collection->setDataToAll('status', $status);
- $collection->walk('save');
-
- $this->messageManager->addSuccess(
- (string)__('A total of %1 record(s) have been modified.', $size)
- );
- } catch (LocalizedException $e) {
- $this->messageManager->addError(
- $e->getMessage()
- );
- } catch (\Exception $e) {
- $this->messageManager->addError(
- (string)__('We can\'t change status these rules right now. Please review the log and try again.')
- );
- $this->logger->critical($e->getMessage());
- }
+ $this->messageManager->addSuccessMessage(
+ (string)__('A total of %1 record(s) have been modified.', $collection->getSize())
+ );
return $this->resultRedirectFactory->create()->setPath('*/*/index');
}
}
diff --git a/src/Controller/Adminhtml/Shipping/Rule/Save.php b/src/Controller/Adminhtml/Shipping/Rule/Save.php
index 2864eda..a6633f6 100644
--- a/src/Controller/Adminhtml/Shipping/Rule/Save.php
+++ b/src/Controller/Adminhtml/Shipping/Rule/Save.php
@@ -7,17 +7,14 @@
namespace Eriocnemis\RegionShippingRuleAdminUi\Controller\Adminhtml\Shipping\Rule;
-use Psr\Log\LoggerInterface;
use Magento\Backend\App\Action;
use Magento\Backend\App\Action\Context;
-use Magento\Framework\App\Action\HttpPostActionInterface;
+use Magento\Framework\Controller\ResultInterface;
use Magento\Framework\Controller\Result\Redirect;
-use Magento\Framework\Exception\LocalizedException;
-use Magento\Framework\Validation\ValidationException;
-use Magento\Framework\App\Request\DataPersistorInterface;
+use Magento\Framework\App\Action\HttpPostActionInterface;
+use Eriocnemis\Core\Exception\ResolveExceptionInterface;
use Eriocnemis\RegionShippingRuleApi\Api\Data\RuleInterface;
-use Eriocnemis\RegionShippingRuleApi\Api\SaveRuleInterface;
-use Eriocnemis\RegionShippingRuleAdminUi\Api\ResolveRuleInterface;
+use Eriocnemis\RegionShippingRuleAdminUi\Api\SaveRuleDataInterface;
/**
* Save controller
@@ -30,45 +27,34 @@ class Save extends Action implements HttpPostActionInterface
const ADMIN_RESOURCE = 'Eriocnemis_Region::shipping_rule_edit';
/**
- * @var ResolveRuleInterface
- */
- private $resolveRule;
-
- /**
- * @var SaveRuleInterface
+ * Action name constant
*/
- private $saveRule;
+ const ACTION_NAME = 'save';
/**
- * @var DataPersistorInterface
+ * @var SaveRuleDataInterface
*/
- private $dataPersistor;
+ private $saveRuleData;
/**
- * @var LoggerInterface
+ * @var ResolveExceptionInterface
*/
- private $logger;
+ private $resolveException;
/**
* Initialize controller
*
* @param Context $context
- * @param ResolveRuleInterface $resolveRule
- * @param SaveRuleInterface $saveRule
- * @param DataPersistorInterface $dataPersistor
- * @param LoggerInterface $logger
+ * @param SaveRuleDataInterface $saveRuleData
+ * @param ResolveExceptionInterface $resolveException
*/
public function __construct(
Context $context,
- ResolveRuleInterface $resolveRule,
- SaveRuleInterface $saveRule,
- DataPersistorInterface $dataPersistor,
- LoggerInterface $logger
+ SaveRuleDataInterface $saveRuleData,
+ ResolveExceptionInterface $resolveException
) {
- $this->resolveRule = $resolveRule;
- $this->saveRule = $saveRule;
- $this->dataPersistor = $dataPersistor;
- $this->logger = $logger;
+ $this->saveRuleData = $saveRuleData;
+ $this->resolveException = $resolveException;
parent::__construct(
$context
@@ -78,90 +64,62 @@ public function __construct(
/**
* Save rule
*
- * @return Redirect
+ * @return ResultInterface
*/
- public function execute(): Redirect
+ public function execute(): ResultInterface
{
- $data = $this->getRequest()->getPost('rule');
- $ruleId = $data[RuleInterface::RULE_ID] ?? null;
-
+ $ruleId = (int)$this->getRequest()->getPost(RuleInterface::RULE_ID);
/** @var Redirect $result */
$result = $this->resultRedirectFactory->create();
- if (!$this->getRequest()->isPost() || empty($data)) {
- $this->messageManager->addErrorMessage(
- (string)__('Wrong request.')
- );
- $this->redirectAfterFailure($result);
- return $result;
- }
try {
- $this->dataPersistor->set('eriocnemis_region_shipping_rule', $data);
- $rule = $this->resolveRule->execute($ruleId, $data);
- $rule = $this->saveRule->execute($rule);
- $this->messageManager->addSuccessMessage(
- (string)__('The Rule has been saved.')
- );
- $this->redirectAfterSuccess($result, (int)$rule->getId());
- } catch (ValidationException $e) {
- foreach ($e->getErrors() as $error) {
- $this->messageManager->addErrorMessage(
- $error->getMessage()
- );
- }
- $this->redirectAfterFailure($result, $ruleId);
- } catch (LocalizedException $e) {
- $this->messageManager->addErrorMessage(
- $e->getMessage()
- );
- $this->redirectAfterFailure($result, $ruleId);
+ $rule = $this->saveRuleData->execute($this->getRequest());
+ return $this->resolveResult($result, (int)$rule->getId());
} catch (\Exception $e) {
- $this->logger->critical($e->getMessage());
- $this->messageManager->addErrorMessage(
- (string)__('We can\'t save the rule right now. Please review the log and try again.')
- );
- $this->redirectAfterFailure($result, $ruleId);
+ $this->resolveException->execute($e, self::ACTION_NAME);
}
- return $result;
+ return $this->resolveFailureResult($result, $ruleId);
}
/**
- * Retrieve redirect url after save
+ * Resolve success result
*
* @param Redirect $result
* @param int $ruleId
- * @return void
+ * @return ResultInterface
*/
- private function redirectAfterSuccess(Redirect $result, $ruleId): void
+ private function resolveResult(Redirect $result, int $ruleId): ResultInterface
{
- $path = '*/*/';
- $params = [];
- if ($this->getRequest()->getParam('back')) {
- $path = '*/*/edit';
- $params = ['_current' => true, RuleInterface::RULE_ID => $ruleId];
- } elseif ($this->getRequest()->getParam('redirect_to_new')) {
- $path = '*/*/new';
- $params = ['_current' => true];
- }
- $result->setPath($path, $params);
+ return empty($this->getRequest()->getParam('back'))
+ ? $result->setPath('*/*/index')
+ : $result->setPath('*/*/edit', $this->getParams($ruleId));
}
/**
- * Retrieve redirect url after unsuccessful save
+ * Resolve failure result
*
* @param Redirect $result
* @param int|null $ruleId
- * @return void
+ * @return ResultInterface
*/
- private function redirectAfterFailure(Redirect $result, $ruleId = null): void
+ private function resolveFailureResult(Redirect $result, int $ruleId = null): ResultInterface
{
- if (null === $ruleId) {
- $result->setPath('*/*/new');
- } else {
- $result->setPath(
- '*/*/edit',
- [RuleInterface::RULE_ID => $ruleId, '_current' => true]
- );
- }
+ return empty($ruleId)
+ ? $result->setPath('*/*/new')
+ : $result->setPath('*/*/edit', $this->getParams($ruleId));
+ }
+
+ /**
+ * Retrieve params
+ *
+ * @param int $ruleId
+ * @return mixed[]
+ */
+ private function getParams(int $ruleId): array
+ {
+ return [
+ RuleInterface::RULE_ID => $ruleId,
+ '_current' => true
+ ];
}
}
diff --git a/src/Controller/Adminhtml/Shipping/Rule/Validate.php b/src/Controller/Adminhtml/Shipping/Rule/Validate.php
index 4bc7b7f..26ce3fb 100644
--- a/src/Controller/Adminhtml/Shipping/Rule/Validate.php
+++ b/src/Controller/Adminhtml/Shipping/Rule/Validate.php
@@ -7,14 +7,12 @@
namespace Eriocnemis\RegionShippingRuleAdminUi\Controller\Adminhtml\Shipping\Rule;
-use Psr\Log\LoggerInterface;
use Magento\Backend\App\Action;
use Magento\Backend\App\Action\Context;
use Magento\Framework\App\Action\HttpPostActionInterface;
use Magento\Framework\Controller\Result\JsonFactory;
use Magento\Framework\Controller\ResultInterface;
-use Magento\Framework\Exception\LocalizedException;
-use Magento\Framework\Validation\ValidationException;
+use Eriocnemis\Core\Exception\ResolveExceptionInterface;
use Eriocnemis\RegionShippingRuleApi\Api\Data\RuleInterface;
use Eriocnemis\RegionShippingRuleApi\Api\ValidateRuleInterface;
use Eriocnemis\RegionShippingRuleAdminUi\Api\ResolveRuleInterface;
@@ -29,6 +27,11 @@ class Validate extends Action implements HttpPostActionInterface
*/
const ADMIN_RESOURCE = 'Eriocnemis_Region::shipping_rule_edit';
+ /**
+ * Action name constant
+ */
+ const ACTION_NAME = 'validate';
+
/**
* @var ResolveRuleInterface
*/
@@ -45,9 +48,9 @@ class Validate extends Action implements HttpPostActionInterface
private $resultJsonFactory;
/**
- * @var LoggerInterface
+ * @var ResolveExceptionInterface
*/
- private $logger;
+ private $resolveException;
/**
* Initialize controller
@@ -56,19 +59,19 @@ class Validate extends Action implements HttpPostActionInterface
* @param JsonFactory $resultJsonFactory
* @param ResolveRuleInterface $resolveRule
* @param ValidateRuleInterface $validateRule
- * @param LoggerInterface $logger
+ * @param ResolveExceptionInterface $resolveException
*/
public function __construct(
Context $context,
JsonFactory $resultJsonFactory,
ResolveRuleInterface $resolveRule,
ValidateRuleInterface $validateRule,
- LoggerInterface $logger
+ ResolveExceptionInterface $resolveException
) {
$this->resolveRule = $resolveRule;
$this->validateRule = $validateRule;
$this->resultJsonFactory = $resultJsonFactory;
- $this->logger = $logger;
+ $this->resolveException = $resolveException;
parent::__construct(
$context
@@ -90,16 +93,12 @@ public function execute(): ResultInterface
$rule = $this->resolveRule->execute($ruleId, $data);
$this->validateRule->execute($rule);
$response = ['error' => false];
- } catch (ValidationException $e) {
+ } catch (\Exception $e) {
+ $this->resolveException->execute($e, self::ACTION_NAME);
$response['messages'] = [];
- foreach ($e->getErrors() as $error) {
- $response['messages'][] = $error->getMessage();
+ foreach ($this->messageManager->getMessages(true)->getErrors() as $message) {
+ $response['messages'][] = $message->getText();
}
- } catch (LocalizedException $e) {
- $response['message'] = $e->getMessage();
- } catch (\Exception $e) {
- $this->logger->critical($e->getMessage());
- $response['message'] = __('We can\'t validate the rule right now. Please review the log and try again.');
}
return $this->resultJsonFactory->create()->setData($response);
}
diff --git a/src/Model/SaveRuleData.php b/src/Model/SaveRuleData.php
new file mode 100644
index 0000000..fbb137a
--- /dev/null
+++ b/src/Model/SaveRuleData.php
@@ -0,0 +1,95 @@
+saveRule = $saveRule;
+ $this->resolveRule = $resolveRule;
+ $this->dataPersistor = $dataPersistor;
+ $this->messageManager = $messageManager;
+ }
+
+ /**
+ * Save data
+ *
+ * @param RequestInterface $request
+ * @return RuleInterface
+ * @throws LocalizedException
+ */
+ public function execute(RequestInterface $request): RuleInterface
+ {
+ $data = $request->getPost('rule');
+ if (empty($data)) {
+ throw new LocalizedException(
+ __('Wrong request.')
+ );
+ }
+
+ $ruleId = $data[RuleInterface::RULE_ID] ?? null;
+ $this->dataPersistor->set('eriocnemis_region_shipping_rule', $data);
+
+ $rule = $this->saveRule->execute(
+ $this->resolveRule->execute($ruleId, $data)
+ );
+
+ $this->messageManager->addSuccessMessage(
+ (string)__('The Rule has been saved.')
+ );
+
+ return $rule;
+ }
+}
diff --git a/src/etc/adminhtml/di.xml b/src/etc/adminhtml/di.xml
index a976feb..a87aaa1 100644
--- a/src/etc/adminhtml/di.xml
+++ b/src/etc/adminhtml/di.xml
@@ -9,6 +9,7 @@
xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
+