This commit is contained in:
2026-09-15 10:35:56 +08:00
commit 782f8ea7aa
4086 changed files with 631288 additions and 0 deletions
@@ -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;
}
}
@@ -0,0 +1,37 @@
<?php
declare(strict_types=1);
namespace Esun\CustomerMessage\Controller\Account;
use Esun\CustomerMessage\Model\MessageProvider;
use Magento\Customer\Controller\AbstractAccount;
use Magento\Customer\Model\Session;
use Magento\Framework\App\Action\HttpPostActionInterface;
use Magento\Framework\App\Action\Context;
use Magento\Framework\App\RequestInterface;
use Magento\Framework\Controller\Result\RedirectFactory;
use Magento\Framework\Data\Form\FormKey\Validator;
class Read extends AbstractAccount implements HttpPostActionInterface
{
public function __construct(
Context $context,
private readonly RequestInterface $request,
private readonly RedirectFactory $redirects,
private readonly Validator $formKey,
private readonly Session $session,
private readonly MessageProvider $provider
) {
parent::__construct($context);
}
public function execute()
{
if ($this->formKey->validate($this->request)) {
$this->provider->markRead(
(int)$this->request->getParam('recipient_id'),
(int)$this->session->getCustomerId()
);
}
return $this->redirects->create()->setPath('customer-message/account/index');
}
}