From ff4bae4a91cca4845c975fe11c740575141f231c Mon Sep 17 00:00:00 2001 From: Fanny DECLERCK Date: Tue, 4 Jun 2019 15:22:21 +0200 Subject: [PATCH] Add Retailer Grid massAction --- .../Adminhtml/Retailer/MassAllowDelivery.php | 55 +++++++++++++++++++ Controller/Adminhtml/Retailer/MassDelete.php | 54 ++++++++++++++++++ Controller/Adminhtml/Retailer/MassDisable.php | 55 +++++++++++++++++++ .../Retailer/MassDisallowDelivery.php | 55 +++++++++++++++++++ Controller/Adminhtml/Retailer/MassEnable.php | 55 +++++++++++++++++++ Model/RetailerRepository.php | 2 +- etc/acl.xml | 5 +- .../ui_component/smile_retailer_listing.xml | 37 +++++++++++++ 8 files changed, 315 insertions(+), 3 deletions(-) create mode 100644 Controller/Adminhtml/Retailer/MassAllowDelivery.php create mode 100644 Controller/Adminhtml/Retailer/MassDelete.php create mode 100644 Controller/Adminhtml/Retailer/MassDisable.php create mode 100644 Controller/Adminhtml/Retailer/MassDisallowDelivery.php create mode 100644 Controller/Adminhtml/Retailer/MassEnable.php diff --git a/Controller/Adminhtml/Retailer/MassAllowDelivery.php b/Controller/Adminhtml/Retailer/MassAllowDelivery.php new file mode 100644 index 0000000..db81f79 --- /dev/null +++ b/Controller/Adminhtml/Retailer/MassAllowDelivery.php @@ -0,0 +1,55 @@ + + * @copyright 2019 Smile + * @license Open Software License ("OSL") v. 3.0 + */ + +namespace Smile\Retailer\Controller\Adminhtml\Retailer; + +use Magento\Framework\App\Action\HttpPostActionInterface; +use Magento\Framework\Controller\ResultFactory; +use Magento\Backend\App\Action\Context; +use Smile\Retailer\Controller\Adminhtml\AbstractRetailer; + +/** + * Retailer Adminhtml MassAllowDelivery controller. + * + * @category Smile + * @package Smile\Retailer + * @author Fanny DECLERCK + */ +class MassAllowDelivery extends AbstractRetailer implements HttpPostActionInterface +{ + /** + * Execute action + * + * @return \Magento\Backend\Model\View\Result\Redirect + * @throws \Magento\Framework\Exception\LocalizedException|\Exception + */ + public function execute() + { + $retailerIds = $this->getRequest()->getParam('selected'); + foreach ($retailerIds as $id) { + $model = $this->retailerRepository->get($id); + $model->setData('allow_store_delivery', true); + $this->retailerRepository->save($model); + } + + $this->messageManager->addSuccessMessage( + __('A total of %1 record(s) have been allowed to store delivery.', count($retailerIds)) + ); + + /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */ + $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT); + + return $resultRedirect->setPath('*/*/'); + } +} diff --git a/Controller/Adminhtml/Retailer/MassDelete.php b/Controller/Adminhtml/Retailer/MassDelete.php new file mode 100644 index 0000000..335c9ed --- /dev/null +++ b/Controller/Adminhtml/Retailer/MassDelete.php @@ -0,0 +1,54 @@ + + * @copyright 2019 Smile + * @license Open Software License ("OSL") v. 3.0 + */ + +namespace Smile\Retailer\Controller\Adminhtml\Retailer; + +use Magento\Framework\App\Action\HttpPostActionInterface; +use Magento\Framework\Controller\ResultFactory; +use Magento\Backend\App\Action\Context; +use Smile\Retailer\Controller\Adminhtml\AbstractRetailer; + +/** + * Retailer Adminhtml MassDelete controller. + * + * @category Smile + * @package Smile\Retailer + * @author Fanny DECLERCK + */ +class MassDelete extends AbstractRetailer implements HttpPostActionInterface +{ + /** + * Execute action + * + * @return \Magento\Backend\Model\View\Result\Redirect + * @throws \Magento\Framework\Exception\LocalizedException|\Exception + */ + public function execute() + { + $retailerIds = $this->getRequest()->getParam('selected'); + foreach ($retailerIds as $id) { + $model = $this->retailerRepository->get($id); + $this->retailerRepository->delete($model); + } + + $this->messageManager->addSuccessMessage( + __('A total of %1 record(s) have been deleted.', count($retailerIds)) + ); + + /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */ + $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT); + + return $resultRedirect->setPath('*/*/'); + } +} diff --git a/Controller/Adminhtml/Retailer/MassDisable.php b/Controller/Adminhtml/Retailer/MassDisable.php new file mode 100644 index 0000000..190c18b --- /dev/null +++ b/Controller/Adminhtml/Retailer/MassDisable.php @@ -0,0 +1,55 @@ + + * @copyright 2019 Smile + * @license Open Software License ("OSL") v. 3.0 + */ + +namespace Smile\Retailer\Controller\Adminhtml\Retailer; + +use Magento\Framework\App\Action\HttpPostActionInterface; +use Magento\Framework\Controller\ResultFactory; +use Magento\Backend\App\Action\Context; +use Smile\Retailer\Controller\Adminhtml\AbstractRetailer; + +/** + * Retailer Adminhtml MassDisable controller. + * + * @category Smile + * @package Smile\Retailer + * @author Fanny DECLERCK + */ +class MassDisable extends AbstractRetailer implements HttpPostActionInterface +{ + /** + * Execute action + * + * @return \Magento\Backend\Model\View\Result\Redirect + * @throws \Magento\Framework\Exception\LocalizedException|\Exception + */ + public function execute() + { + $retailerIds = $this->getRequest()->getParam('selected'); + foreach ($retailerIds as $id) { + $model = $this->retailerRepository->get($id); + $model->setData('is_active', false); + $this->retailerRepository->save($model); + } + + $this->messageManager->addSuccessMessage( + __('A total of %1 record(s) have been disabled.', count($retailerIds)) + ); + + /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */ + $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT); + + return $resultRedirect->setPath('*/*/'); + } +} diff --git a/Controller/Adminhtml/Retailer/MassDisallowDelivery.php b/Controller/Adminhtml/Retailer/MassDisallowDelivery.php new file mode 100644 index 0000000..fc721f2 --- /dev/null +++ b/Controller/Adminhtml/Retailer/MassDisallowDelivery.php @@ -0,0 +1,55 @@ + + * @copyright 2019 Smile + * @license Open Software License ("OSL") v. 3.0 + */ + +namespace Smile\Retailer\Controller\Adminhtml\Retailer; + +use Magento\Framework\App\Action\HttpPostActionInterface; +use Magento\Framework\Controller\ResultFactory; +use Magento\Backend\App\Action\Context; +use Smile\Retailer\Controller\Adminhtml\AbstractRetailer; + +/** + * Retailer Adminhtml MassDisallowDelivery controller. + * + * @category Smile + * @package Smile\Retailer + * @author Fanny DECLERCK + */ +class MassDisallowDelivery extends AbstractRetailer implements HttpPostActionInterface +{ + /** + * Execute action + * + * @return \Magento\Backend\Model\View\Result\Redirect + * @throws \Magento\Framework\Exception\LocalizedException|\Exception + */ + public function execute() + { + $retailerIds = $this->getRequest()->getParam('selected'); + foreach ($retailerIds as $id) { + $model = $this->retailerRepository->get($id); + $model->setData('allow_store_delivery', false); + $this->retailerRepository->save($model); + } + + $this->messageManager->addSuccessMessage( + __('A total of %1 record(s) have been disallowed to store delivery.', count($retailerIds)) + ); + + /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */ + $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT); + + return $resultRedirect->setPath('*/*/'); + } +} diff --git a/Controller/Adminhtml/Retailer/MassEnable.php b/Controller/Adminhtml/Retailer/MassEnable.php new file mode 100644 index 0000000..f81f72c --- /dev/null +++ b/Controller/Adminhtml/Retailer/MassEnable.php @@ -0,0 +1,55 @@ + + * @copyright 2019 Smile + * @license Open Software License ("OSL") v. 3.0 + */ + +namespace Smile\Retailer\Controller\Adminhtml\Retailer; + +use Magento\Framework\App\Action\HttpPostActionInterface; +use Magento\Framework\Controller\ResultFactory; +use Magento\Backend\App\Action\Context; +use Smile\Retailer\Controller\Adminhtml\AbstractRetailer; + +/** + * Retailer Adminhtml MassEnable controller. + * + * @category Smile + * @package Smile\Retailer + * @author Fanny DECLERCK + */ +class MassEnable extends AbstractRetailer implements HttpPostActionInterface +{ + /** + * Execute action + * + * @return \Magento\Backend\Model\View\Result\Redirect + * @throws \Magento\Framework\Exception\LocalizedException|\Exception + */ + public function execute() + { + $retailerIds = $this->getRequest()->getParam('selected'); + foreach ($retailerIds as $id) { + $model = $this->retailerRepository->get($id); + $model->setData('is_active', true); + $this->retailerRepository->save($model); + } + + $this->messageManager->addSuccessMessage( + __('A total of %1 record(s) have been enabled.', count($retailerIds)) + ); + + /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */ + $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT); + + return $resultRedirect->setPath('*/*/'); + } +} diff --git a/Model/RetailerRepository.php b/Model/RetailerRepository.php index 306c376..e24b25b 100644 --- a/Model/RetailerRepository.php +++ b/Model/RetailerRepository.php @@ -16,7 +16,6 @@ use Magento\Framework\Api\SortOrder; use Magento\Framework\Api\ExtensionAttribute\JoinProcessorInterface; use Magento\Framework\Api\SearchCriteria\CollectionProcessorInterface; - use Smile\Retailer\Api\Data\RetailerInterface; use Smile\Retailer\Api\Data\RetailerSearchResultsInterface; use Smile\Retailer\Api\RetailerRepositoryInterface; @@ -30,6 +29,7 @@ * @category Smile * @package Smile\Retailer * @author Romain Ruaud + * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ class RetailerRepository implements RetailerRepositoryInterface { diff --git a/etc/acl.xml b/etc/acl.xml index a26e8d7..8a8cd4c 100644 --- a/etc/acl.xml +++ b/etc/acl.xml @@ -12,7 +12,8 @@ * @category Smile * @package Smile\Retailer * @author Romain Ruaud - * @copyright 2017 Smile + * @author Fanny DECLERCK + * @copyright 2019 Smile * @license Open Software License ("OSL") v. 3.0 */ --> @@ -21,7 +22,7 @@ - + diff --git a/view/adminhtml/ui_component/smile_retailer_listing.xml b/view/adminhtml/ui_component/smile_retailer_listing.xml index 944f82f..4b0afab 100644 --- a/view/adminhtml/ui_component/smile_retailer_listing.xml +++ b/view/adminhtml/ui_component/smile_retailer_listing.xml @@ -88,6 +88,43 @@ + + + + + enable + + + + + + + disable + + + + + + + allow_delivery + + + + + + + disallow_delivery + + + + + + + delete + + + +