42 lines
1.4 KiB
PHP
42 lines
1.4 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
namespace Esun\CustomerVat\Model;
|
|
|
|
use Magento\Customer\Model\Session;
|
|
use Magento\Framework\Url\EncoderInterface;
|
|
use Magento\Framework\UrlInterface;
|
|
use Magento\Store\Model\StoreManagerInterface;
|
|
|
|
class VatPromptProvider
|
|
{
|
|
public function __construct(
|
|
private readonly Session $customerSession,
|
|
private readonly StoreManagerInterface $storeManager,
|
|
private readonly VatApplicationService $applications,
|
|
private readonly UrlInterface $urlBuilder,
|
|
private readonly EncoderInterface $urlEncoder
|
|
) {
|
|
}
|
|
|
|
public function getData(): array
|
|
{
|
|
if ((string)$this->storeManager->getWebsite()->getCode() !== 'eu_site') {
|
|
return ['show' => false];
|
|
}
|
|
$loggedIn = $this->customerSession->isLoggedIn();
|
|
$status = $this->applications->getCustomerStatus((int)$this->customerSession->getCustomerId());
|
|
$show = !$loggedIn || in_array($status, ['none', VatApplication::STATUS_REJECTED], true);
|
|
$vatUrl = $this->urlBuilder->getUrl('esun_customer_vat/vat/new');
|
|
$applyUrl = $loggedIn ? $vatUrl : $this->urlBuilder->getUrl('customer/account/login', [
|
|
'referer' => $this->urlEncoder->encode($vatUrl),
|
|
]);
|
|
return [
|
|
'show' => $show,
|
|
'is_logged_in' => $loggedIn,
|
|
'status' => $status,
|
|
'apply_url' => $applyUrl,
|
|
];
|
|
}
|
|
}
|