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

62 lines
1.9 KiB
PHP

<?php
declare(strict_types=1);
namespace Esun\CustomerVat\Block\Account;
use Esun\CustomerVat\Model\EuCountries;
use Esun\CustomerVat\Model\ResourceModel\VatApplication\Collection;
use Esun\CustomerVat\Model\ResourceModel\VatApplication\CollectionFactory;
use Esun\CustomerVat\Model\VatApplication;
use Magento\Customer\Model\Session;
use Magento\Framework\Registry;
use Magento\Framework\View\Element\Template;
class Vat extends Template
{
private ?Collection $applications = null;
public function __construct(
Template\Context $context,
private readonly Session $customerSession,
private readonly CollectionFactory $collectionFactory,
private readonly EuCountries $euCountries,
private readonly Registry $registry,
array $data = []
) {
parent::__construct($context, $data);
}
public function getApplications(): Collection
{
return $this->applications ??= $this->collectionFactory->create()
->addFieldToFilter('customer_id', (int)$this->customerSession->getCustomerId())
->setOrder('created_at', 'DESC');
}
public function getCurrentApplication(): ?VatApplication
{
$application = $this->registry->registry('current_customer_vat');
return $application instanceof VatApplication ? $application : null;
}
public function getCountryOptions(): array
{
return $this->euCountries->getOptions();
}
public function getCountryName(string $countryId): string
{
foreach ($this->getCountryOptions() as $option) {
if ($option['value'] === $countryId) {
return (string)$option['label'];
}
}
return $countryId;
}
public function getStatusLabel(string $status): string
{
return (string)(VatApplication::getStatuses()[$status] ?? $status);
}
}