-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
359 additions
and
304 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
/** | ||
* Copyright © Eriocnemis, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Eriocnemis\RegionShippingRuleAdminUi\Api; | ||
|
||
use Magento\Framework\App\RequestInterface; | ||
use Magento\Framework\Exception\LocalizedException; | ||
use Eriocnemis\RegionShippingRuleApi\Api\Data\RuleInterface; | ||
|
||
/** | ||
* Save data | ||
* | ||
* @api | ||
*/ | ||
interface SaveRuleDataInterface | ||
{ | ||
/** | ||
* Save data | ||
* | ||
* @param RequestInterface $request | ||
* @return RuleInterface | ||
* @throws LocalizedException | ||
*/ | ||
public function execute(RequestInterface $request): RuleInterface; | ||
} |
105 changes: 105 additions & 0 deletions
105
src/Controller/Adminhtml/Shipping/Rule/AbstractMassAction.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
<?php | ||
/** | ||
* Copyright © Eriocnemis, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Eriocnemis\RegionShippingRuleAdminUi\Controller\Adminhtml\Shipping\Rule; | ||
|
||
use Psr\Log\LoggerInterface; | ||
use Magento\Backend\App\Action; | ||
use Magento\Backend\App\Action\Context; | ||
use Magento\Ui\Component\MassAction\Filter; | ||
use Magento\Framework\Data\Collection\AbstractDb; | ||
use Magento\Framework\Controller\ResultInterface; | ||
use Magento\Framework\Exception\LocalizedException; | ||
use Eriocnemis\RegionShippingRule\Model\ResourceModel\Rule\CollectionFactory; | ||
|
||
/** | ||
* Abstract mass action controller | ||
*/ | ||
abstract class AbstractMassAction extends Action | ||
{ | ||
/** | ||
* @var Filter | ||
*/ | ||
protected $filter; | ||
|
||
/** | ||
* @var CollectionFactory | ||
*/ | ||
protected $collectionFactory; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
protected $errorMessage; | ||
|
||
/** | ||
* @var LoggerInterface | ||
*/ | ||
protected $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 | ||
); | ||
} | ||
|
||
/** | ||
* 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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.