init
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Esun\CustomerMessage\Block\Adminhtml\Message;
|
||||
|
||||
use Esun\CustomerMessage\Model\ConversationService;
|
||||
use Magento\Backend\Block\Template;
|
||||
use Magento\Sales\Api\OrderRepositoryInterface;
|
||||
|
||||
class Index extends Template
|
||||
{
|
||||
public function __construct(Template\Context $context, private readonly ConversationService $conversations, private readonly OrderRepositoryInterface $orders, array $data = [])
|
||||
{
|
||||
parent::__construct($context, $data);
|
||||
}
|
||||
|
||||
public function getThreads(): array
|
||||
{
|
||||
return $this->conversations->getThreadsForAdmin();
|
||||
}
|
||||
|
||||
public function getSelectedThread(): ?array
|
||||
{
|
||||
$threadId = (int)$this->getRequest()->getParam('thread_id');
|
||||
if ($threadId) {
|
||||
return $this->conversations->getThreadForAdmin($threadId);
|
||||
}
|
||||
$orderId = (int)$this->getRequest()->getParam('order_id');
|
||||
return $orderId ? $this->conversations->getOrderThreadForAdmin($orderId) : null;
|
||||
}
|
||||
|
||||
public function getMessages(?array $thread): array
|
||||
{
|
||||
return $thread ? $this->conversations->getMessages((int)$thread['thread_id']) : [];
|
||||
}
|
||||
|
||||
public function getOrder(): ?\Magento\Sales\Api\Data\OrderInterface
|
||||
{
|
||||
$orderId = (int)$this->getRequest()->getParam('order_id');
|
||||
if (!$orderId) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
return $this->orders->get($orderId);
|
||||
} catch (\Throwable) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user