39 lines
1.4 KiB
PHP
39 lines
1.4 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
namespace Esun\CustomerMessage\Controller\Adminhtml\Message;
|
|
|
|
use Esun\CustomerMessage\Model\ConversationService;
|
|
use Magento\Backend\App\Action;
|
|
use Magento\Backend\App\Action\Context;
|
|
use Magento\Framework\App\Action\HttpGetActionInterface;
|
|
use Magento\Framework\Controller\ResultFactory;
|
|
|
|
class Index extends Action implements HttpGetActionInterface
|
|
{
|
|
public const ADMIN_RESOURCE='Esun_CustomerMessage::messages';
|
|
public function __construct(Context $context, private readonly ConversationService $conversations)
|
|
{
|
|
parent::__construct($context);
|
|
}
|
|
public function execute()
|
|
{
|
|
$threadId = (int)$this->getRequest()->getParam('thread_id');
|
|
if (!$threadId) {
|
|
$orderId = (int)$this->getRequest()->getParam('order_id');
|
|
$thread = $orderId
|
|
? $this->conversations->getOrderThreadForAdmin($orderId)
|
|
: null;
|
|
$threadId = $thread ? (int)$thread['thread_id'] : 0;
|
|
}
|
|
|
|
if ($threadId && $this->conversations->getThreadForAdmin($threadId)) {
|
|
$this->conversations->markAdminRead($threadId);
|
|
}
|
|
|
|
$page = $this->resultFactory->create(ResultFactory::TYPE_PAGE);
|
|
$page->setActiveMenu(self::ADMIN_RESOURCE);
|
|
$page->getConfig()->getTitle()->prepend(__('Customer Messages'));
|
|
return $page;
|
|
}
|
|
}
|