init
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
namespace Esun\CustomerMessage\Controller\Account;
|
||||
|
||||
use Esun\CustomerMessage\Model\ConversationService;
|
||||
use Magento\Customer\Controller\AbstractAccount;
|
||||
use Magento\Customer\Model\Session;
|
||||
use Magento\Framework\App\Action\Context;
|
||||
use Magento\Framework\App\Action\HttpGetActionInterface;
|
||||
use Magento\Framework\Controller\ResultFactory;
|
||||
|
||||
class Index extends AbstractAccount implements HttpGetActionInterface
|
||||
{
|
||||
public function __construct(Context $context, private readonly Session $session, private readonly ConversationService $conversations)
|
||||
{
|
||||
parent::__construct($context);
|
||||
}
|
||||
|
||||
public function execute()
|
||||
{
|
||||
$customerId = (int)$this->session->getCustomerId();
|
||||
$threadId = (int)$this->getRequest()->getParam('thread_id');
|
||||
$orderId = (int)$this->getRequest()->getParam('order_id');
|
||||
if (!$threadId && $orderId) {
|
||||
$thread = $this->conversations->getOrderThreadForCustomer($orderId, $customerId);
|
||||
$threadId = $thread ? (int)$thread['thread_id'] : 0;
|
||||
}
|
||||
if (!$threadId && !$orderId && (int)$this->getRequest()->getParam('new') !== 1) {
|
||||
$threads = $this->conversations->getThreadsForCustomer($customerId, 1);
|
||||
$threadId = $threads ? (int)$threads[0]['thread_id'] : 0;
|
||||
}
|
||||
|
||||
if ($threadId && $this->conversations->getThreadForCustomer($threadId, $customerId)) {
|
||||
$this->conversations->markCustomerRead($threadId, $customerId);
|
||||
}
|
||||
|
||||
$page = $this->resultFactory->create(ResultFactory::TYPE_PAGE);
|
||||
$page->getConfig()->getTitle()->set(__('Messages'));
|
||||
return $page;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user