Files
2026-09-15 10:35:56 +08:00

33 lines
1012 B
PHP

<?php
declare(strict_types=1);
namespace Esun\CustomerMessage\Block\Account;
use Esun\CustomerMessage\Model\ConversationService;
use Magento\Customer\Block\Account\SortLink;
use Magento\Customer\Model\Session;
use Magento\Framework\App\DefaultPathInterface;
use Magento\Framework\View\Element\Template\Context;
class NavigationLink extends SortLink
{
private ?int $unreadCount = null;
public function __construct(Context $context, DefaultPathInterface $defaultPath, private readonly Session $session, private readonly ConversationService $conversations, array $data = [])
{
parent::__construct($context, $defaultPath, $data);
}
public function getUnreadCount(): int
{
if ($this->unreadCount === null) {
$customerId = (int)$this->session->getCustomerId();
$this->unreadCount = $customerId > 0
? $this->conversations->getCustomerUnreadTotal($customerId)
: 0;
}
return $this->unreadCount;
}
}