init
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user