init
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Esun\Catalog\Controller\Adminhtml\Faq;
|
||||
|
||||
use Esun\Catalog\Model\FaqFactory;
|
||||
use Magento\Backend\App\Action;
|
||||
use Magento\Framework\Exception\LocalizedException;
|
||||
|
||||
class Delete extends Action
|
||||
{
|
||||
public const ADMIN_RESOURCE = 'Esun_Catalog::faqs_delete';
|
||||
|
||||
public function __construct(
|
||||
Action\Context $context,
|
||||
private readonly FaqFactory $faqFactory
|
||||
) {
|
||||
parent::__construct($context);
|
||||
}
|
||||
|
||||
public function execute()
|
||||
{
|
||||
$redirect = $this->resultRedirectFactory->create();
|
||||
|
||||
try {
|
||||
$faq = $this->faqFactory->create()->load((int)$this->getRequest()->getParam('id'));
|
||||
if (!$faq->getId()) {
|
||||
throw new LocalizedException(__('The FAQ no longer exists.'));
|
||||
}
|
||||
|
||||
$faq->delete();
|
||||
$this->messageManager->addSuccessMessage(__('The FAQ has been deleted.'));
|
||||
} catch (\Throwable $e) {
|
||||
$this->messageManager->addErrorMessage($e->getMessage());
|
||||
}
|
||||
|
||||
return $redirect->setPath('esun_catalog/faq/index');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Esun\Catalog\Controller\Adminhtml\Faq;
|
||||
|
||||
use Magento\Backend\App\Action;
|
||||
use Magento\Framework\View\Result\PageFactory;
|
||||
|
||||
class Edit extends Action
|
||||
{
|
||||
public const ADMIN_RESOURCE = 'Esun_Catalog::faqs';
|
||||
|
||||
public function __construct(
|
||||
Action\Context $context,
|
||||
private readonly PageFactory $resultPageFactory
|
||||
) {
|
||||
parent::__construct($context);
|
||||
}
|
||||
|
||||
public function execute()
|
||||
{
|
||||
$page = $this->resultPageFactory->create();
|
||||
$page->setActiveMenu('Esun_Catalog::faqs');
|
||||
$page->getConfig()->getTitle()->prepend(__('Edit Product FAQ'));
|
||||
|
||||
return $page;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Esun\Catalog\Controller\Adminhtml\Faq;
|
||||
|
||||
use Magento\Backend\App\Action;
|
||||
use Magento\Framework\View\Result\PageFactory;
|
||||
|
||||
class Index extends Action
|
||||
{
|
||||
public const ADMIN_RESOURCE = 'Esun_Catalog::faqs';
|
||||
|
||||
public function __construct(
|
||||
Action\Context $context,
|
||||
private readonly PageFactory $resultPageFactory
|
||||
) {
|
||||
parent::__construct($context);
|
||||
}
|
||||
|
||||
public function execute()
|
||||
{
|
||||
$page = $this->resultPageFactory->create();
|
||||
$page->setActiveMenu('Esun_Catalog::faqs');
|
||||
$page->getConfig()->getTitle()->prepend(__('Product FAQ'));
|
||||
|
||||
return $page;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Esun\Catalog\Controller\Adminhtml\Faq;
|
||||
|
||||
class NewAction extends Edit
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Esun\Catalog\Controller\Adminhtml\Faq;
|
||||
|
||||
use Esun\Catalog\Model\FaqFactory;
|
||||
use Magento\Backend\App\Action;
|
||||
use Magento\Framework\Exception\LocalizedException;
|
||||
|
||||
class Save extends Action
|
||||
{
|
||||
public const ADMIN_RESOURCE = 'Esun_Catalog::faqs_save';
|
||||
|
||||
public function __construct(
|
||||
Action\Context $context,
|
||||
private readonly FaqFactory $faqFactory
|
||||
) {
|
||||
parent::__construct($context);
|
||||
}
|
||||
|
||||
public function execute()
|
||||
{
|
||||
$id = (int)$this->getRequest()->getParam('faq_id');
|
||||
$redirect = $this->resultRedirectFactory->create();
|
||||
|
||||
try {
|
||||
$faq = $this->faqFactory->create();
|
||||
if ($id) {
|
||||
$faq->load($id);
|
||||
if (!$faq->getId()) {
|
||||
throw new LocalizedException(__('The FAQ no longer exists.'));
|
||||
}
|
||||
}
|
||||
|
||||
$title = trim((string)$this->getRequest()->getParam('title'));
|
||||
if ($title === '') {
|
||||
throw new LocalizedException(__('Title is required.'));
|
||||
}
|
||||
|
||||
$storeIds = (array)$this->getRequest()->getParam('store_ids', [0]);
|
||||
$storeIds = array_map('intval', $storeIds);
|
||||
if (!$storeIds) {
|
||||
$storeIds = [0];
|
||||
}
|
||||
|
||||
$faq->addData([
|
||||
'title' => $title,
|
||||
'content' => (string)$this->getRequest()->getParam('content'),
|
||||
'store_ids' => implode(',', array_unique($storeIds)),
|
||||
'status' => $this->getRequest()->getParam('status') === '0' ? 0 : 1,
|
||||
'sort_order' => (int)$this->getRequest()->getParam('sort_order'),
|
||||
])->save();
|
||||
|
||||
$this->messageManager->addSuccessMessage(__('The FAQ has been saved.'));
|
||||
return $redirect->setPath('esun_catalog/faq/index');
|
||||
} catch (\Throwable $e) {
|
||||
$this->messageManager->addErrorMessage($e->getMessage());
|
||||
return $redirect->setPath($id ? 'esun_catalog/faq/edit' : 'esun_catalog/faq/new', $id ? ['id' => $id] : []);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user