ltsecurityinc安防产品在线商城代码
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
<?php declare(strict_types=1);
|
||||
/**
|
||||
* Copyright (c) 2021
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
namespace Olegnax\Carousel\Controller\Adminhtml;
|
||||
|
||||
|
||||
use Magento\Backend\App\Action;
|
||||
use Magento\Backend\App\Action\Context;
|
||||
use Magento\Backend\Model\View\Result\Page;
|
||||
use Magento\Framework\Registry;
|
||||
|
||||
abstract class Carousel extends Action
|
||||
{
|
||||
const ADMIN_RESOURCE = 'Olegnax_Carousel::Carousel';
|
||||
protected $_coreRegistry;
|
||||
|
||||
/**
|
||||
* @param Context $context
|
||||
* @param Registry $coreRegistry
|
||||
*/
|
||||
public function __construct(
|
||||
Context $context,
|
||||
Registry $coreRegistry
|
||||
) {
|
||||
$this->_coreRegistry = $coreRegistry;
|
||||
parent::__construct($context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Init page
|
||||
*
|
||||
* @param Page $resultPage
|
||||
* @return Page
|
||||
*/
|
||||
public function initPage($resultPage)
|
||||
{
|
||||
$resultPage->setActiveMenu(self::ADMIN_RESOURCE)
|
||||
->addBreadcrumb(__('Olegnax'), __('Olegnax'))
|
||||
->addBreadcrumb(__('Carousel'), __('Carousel'));
|
||||
return $resultPage;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
<?php declare(strict_types=1);
|
||||
/**
|
||||
* Copyright (c) 2021
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
namespace Olegnax\Carousel\Controller\Adminhtml\Carousel;
|
||||
|
||||
|
||||
use Exception;
|
||||
use Magento\Backend\Model\View\Result\Redirect;
|
||||
use Magento\Framework\Controller\ResultInterface;
|
||||
use Olegnax\Carousel\Model\Carousel;
|
||||
|
||||
class Delete extends \Olegnax\Carousel\Controller\Adminhtml\Carousel
|
||||
{
|
||||
|
||||
const ADMIN_RESOURCE = 'Olegnax_Carousel::Carousel_delete';
|
||||
/**
|
||||
* Delete action
|
||||
*
|
||||
* @return ResultInterface
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
/** @var Redirect $resultRedirect */
|
||||
$resultRedirect = $this->resultRedirectFactory->create();
|
||||
// check if we know what should be deleted
|
||||
$id = $this->getRequest()->getParam('carousel_id');
|
||||
if ($id) {
|
||||
try {
|
||||
// init model and delete
|
||||
$model = $this->_objectManager->create(Carousel::class);
|
||||
$model->load($id);
|
||||
$model->delete();
|
||||
// display success message
|
||||
$this->messageManager->addSuccessMessage(__('You deleted the Carousel.'));
|
||||
// go to grid
|
||||
return $resultRedirect->setPath('*/*/');
|
||||
} catch (Exception $e) {
|
||||
// display error message
|
||||
$this->messageManager->addErrorMessage($e->getMessage());
|
||||
// go back to edit form
|
||||
return $resultRedirect->setPath('*/*/edit', ['carousel_id' => $id]);
|
||||
}
|
||||
}
|
||||
// display error message
|
||||
$this->messageManager->addErrorMessage(__('We can\'t find a Carousel to delete.'));
|
||||
// go to grid
|
||||
return $resultRedirect->setPath('*/*/');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,90 @@
|
||||
<?php declare(strict_types=1);
|
||||
/**
|
||||
* Copyright (c) 2021
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
namespace Olegnax\Carousel\Controller\Adminhtml\Carousel;
|
||||
|
||||
|
||||
use Magento\Backend\App\Action\Context;
|
||||
use Magento\Backend\Model\View\Result\Page;
|
||||
use Magento\Backend\Model\View\Result\Redirect;
|
||||
use Magento\Framework\Controller\ResultInterface;
|
||||
use Magento\Framework\Registry;
|
||||
use Magento\Framework\View\Result\PageFactory;
|
||||
use Olegnax\Carousel\Model\Carousel;
|
||||
|
||||
class Edit extends \Olegnax\Carousel\Controller\Adminhtml\Carousel
|
||||
{
|
||||
const ADMIN_RESOURCE = 'Olegnax_Carousel::Carousel_view';
|
||||
|
||||
protected $resultPageFactory;
|
||||
|
||||
/**
|
||||
* @param Context $context
|
||||
* @param Registry $coreRegistry
|
||||
* @param PageFactory $resultPageFactory
|
||||
*/
|
||||
public function __construct(
|
||||
Context $context,
|
||||
Registry $coreRegistry,
|
||||
PageFactory $resultPageFactory
|
||||
) {
|
||||
$this->resultPageFactory = $resultPageFactory;
|
||||
parent::__construct($context, $coreRegistry);
|
||||
}
|
||||
|
||||
/**
|
||||
* Edit action
|
||||
*
|
||||
* @return ResultInterface
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
// 1. Get ID and create model
|
||||
$id = $this->getRequest()->getParam('carousel_id');
|
||||
$model = $this->_objectManager->create(Carousel::class);
|
||||
|
||||
// 2. Initial checking
|
||||
if ($id) {
|
||||
$model->load($id);
|
||||
if (!$model->getId()) {
|
||||
$this->messageManager->addErrorMessage(__('This Carousel no longer exists.'));
|
||||
/** @var Redirect $resultRedirect */
|
||||
$resultRedirect = $this->resultRedirectFactory->create();
|
||||
return $resultRedirect->setPath('*/*/');
|
||||
}
|
||||
}
|
||||
$this->_coreRegistry->register('olegnax_carousel_carousel', $model);
|
||||
|
||||
// 3. Build edit form
|
||||
/** @var Page $resultPage */
|
||||
$resultPage = $this->resultPageFactory->create();
|
||||
$this->initPage($resultPage)->addBreadcrumb(
|
||||
$id ? __('Edit Carousel') : __('New Carousel'),
|
||||
$id ? __('Edit Carousel') : __('New Carousel')
|
||||
);
|
||||
$resultPage->getConfig()->getTitle()->prepend(__('Carousels'));
|
||||
$resultPage->getConfig()->getTitle()->prepend($model->getId() ? __('Edit Carousel %1', $model->getId()) : __('New Carousel'));
|
||||
return $resultPage;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
<?php declare(strict_types=1);
|
||||
/**
|
||||
* Copyright (c) 2021
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
namespace Olegnax\Carousel\Controller\Adminhtml\Carousel;
|
||||
|
||||
|
||||
use Magento\Backend\App\Action;
|
||||
use Magento\Backend\App\Action\Context;
|
||||
use Magento\Framework\Controller\ResultInterface;
|
||||
use Magento\Framework\View\Result\PageFactory;
|
||||
|
||||
class Index extends Action
|
||||
{
|
||||
const ADMIN_RESOURCE = 'Olegnax_Carousel::Carousel';
|
||||
|
||||
protected $resultPageFactory;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param Context $context
|
||||
* @param PageFactory $resultPageFactory
|
||||
*/
|
||||
public function __construct(
|
||||
Context $context,
|
||||
PageFactory $resultPageFactory
|
||||
) {
|
||||
$this->resultPageFactory = $resultPageFactory;
|
||||
parent::__construct($context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Index action
|
||||
*
|
||||
* @return ResultInterface
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
$resultPage = $this->resultPageFactory->create();
|
||||
$resultPage->getConfig()->getTitle()->prepend(__("Carousel"));
|
||||
return $resultPage;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
<?php declare(strict_types=1);
|
||||
/**
|
||||
* Copyright (c) 2021
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
namespace Olegnax\Carousel\Controller\Adminhtml\Carousel;
|
||||
|
||||
|
||||
use Exception;
|
||||
use Magento\Backend\App\Action;
|
||||
use Magento\Backend\App\Action\Context;
|
||||
use Magento\Framework\Controller\Result\Json;
|
||||
use Magento\Framework\Controller\Result\JsonFactory;
|
||||
use Magento\Framework\Controller\ResultInterface;
|
||||
use Olegnax\Carousel\Model\Carousel;
|
||||
|
||||
class InlineEdit extends Action
|
||||
{
|
||||
const ADMIN_RESOURCE = 'Olegnax_Carousel::Carousel_save';
|
||||
|
||||
protected $jsonFactory;
|
||||
|
||||
/**
|
||||
* @param Context $context
|
||||
* @param JsonFactory $jsonFactory
|
||||
*/
|
||||
public function __construct(
|
||||
Context $context,
|
||||
JsonFactory $jsonFactory
|
||||
) {
|
||||
parent::__construct($context);
|
||||
$this->jsonFactory = $jsonFactory;
|
||||
}
|
||||
|
||||
/**
|
||||
* Inline edit action
|
||||
*
|
||||
* @return ResultInterface
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
/** @var Json $resultJson */
|
||||
$resultJson = $this->jsonFactory->create();
|
||||
$error = false;
|
||||
$messages = [];
|
||||
|
||||
if ($this->getRequest()->getParam('isAjax')) {
|
||||
$postItems = $this->getRequest()->getParam('items', []);
|
||||
if (!count($postItems)) {
|
||||
$messages[] = __('Please correct the data sent.');
|
||||
$error = true;
|
||||
} else {
|
||||
foreach (array_keys($postItems) as $modelid) {
|
||||
/** @var Carousel $model */
|
||||
$model = $this->_objectManager->create(Carousel::class)->load($modelid);
|
||||
try {
|
||||
$model->setData(array_merge($model->getData(), $postItems[$modelid]));
|
||||
$model->save();
|
||||
} catch (Exception $e) {
|
||||
$messages[] = "[Carousel ID: {$modelid}] {$e->getMessage()}";
|
||||
$error = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $resultJson->setData([
|
||||
'messages' => $messages,
|
||||
'error' => $error
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
<?php declare(strict_types=1);
|
||||
/**
|
||||
* Copyright (c) 2021
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
namespace Olegnax\Carousel\Controller\Adminhtml\Carousel;
|
||||
|
||||
|
||||
use Magento\Backend\App\Action\Context;
|
||||
use Magento\Backend\Model\View\Result\ForwardFactory;
|
||||
use Magento\Framework\Controller\Result\Forward;
|
||||
use Magento\Framework\Controller\ResultInterface;
|
||||
use Magento\Framework\Registry;
|
||||
use Olegnax\Carousel\Controller\Adminhtml\Carousel;
|
||||
|
||||
class NewAction extends Carousel
|
||||
{
|
||||
const ADMIN_RESOURCE = 'Olegnax_Carousel::Carousel_save';
|
||||
|
||||
protected $resultForwardFactory;
|
||||
|
||||
/**
|
||||
* @param Context $context
|
||||
* @param Registry $coreRegistry
|
||||
* @param ForwardFactory $resultForwardFactory
|
||||
*/
|
||||
public function __construct(
|
||||
Context $context,
|
||||
Registry $coreRegistry,
|
||||
ForwardFactory $resultForwardFactory
|
||||
) {
|
||||
$this->resultForwardFactory = $resultForwardFactory;
|
||||
parent::__construct($context, $coreRegistry);
|
||||
}
|
||||
|
||||
/**
|
||||
* New action
|
||||
*
|
||||
* @return ResultInterface
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
/** @var Forward $resultForward */
|
||||
$resultForward = $this->resultForwardFactory->create();
|
||||
return $resultForward->forward('edit');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,96 @@
|
||||
<?php declare(strict_types=1);
|
||||
/**
|
||||
* Copyright (c) 2021
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
namespace Olegnax\Carousel\Controller\Adminhtml\Carousel;
|
||||
|
||||
use Exception;
|
||||
use Magento\Backend\App\Action;
|
||||
use Magento\Backend\App\Action\Context;
|
||||
use Magento\Backend\Model\View\Result\Redirect;
|
||||
use Magento\Framework\App\Request\DataPersistorInterface;
|
||||
use Magento\Framework\Controller\ResultInterface;
|
||||
use Magento\Framework\Exception\LocalizedException;
|
||||
use Olegnax\Carousel\Model\Carousel;
|
||||
|
||||
|
||||
class Save extends Action
|
||||
{
|
||||
const ADMIN_RESOURCE = 'Olegnax_Carousel::Carousel_save';
|
||||
|
||||
protected $dataPersistor;
|
||||
|
||||
/**
|
||||
* @param Context $context
|
||||
* @param DataPersistorInterface $dataPersistor
|
||||
*/
|
||||
public function __construct(
|
||||
Context $context,
|
||||
DataPersistorInterface $dataPersistor
|
||||
) {
|
||||
$this->dataPersistor = $dataPersistor;
|
||||
parent::__construct($context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Save action
|
||||
*
|
||||
* @return ResultInterface
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
/** @var Redirect $resultRedirect */
|
||||
$resultRedirect = $this->resultRedirectFactory->create();
|
||||
$data = $this->getRequest()->getPostValue();
|
||||
if ($data) {
|
||||
$id = $this->getRequest()->getParam('carousel_id');
|
||||
|
||||
$model = $this->_objectManager->create(Carousel::class)->load($id);
|
||||
if (!$model->getId() && $id) {
|
||||
$this->messageManager->addErrorMessage(__('This Carousel no longer exists.'));
|
||||
return $resultRedirect->setPath('*/*/');
|
||||
}
|
||||
|
||||
$model->setData($data);
|
||||
|
||||
try {
|
||||
$model->save();
|
||||
$this->messageManager->addSuccessMessage(__('You saved the Carousel.'));
|
||||
$this->dataPersistor->clear('olegnax_carousel_carousel');
|
||||
|
||||
if ($this->getRequest()->getParam('back')) {
|
||||
return $resultRedirect->setPath('*/*/edit', ['carousel_id' => $model->getId()]);
|
||||
}
|
||||
return $resultRedirect->setPath('*/*/');
|
||||
} catch (LocalizedException $e) {
|
||||
$this->messageManager->addErrorMessage($e->getMessage());
|
||||
} catch (Exception $e) {
|
||||
$this->messageManager->addExceptionMessage($e, __('Something went wrong while saving the Carousel.'));
|
||||
}
|
||||
|
||||
$this->dataPersistor->set('olegnax_carousel_carousel', $data);
|
||||
return $resultRedirect->setPath('*/*/edit', ['carousel_id' => $this->getRequest()->getParam('carousel_id')]);
|
||||
}
|
||||
return $resultRedirect->setPath('*/*/');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
<?php declare(strict_types=1);
|
||||
/**
|
||||
* Copyright (c) 2021
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
namespace Olegnax\Carousel\Controller\Adminhtml;
|
||||
|
||||
|
||||
use Magento\Backend\App\Action;
|
||||
use Magento\Backend\App\Action\Context;
|
||||
use Magento\Backend\Model\View\Result\Page;
|
||||
use Magento\Framework\Registry;
|
||||
|
||||
abstract class Slide extends Action
|
||||
{
|
||||
|
||||
const ADMIN_RESOURCE = 'Olegnax_Carousel::Slide';
|
||||
protected $_coreRegistry;
|
||||
|
||||
/**
|
||||
* @param Context $context
|
||||
* @param Registry $coreRegistry
|
||||
*/
|
||||
public function __construct(
|
||||
Context $context,
|
||||
Registry $coreRegistry
|
||||
) {
|
||||
$this->_coreRegistry = $coreRegistry;
|
||||
parent::__construct($context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Init page
|
||||
*
|
||||
* @param Page $resultPage
|
||||
* @return Page
|
||||
*/
|
||||
public function initPage($resultPage)
|
||||
{
|
||||
$resultPage->setActiveMenu(self::ADMIN_RESOURCE)
|
||||
->addBreadcrumb(__('Olegnax'), __('Olegnax'))
|
||||
->addBreadcrumb(__('Slide'), __('Slide'));
|
||||
return $resultPage;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
<?php declare(strict_types=1);
|
||||
/**
|
||||
* Copyright (c) 2021
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
namespace Olegnax\Carousel\Controller\Adminhtml\Slide;
|
||||
|
||||
|
||||
use Exception;
|
||||
use Magento\Backend\Model\View\Result\Redirect;
|
||||
use Magento\Framework\Controller\ResultInterface;
|
||||
use Olegnax\Carousel\Model\Slide;
|
||||
|
||||
class Delete extends \Olegnax\Carousel\Controller\Adminhtml\Slide
|
||||
{
|
||||
const ADMIN_RESOURCE = 'Olegnax_Carousel::Slide_delete';
|
||||
/**
|
||||
* Delete action
|
||||
*
|
||||
* @return ResultInterface
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
/** @var Redirect $resultRedirect */
|
||||
$resultRedirect = $this->resultRedirectFactory->create();
|
||||
// check if we know what should be deleted
|
||||
$id = $this->getRequest()->getParam('slide_id');
|
||||
if ($id) {
|
||||
try {
|
||||
// init model and delete
|
||||
$model = $this->_objectManager->create(Slide::class);
|
||||
$model->load($id);
|
||||
$model->delete();
|
||||
// display success message
|
||||
$this->messageManager->addSuccessMessage(__('You deleted the Slide.'));
|
||||
// go to grid
|
||||
return $resultRedirect->setPath('*/*/');
|
||||
} catch (Exception $e) {
|
||||
// display error message
|
||||
$this->messageManager->addErrorMessage($e->getMessage());
|
||||
// go back to edit form
|
||||
return $resultRedirect->setPath('*/*/edit', ['slide_id' => $id]);
|
||||
}
|
||||
}
|
||||
// display error message
|
||||
$this->messageManager->addErrorMessage(__('We can\'t find a Slide to delete.'));
|
||||
// go to grid
|
||||
return $resultRedirect->setPath('*/*/');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,90 @@
|
||||
<?php declare(strict_types=1);
|
||||
/**
|
||||
* Copyright (c) 2021
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
namespace Olegnax\Carousel\Controller\Adminhtml\Slide;
|
||||
|
||||
|
||||
use Magento\Backend\App\Action\Context;
|
||||
use Magento\Backend\Model\View\Result\Page;
|
||||
use Magento\Backend\Model\View\Result\Redirect;
|
||||
use Magento\Framework\Controller\ResultInterface;
|
||||
use Magento\Framework\Registry;
|
||||
use Magento\Framework\View\Result\PageFactory;
|
||||
use Olegnax\Carousel\Model\Slide;
|
||||
|
||||
class Edit extends \Olegnax\Carousel\Controller\Adminhtml\Slide
|
||||
{
|
||||
const ADMIN_RESOURCE = 'Olegnax_Carousel::Slide_view';
|
||||
|
||||
protected $resultPageFactory;
|
||||
|
||||
/**
|
||||
* @param Context $context
|
||||
* @param Registry $coreRegistry
|
||||
* @param PageFactory $resultPageFactory
|
||||
*/
|
||||
public function __construct(
|
||||
Context $context,
|
||||
Registry $coreRegistry,
|
||||
PageFactory $resultPageFactory
|
||||
) {
|
||||
$this->resultPageFactory = $resultPageFactory;
|
||||
parent::__construct($context, $coreRegistry);
|
||||
}
|
||||
|
||||
/**
|
||||
* Edit action
|
||||
*
|
||||
* @return ResultInterface
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
// 1. Get ID and create model
|
||||
$id = $this->getRequest()->getParam('slide_id');
|
||||
$model = $this->_objectManager->create(Slide::class);
|
||||
|
||||
// 2. Initial checking
|
||||
if ($id) {
|
||||
$model->load($id);
|
||||
if (!$model->getId()) {
|
||||
$this->messageManager->addErrorMessage(__('This Slide no longer exists.'));
|
||||
/** @var Redirect $resultRedirect */
|
||||
$resultRedirect = $this->resultRedirectFactory->create();
|
||||
return $resultRedirect->setPath('*/*/');
|
||||
}
|
||||
}
|
||||
$this->_coreRegistry->register('olegnax_carousel_slide', $model);
|
||||
|
||||
// 3. Build edit form
|
||||
/** @var Page $resultPage */
|
||||
$resultPage = $this->resultPageFactory->create();
|
||||
$this->initPage($resultPage)->addBreadcrumb(
|
||||
$id ? __('Edit Slide') : __('New Slide'),
|
||||
$id ? __('Edit Slide') : __('New Slide')
|
||||
);
|
||||
$resultPage->getConfig()->getTitle()->prepend(__('Slides'));
|
||||
$resultPage->getConfig()->getTitle()->prepend($model->getId() ? __('Edit Slide %1', $model->getId()) : __('New Slide'));
|
||||
return $resultPage;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
<?php declare(strict_types=1);
|
||||
/**
|
||||
* Copyright (c) 2021
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
namespace Olegnax\Carousel\Controller\Adminhtml\Slide;
|
||||
|
||||
|
||||
use Magento\Backend\App\Action;
|
||||
use Magento\Backend\App\Action\Context;
|
||||
use Magento\Framework\Controller\ResultInterface;
|
||||
use Magento\Framework\View\Result\PageFactory;
|
||||
|
||||
class Index extends Action
|
||||
{
|
||||
const ADMIN_RESOURCE = 'Olegnax_Carousel::Slide';
|
||||
|
||||
protected $resultPageFactory;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param Context $context
|
||||
* @param PageFactory $resultPageFactory
|
||||
*/
|
||||
public function __construct(
|
||||
Context $context,
|
||||
PageFactory $resultPageFactory
|
||||
) {
|
||||
$this->resultPageFactory = $resultPageFactory;
|
||||
parent::__construct($context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Index action
|
||||
*
|
||||
* @return ResultInterface
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
$resultPage = $this->resultPageFactory->create();
|
||||
$resultPage->getConfig()->getTitle()->prepend(__("Slide"));
|
||||
return $resultPage;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
<?php declare(strict_types=1);
|
||||
/**
|
||||
* Copyright (c) 2021
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
namespace Olegnax\Carousel\Controller\Adminhtml\Slide;
|
||||
|
||||
|
||||
use Exception;
|
||||
use Magento\Backend\App\Action;
|
||||
use Magento\Backend\App\Action\Context;
|
||||
use Magento\Framework\Controller\Result\Json;
|
||||
use Magento\Framework\Controller\Result\JsonFactory;
|
||||
use Magento\Framework\Controller\ResultInterface;
|
||||
use Olegnax\Carousel\Model\Slide;
|
||||
|
||||
class InlineEdit extends Action
|
||||
{
|
||||
const ADMIN_RESOURCE = 'Olegnax_Carousel::Slide_save';
|
||||
|
||||
protected $jsonFactory;
|
||||
|
||||
/**
|
||||
* @param Context $context
|
||||
* @param JsonFactory $jsonFactory
|
||||
*/
|
||||
public function __construct(
|
||||
Context $context,
|
||||
JsonFactory $jsonFactory
|
||||
) {
|
||||
parent::__construct($context);
|
||||
$this->jsonFactory = $jsonFactory;
|
||||
}
|
||||
|
||||
/**
|
||||
* Inline edit action
|
||||
*
|
||||
* @return ResultInterface
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
/** @var Json $resultJson */
|
||||
$resultJson = $this->jsonFactory->create();
|
||||
$error = false;
|
||||
$messages = [];
|
||||
|
||||
if ($this->getRequest()->getParam('isAjax')) {
|
||||
$postItems = $this->getRequest()->getParam('items', []);
|
||||
if (!count($postItems)) {
|
||||
$messages[] = __('Please correct the data sent.');
|
||||
$error = true;
|
||||
} else {
|
||||
foreach (array_keys($postItems) as $modelid) {
|
||||
/** @var Slide $model */
|
||||
$model = $this->_objectManager->create(Slide::class)->load($modelid);
|
||||
try {
|
||||
$model->setData(array_merge($model->getData(), $postItems[$modelid]));
|
||||
$model->save();
|
||||
} catch (Exception $e) {
|
||||
$messages[] = "[Slide ID: {$modelid}] {$e->getMessage()}";
|
||||
$error = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $resultJson->setData([
|
||||
'messages' => $messages,
|
||||
'error' => $error
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
<?php declare(strict_types=1);
|
||||
/**
|
||||
* Copyright (c) 2021
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
namespace Olegnax\Carousel\Controller\Adminhtml\Slide;
|
||||
|
||||
|
||||
use Magento\Backend\App\Action\Context;
|
||||
use Magento\Backend\Model\View\Result\ForwardFactory;
|
||||
use Magento\Framework\Controller\Result\Forward;
|
||||
use Magento\Framework\Controller\ResultInterface;
|
||||
use Magento\Framework\Registry;
|
||||
use Olegnax\Carousel\Controller\Adminhtml\Slide;
|
||||
|
||||
class NewAction extends Slide
|
||||
{
|
||||
const ADMIN_RESOURCE = 'Olegnax_Carousel::Slide_save';
|
||||
|
||||
protected $resultForwardFactory;
|
||||
|
||||
/**
|
||||
* @param Context $context
|
||||
* @param Registry $coreRegistry
|
||||
* @param ForwardFactory $resultForwardFactory
|
||||
*/
|
||||
public function __construct(
|
||||
Context $context,
|
||||
Registry $coreRegistry,
|
||||
ForwardFactory $resultForwardFactory
|
||||
) {
|
||||
$this->resultForwardFactory = $resultForwardFactory;
|
||||
parent::__construct($context, $coreRegistry);
|
||||
}
|
||||
|
||||
/**
|
||||
* New action
|
||||
*
|
||||
* @return ResultInterface
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
/** @var Forward $resultForward */
|
||||
$resultForward = $this->resultForwardFactory->create();
|
||||
return $resultForward->forward('edit');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,96 @@
|
||||
<?php declare(strict_types=1);
|
||||
/**
|
||||
* Copyright (c) 2021
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
namespace Olegnax\Carousel\Controller\Adminhtml\Slide;
|
||||
|
||||
use Exception;
|
||||
use Magento\Backend\App\Action;
|
||||
use Magento\Backend\App\Action\Context;
|
||||
use Magento\Backend\Model\View\Result\Redirect;
|
||||
use Magento\Framework\App\Request\DataPersistorInterface;
|
||||
use Magento\Framework\Controller\ResultInterface;
|
||||
use Magento\Framework\Exception\LocalizedException;
|
||||
use Olegnax\Carousel\Model\Slide;
|
||||
|
||||
|
||||
class Save extends Action
|
||||
{
|
||||
const ADMIN_RESOURCE = 'Olegnax_Carousel::Slide_save';
|
||||
|
||||
protected $dataPersistor;
|
||||
|
||||
/**
|
||||
* @param Context $context
|
||||
* @param DataPersistorInterface $dataPersistor
|
||||
*/
|
||||
public function __construct(
|
||||
Context $context,
|
||||
DataPersistorInterface $dataPersistor
|
||||
) {
|
||||
$this->dataPersistor = $dataPersistor;
|
||||
parent::__construct($context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Save action
|
||||
*
|
||||
* @return ResultInterface
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
/** @var Redirect $resultRedirect */
|
||||
$resultRedirect = $this->resultRedirectFactory->create();
|
||||
$data = $this->getRequest()->getPostValue();
|
||||
if ($data) {
|
||||
$id = $this->getRequest()->getParam('slide_id');
|
||||
|
||||
$model = $this->_objectManager->create(Slide::class)->load($id);
|
||||
if (!$model->getId() && $id) {
|
||||
$this->messageManager->addErrorMessage(__('This Slide no longer exists.'));
|
||||
return $resultRedirect->setPath('*/*/');
|
||||
}
|
||||
|
||||
$model->setData($data);
|
||||
|
||||
try {
|
||||
$model->save();
|
||||
$this->messageManager->addSuccessMessage(__('You saved the Slide.'));
|
||||
$this->dataPersistor->clear('olegnax_carousel_slide');
|
||||
|
||||
if ($this->getRequest()->getParam('back')) {
|
||||
return $resultRedirect->setPath('*/*/edit', ['slide_id' => $model->getId()]);
|
||||
}
|
||||
return $resultRedirect->setPath('*/*/');
|
||||
} catch (LocalizedException $e) {
|
||||
$this->messageManager->addErrorMessage($e->getMessage());
|
||||
} catch (Exception $e) {
|
||||
$this->messageManager->addExceptionMessage($e, __('Something went wrong while saving the Slide.'));
|
||||
}
|
||||
|
||||
$this->dataPersistor->set('olegnax_carousel_slide', $data);
|
||||
return $resultRedirect->setPath('*/*/edit', ['slide_id' => $this->getRequest()->getParam('slide_id')]);
|
||||
}
|
||||
return $resultRedirect->setPath('*/*/');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user