This commit is contained in:
2026-09-15 10:35:56 +08:00
commit 782f8ea7aa
4086 changed files with 631288 additions and 0 deletions
@@ -0,0 +1,61 @@
<?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);
}
}
@@ -0,0 +1,40 @@
<?php
declare(strict_types=1);
namespace Esun\CustomerVat\Block\Adminhtml\Application;
use Esun\CustomerVat\Model\EuCountries;
use Esun\CustomerVat\Model\VatApplication;
use Magento\Backend\Block\Template;
use Magento\Customer\Api\CustomerRepositoryInterface;
use Magento\Framework\Registry;
class View extends Template
{
public function __construct(Template\Context $context, private readonly Registry $registry,
private readonly CustomerRepositoryInterface $customers, private readonly EuCountries $countries,
array $data = [])
{
parent::__construct($context, $data);
}
public function getApplication(): VatApplication
{
return $this->registry->registry('current_customer_vat_admin');
}
public function getCustomer()
{
return $this->customers->getById((int)$this->getApplication()->getData('customer_id'));
}
public function getCountryName(string $id): string
{
foreach ($this->countries->getOptions() as $option) {
if ($option['value'] === $id) {
return (string)$option['label'];
}
}
return $id;
}
}
@@ -0,0 +1,20 @@
<?php
declare(strict_types=1);
namespace Esun\CustomerVat\Block\Cart;
use Esun\CustomerVat\Model\VatPromptProvider;
use Magento\Framework\View\Element\Template;
class VatPrompt extends Template
{
public function __construct(Template\Context $context, private readonly VatPromptProvider $provider, array $data = [])
{
parent::__construct($context, $data);
}
public function getPromptData(): array
{
return $this->provider->getData();
}
}
@@ -0,0 +1,26 @@
<?php
declare(strict_types=1);
namespace Esun\CustomerVat\Controller\Adminhtml\Application;
use Magento\Backend\App\Action;
use Magento\Backend\App\Action\Context;
use Magento\Framework\View\Result\PageFactory;
class Index extends Action
{
public const ADMIN_RESOURCE = 'Esun_CustomerVat::applications';
public function __construct(Context $context, private readonly PageFactory $pageFactory)
{
parent::__construct($context);
}
public function execute()
{
$page = $this->pageFactory->create();
$page->setActiveMenu('Esun_CustomerVat::applications');
$page->getConfig()->getTitle()->prepend(__('VAT Number Applications'));
return $page;
}
}
@@ -0,0 +1,52 @@
<?php
declare(strict_types=1);
namespace Esun\CustomerVat\Controller\Adminhtml\Application;
use Esun\CustomerVat\Model\ResourceModel\VatApplication as VatResource;
use Esun\CustomerVat\Model\VatApplication;
use Esun\CustomerVat\Model\VatApplicationFactory;
use Magento\Backend\App\Action;
use Magento\Backend\App\Action\Context;
use Magento\Backend\Model\Auth\Session as AuthSession;
use Magento\Framework\App\Action\HttpPostActionInterface;
use Magento\Framework\Stdlib\DateTime\DateTime;
class Review extends Action implements HttpPostActionInterface
{
public const ADMIN_RESOURCE = 'Esun_CustomerVat::review';
public function __construct(Context $context, private readonly VatApplicationFactory $factory,
private readonly VatResource $resource, private readonly AuthSession $authSession,
private readonly DateTime $dateTime)
{
parent::__construct($context);
}
public function execute()
{
$id = (int)$this->getRequest()->getParam('id');
$status = (string)$this->getRequest()->getParam('status');
$allowed = [VatApplication::STATUS_PENDING, VatApplication::STATUS_APPROVED, VatApplication::STATUS_REJECTED];
$application = $this->factory->create();
$this->resource->load($application, $id);
if (!$application->getId() || !in_array($status, $allowed, true)) {
$this->messageManager->addErrorMessage(__('Unable to review this VAT application.'));
return $this->resultRedirectFactory->create()->setPath('*/*/index');
}
try {
$admin = $this->authSession->getUser();
$application->addData([
'status' => $status,
'review_note' => trim((string)$this->getRequest()->getParam('review_note')) ?: null,
'reviewed_by' => $admin ? (int)$admin->getId() : null,
'reviewed_at' => $this->dateTime->gmtDate(),
]);
$this->resource->save($application);
$this->messageManager->addSuccessMessage(__('The VAT application review has been saved.'));
} catch (\Throwable $exception) {
$this->messageManager->addExceptionMessage($exception, __('Unable to save the VAT application review.'));
}
return $this->resultRedirectFactory->create()->setPath('*/*/view', ['id' => $id]);
}
}
@@ -0,0 +1,38 @@
<?php
declare(strict_types=1);
namespace Esun\CustomerVat\Controller\Adminhtml\Application;
use Esun\CustomerVat\Model\ResourceModel\VatApplication as VatResource;
use Esun\CustomerVat\Model\VatApplicationFactory;
use Magento\Backend\App\Action;
use Magento\Backend\App\Action\Context;
use Magento\Framework\Registry;
use Magento\Framework\View\Result\PageFactory;
class View extends Action
{
public const ADMIN_RESOURCE = 'Esun_CustomerVat::applications';
public function __construct(Context $context, private readonly PageFactory $pageFactory,
private readonly VatApplicationFactory $factory, private readonly VatResource $resource,
private readonly Registry $registry)
{
parent::__construct($context);
}
public function execute()
{
$application = $this->factory->create();
$this->resource->load($application, (int)$this->getRequest()->getParam('id'));
if (!$application->getId()) {
$this->messageManager->addErrorMessage(__('The VAT application no longer exists.'));
return $this->resultRedirectFactory->create()->setPath('*/*/index');
}
$this->registry->register('current_customer_vat_admin', $application);
$page = $this->pageFactory->create();
$page->setActiveMenu('Esun_CustomerVat::applications');
$page->getConfig()->getTitle()->prepend(__('VAT Application #%1', $application->getId()));
return $page;
}
}
@@ -0,0 +1,17 @@
<?php
declare(strict_types=1);
namespace Esun\CustomerVat\Controller\Vat;
use Magento\Customer\Controller\AccountInterface;
use Magento\Customer\Model\Session;
use Magento\Framework\App\Action\Action;
use Magento\Framework\App\Action\Context;
abstract class AbstractVat extends Action implements AccountInterface
{
public function __construct(Context $context, protected readonly Session $customerSession)
{
parent::__construct($context);
}
}
@@ -0,0 +1,40 @@
<?php
declare(strict_types=1);
namespace Esun\CustomerVat\Controller\Vat;
use Esun\CustomerVat\Model\VatApplicationService;
use Magento\Customer\Model\Session;
use Magento\Framework\App\Action\Context;
use Magento\Framework\App\Action\HttpPostActionInterface;
use Magento\Framework\Data\Form\FormKey\Validator;
class Delete extends AbstractVat implements HttpPostActionInterface
{
public function __construct(
Context $context,
Session $customerSession,
private readonly Validator $formKeyValidator,
private readonly VatApplicationService $applications
) {
parent::__construct($context, $customerSession);
}
public function execute()
{
if (!$this->formKeyValidator->validate($this->getRequest())) {
$this->messageManager->addErrorMessage(__('Your session has expired. Please try again.'));
return $this->resultRedirectFactory->create()->setPath('*/*/index');
}
try {
$this->applications->deleteForCustomer(
(int)$this->getRequest()->getParam('id'),
(int)$this->customerSession->getCustomerId()
);
$this->messageManager->addSuccessMessage(__('The VAT number has been deleted.'));
} catch (\Throwable $exception) {
$this->messageManager->addErrorMessage($exception->getMessage());
}
return $this->resultRedirectFactory->create()->setPath('*/*/index');
}
}
@@ -0,0 +1,41 @@
<?php
declare(strict_types=1);
namespace Esun\CustomerVat\Controller\Vat;
use Esun\CustomerVat\Model\VatApplicationService;
use Magento\Customer\Model\Session;
use Magento\Framework\App\Action\Context;
use Magento\Framework\App\Action\HttpGetActionInterface;
use Magento\Framework\Registry;
use Magento\Framework\View\Result\PageFactory;
class Edit extends AbstractVat implements HttpGetActionInterface
{
public function __construct(
Context $context,
Session $customerSession,
private readonly PageFactory $pageFactory,
private readonly VatApplicationService $applications,
private readonly Registry $registry
) {
parent::__construct($context, $customerSession);
}
public function execute()
{
try {
$application = $this->applications->getByIdForCustomer(
(int)$this->getRequest()->getParam('id'),
(int)$this->customerSession->getCustomerId()
);
$this->registry->register('current_customer_vat', $application);
$page = $this->pageFactory->create();
$page->getConfig()->getTitle()->set(__('Edit VAT Number'));
return $page;
} catch (\Throwable $exception) {
$this->messageManager->addErrorMessage($exception->getMessage());
return $this->resultRedirectFactory->create()->setPath('*/*/index');
}
}
}
@@ -0,0 +1,24 @@
<?php
declare(strict_types=1);
namespace Esun\CustomerVat\Controller\Vat;
use Magento\Framework\App\Action\Context;
use Magento\Framework\App\Action\HttpGetActionInterface;
use Magento\Framework\View\Result\PageFactory;
use Magento\Customer\Model\Session;
class Index extends AbstractVat implements HttpGetActionInterface
{
public function __construct(Context $context, Session $customerSession, private readonly PageFactory $pageFactory)
{
parent::__construct($context, $customerSession);
}
public function execute()
{
$page = $this->pageFactory->create();
$page->getConfig()->getTitle()->set(__('VAT Number Management'));
return $page;
}
}
@@ -0,0 +1,24 @@
<?php
declare(strict_types=1);
namespace Esun\CustomerVat\Controller\Vat;
use Magento\Framework\App\Action\Context;
use Magento\Framework\App\Action\HttpGetActionInterface;
use Magento\Framework\View\Result\PageFactory;
use Magento\Customer\Model\Session;
class NewAction extends AbstractVat implements HttpGetActionInterface
{
public function __construct(Context $context, Session $customerSession, private readonly PageFactory $pageFactory)
{
parent::__construct($context, $customerSession);
}
public function execute()
{
$page = $this->pageFactory->create();
$page->getConfig()->getTitle()->set(__('Add VAT Number'));
return $page;
}
}
@@ -0,0 +1,43 @@
<?php
declare(strict_types=1);
namespace Esun\CustomerVat\Controller\Vat;
use Esun\CustomerVat\Model\VatApplicationService;
use Magento\Customer\Model\Session;
use Magento\Framework\App\Action\Context;
use Magento\Framework\App\Action\HttpPostActionInterface;
use Magento\Framework\Data\Form\FormKey\Validator;
class Save extends AbstractVat implements HttpPostActionInterface
{
public function __construct(
Context $context,
Session $customerSession,
private readonly Validator $formKeyValidator,
private readonly VatApplicationService $applications
) {
parent::__construct($context, $customerSession);
}
public function execute()
{
if (!$this->formKeyValidator->validate($this->getRequest())) {
$this->messageManager->addErrorMessage(__('Your session has expired. Please try again.'));
return $this->resultRedirectFactory->create()->setPath('*/*/index');
}
$id = (int)$this->getRequest()->getParam('id');
try {
$this->applications->saveForCustomer(
(int)$this->customerSession->getCustomerId(),
(array)$this->getRequest()->getParams(),
$id
);
$this->messageManager->addSuccessMessage(__('Your VAT number has been submitted for review.'));
return $this->resultRedirectFactory->create()->setPath('*/*/index');
} catch (\Throwable $exception) {
$this->messageManager->addErrorMessage($exception->getMessage());
return $this->resultRedirectFactory->create()->setPath('*/*/' . ($id ? 'edit' : 'new'), $id ? ['id' => $id] : []);
}
}
}
@@ -0,0 +1,61 @@
<?php
declare(strict_types=1);
namespace Esun\CustomerVat\Model;
use Magento\Directory\Model\ResourceModel\Country\CollectionFactory;
class EuCountries
{
public const CODES = [
'AT', 'BE', 'BG', 'HR', 'CY', 'CZ', 'DK', 'EE', 'FI', 'FR', 'DE', 'GR', 'HU', 'IE',
'IT', 'LV', 'LT', 'LU', 'MT', 'NL', 'PL', 'PT', 'RO', 'SK', 'SI', 'ES', 'SE',
];
public const RATES = [
'NL' => 21.0,
'AT' => 20.0,
'ES' => 21.0,
'CZ' => 21.0,
'PL' => 23.0,
'FR' => 20.0,
'IT' => 22.0,
'DE' => 19.0,
];
public function __construct(private readonly CollectionFactory $countryCollectionFactory)
{
}
public function isEu(string $countryId): bool
{
return in_array(strtoupper($countryId), self::CODES, true);
}
public function getRate(string $countryId): float
{
return self::RATES[strtoupper($countryId)] ?? 19.0;
}
public function getAppliedRate(string $countryId): float
{
return self::toAppliedRate($this->getRate($countryId));
}
public static function toAppliedRate(float $nominalRate): float
{
return $nominalRate > 0 ? ($nominalRate / (100 + $nominalRate)) * 100 : 0.0;
}
public function getOptions(): array
{
$options = [];
$collection = $this->countryCollectionFactory->create()
->addCountryIdFilter(self::CODES);
foreach ($collection as $country) {
$options[] = ['value' => $country->getCountryId(), 'label' => $country->getName()];
}
usort($options, static fn (array $a, array $b): int => strcasecmp((string)$a['label'], (string)$b['label']));
return $options;
}
}
@@ -0,0 +1,14 @@
<?php
declare(strict_types=1);
namespace Esun\CustomerVat\Model\ResourceModel;
use Magento\Framework\Model\ResourceModel\Db\AbstractDb;
class VatApplication extends AbstractDb
{
protected function _construct(): void
{
$this->_init('esun_customer_vat', 'entity_id');
}
}
@@ -0,0 +1,16 @@
<?php
declare(strict_types=1);
namespace Esun\CustomerVat\Model\ResourceModel\VatApplication;
use Esun\CustomerVat\Model\VatApplication as VatApplicationModel;
use Esun\CustomerVat\Model\ResourceModel\VatApplication as VatApplicationResource;
use Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection;
class Collection extends AbstractCollection
{
protected function _construct(): void
{
$this->_init(VatApplicationModel::class, VatApplicationResource::class);
}
}
@@ -0,0 +1,19 @@
<?php
declare(strict_types=1);
namespace Esun\CustomerVat\Model\Source;
use Esun\CustomerVat\Model\VatApplication;
use Magento\Framework\Data\OptionSourceInterface;
class Status implements OptionSourceInterface
{
public function toOptionArray(): array
{
$options = [];
foreach (VatApplication::getStatuses() as $value => $label) {
$options[] = ['value' => $value, 'label' => $label];
}
return $options;
}
}
@@ -0,0 +1,16 @@
<?php
declare(strict_types=1);
namespace Esun\CustomerVat\Model;
class TaxContext
{
public function __construct(
public readonly string $mode,
public readonly float $nominalRate,
public readonly float $appliedRate,
public readonly bool $exempt,
public readonly ?VatApplication $vatApplication = null
) {
}
}
@@ -0,0 +1,55 @@
<?php
declare(strict_types=1);
namespace Esun\CustomerVat\Model;
use Magento\Store\Model\StoreManagerInterface;
class TaxContextResolver
{
public const MODE_NO_TAX = 'no_tax';
public const MODE_EU_STANDARD = 'eu_standard_vat';
public const MODE_EU_VAT_REGISTERED = 'eu_vat_registered';
public const MODE_UK_STANDARD = 'uk_standard';
public function __construct(
private readonly StoreManagerInterface $storeManager,
private readonly VatApplicationService $applications,
private readonly EuCountries $euCountries
) {
}
public function resolve(int $storeId, int $customerId, string $shippingCountryId): TaxContext
{
$websiteCode = (string)$this->storeManager->getStore($storeId)->getWebsite()->getCode();
if (in_array($websiteCode, ['uk', 'gb_site'], true)) {
return new TaxContext(
self::MODE_UK_STANDARD,
20.0,
EuCountries::toAppliedRate(20.0),
false
);
}
if (!in_array($websiteCode, ['eu', 'eu_site'], true)) {
return new TaxContext(self::MODE_NO_TAX, 0.0, 0.0, false);
}
$countryId = strtoupper($shippingCountryId);
if (!$this->euCountries->isEu($countryId)) {
return new TaxContext(self::MODE_NO_TAX, 0.0, 0.0, false);
}
$nominalRate = $this->euCountries->getRate($countryId);
$appliedRate = $this->euCountries->getAppliedRate($countryId);
$approvedVat = $this->applications->findApproved($customerId, $countryId);
if ($approvedVat !== null) {
return new TaxContext(
self::MODE_EU_VAT_REGISTERED,
$nominalRate,
$appliedRate,
false,
$approvedVat
);
}
return new TaxContext(self::MODE_EU_STANDARD, $nominalRate, $appliedRate, false);
}
}
@@ -0,0 +1,27 @@
<?php
declare(strict_types=1);
namespace Esun\CustomerVat\Model;
use Magento\Framework\Model\AbstractModel;
class VatApplication extends AbstractModel
{
public const STATUS_PENDING = 'pending';
public const STATUS_APPROVED = 'approved';
public const STATUS_REJECTED = 'rejected';
protected function _construct(): void
{
$this->_init(\Esun\CustomerVat\Model\ResourceModel\VatApplication::class);
}
public static function getStatuses(): array
{
return [
self::STATUS_PENDING => __('Pending Review'),
self::STATUS_APPROVED => __('Approved'),
self::STATUS_REJECTED => __('Rejected'),
];
}
}
@@ -0,0 +1,128 @@
<?php
declare(strict_types=1);
namespace Esun\CustomerVat\Model;
use Esun\CustomerVat\Model\ResourceModel\VatApplication as VatResource;
use Esun\CustomerVat\Model\ResourceModel\VatApplication\CollectionFactory;
use Magento\Framework\Exception\LocalizedException;
class VatApplicationService
{
public function __construct(
private readonly VatApplicationFactory $applicationFactory,
private readonly VatResource $resource,
private readonly CollectionFactory $collectionFactory,
private readonly EuCountries $euCountries
) {
}
public function getByIdForCustomer(int $id, int $customerId): VatApplication
{
$application = $this->applicationFactory->create();
$this->resource->load($application, $id);
if (!$application->getId() || (int)$application->getData('customer_id') !== $customerId) {
throw new LocalizedException(__('The VAT application no longer exists.'));
}
return $application;
}
public function saveForCustomer(int $customerId, array $data, int $id = 0): VatApplication
{
$companyName = trim((string)($data['company_name'] ?? ''));
$countryId = strtoupper(trim((string)($data['country_id'] ?? '')));
$vatNumber = trim((string)($data['vat_number'] ?? ''));
$normalized = $this->normalize($vatNumber);
if ($companyName === '' || mb_strlen($companyName) > 255) {
throw new LocalizedException(__('Enter a valid company name.'));
}
if (!$this->euCountries->isEu($countryId)) {
throw new LocalizedException(__('Select a valid EU country.'));
}
if (strlen($normalized) < 4 || strlen($normalized) > 64) {
throw new LocalizedException(__('Enter a valid VAT number.'));
}
$duplicate = $this->collectionFactory->create()
->addFieldToFilter('customer_id', $customerId)
->addFieldToFilter('country_id', $countryId)
->addFieldToFilter('normalized_vat_number', $normalized);
if ($id > 0) {
$duplicate->addFieldToFilter('entity_id', ['neq' => $id]);
}
if ($duplicate->getSize()) {
throw new LocalizedException(__('This VAT number has already been submitted for the selected country.'));
}
$application = $id > 0
? $this->getByIdForCustomer($id, $customerId)
: $this->applicationFactory->create()->setData('customer_id', $customerId);
$changed = !$application->getId()
|| (string)$application->getData('company_name') !== $companyName
|| (string)$application->getData('country_id') !== $countryId
|| (string)$application->getData('normalized_vat_number') !== $normalized;
$application->addData([
'company_name' => $companyName,
'country_id' => $countryId,
'vat_number' => $vatNumber,
'normalized_vat_number' => $normalized,
]);
if ($changed) {
$application->addData([
'status' => VatApplication::STATUS_PENDING,
'review_note' => null,
'reviewed_by' => null,
'reviewed_at' => null,
]);
}
$this->resource->save($application);
return $application;
}
public function deleteForCustomer(int $id, int $customerId): void
{
$this->resource->delete($this->getByIdForCustomer($id, $customerId));
}
public function findApproved(int $customerId, string $countryId): ?VatApplication
{
if ($customerId <= 0 || !$this->euCountries->isEu($countryId)) {
return null;
}
$application = $this->collectionFactory->create()
->addFieldToFilter('customer_id', $customerId)
->addFieldToFilter('country_id', strtoupper($countryId))
->addFieldToFilter('status', VatApplication::STATUS_APPROVED)
->setOrder('reviewed_at', 'DESC')
->setPageSize(1)
->getFirstItem();
return $application->getId() ? $application : null;
}
public function getCustomerStatus(int $customerId): string
{
if ($customerId <= 0) {
return 'guest';
}
$statuses = $this->collectionFactory->create()
->addFieldToFilter('customer_id', $customerId)
->getColumnValues('status');
if (in_array(VatApplication::STATUS_APPROVED, $statuses, true)) {
return VatApplication::STATUS_APPROVED;
}
if (in_array(VatApplication::STATUS_PENDING, $statuses, true)) {
return VatApplication::STATUS_PENDING;
}
if (in_array(VatApplication::STATUS_REJECTED, $statuses, true)) {
return VatApplication::STATUS_REJECTED;
}
return 'none';
}
public function normalize(string $vatNumber): string
{
return strtoupper((string)preg_replace('/[^A-Z0-9]/i', '', $vatNumber));
}
}
@@ -0,0 +1,41 @@
<?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,
];
}
}
@@ -0,0 +1,27 @@
<?php
declare(strict_types=1);
namespace Esun\CustomerVat\Observer;
use Magento\Framework\Event\Observer;
use Magento\Framework\Event\ObserverInterface;
use Magento\Quote\Model\Quote;
use Magento\Sales\Model\Order;
class CopyVatContextToOrder implements ObserverInterface
{
private const FIELDS = ['esun_vat_id', 'esun_vat_number', 'esun_vat_country_id',
'esun_vat_company_name', 'esun_vat_exempt', 'esun_nominal_tax_rate', 'esun_tax_mode'];
public function execute(Observer $observer): void
{
$quote = $observer->getEvent()->getQuote();
$order = $observer->getEvent()->getOrder();
if (!$quote instanceof Quote || !$order instanceof Order) {
return;
}
foreach (self::FIELDS as $field) {
$order->setData($field, $quote->getData($field));
}
}
}
@@ -0,0 +1,40 @@
<?php
declare(strict_types=1);
namespace Esun\CustomerVat\Observer;
use Esun\CustomerVat\Model\TaxContextResolver;
use Magento\Framework\Event\Observer;
use Magento\Framework\Event\ObserverInterface;
use Magento\Quote\Model\Quote;
class UpdateQuoteVatContext implements ObserverInterface
{
public function __construct(private readonly TaxContextResolver $resolver)
{
}
public function execute(Observer $observer): void
{
$quote = $observer->getEvent()->getQuote();
if (!$quote instanceof Quote || !(int)$quote->getStoreId()) {
return;
}
$address = $quote->isVirtual() ? $quote->getBillingAddress() : $quote->getShippingAddress();
$context = $this->resolver->resolve(
(int)$quote->getStoreId(),
(int)$quote->getCustomerId(),
(string)$address->getCountryId()
);
$vat = $context->vatApplication;
$quote->addData([
'esun_vat_id' => $vat ? (int)$vat->getId() : null,
'esun_vat_number' => $vat ? (string)$vat->getData('vat_number') : null,
'esun_vat_country_id' => $vat ? (string)$vat->getData('country_id') : null,
'esun_vat_company_name' => $vat ? (string)$vat->getData('company_name') : null,
'esun_vat_exempt' => $context->exempt ? 1 : 0,
'esun_nominal_tax_rate' => $context->nominalRate,
'esun_tax_mode' => $context->mode,
]);
}
}
@@ -0,0 +1,20 @@
<?php
declare(strict_types=1);
namespace Esun\CustomerVat\Plugin\CustomerData;
use Esun\CustomerVat\Model\VatPromptProvider;
use Magento\Checkout\CustomerData\Cart;
class CartVatPromptPlugin
{
public function __construct(private readonly VatPromptProvider $provider)
{
}
public function afterGetSectionData(Cart $subject, array $result): array
{
$result['vat_prompt'] = $this->provider->getData();
return $result;
}
}
@@ -0,0 +1,81 @@
<?php
declare(strict_types=1);
namespace Esun\CustomerVat\Plugin\Tax;
use Esun\CustomerVat\Model\TaxContextResolver;
use Esun\CustomerVat\Setup\Patch\Data\ConfigureTaxRules;
use Magento\Framework\App\ResourceConnection;
use Magento\Tax\Api\Data\QuoteDetailsInterface;
use Magento\Tax\Model\TaxCalculation;
class TaxCalculationPlugin
{
private ?int $exemptClassId = null;
public function __construct(
private readonly TaxContextResolver $contextResolver,
private readonly ResourceConnection $resourceConnection
) {
}
public function beforeCalculateTax(
TaxCalculation $subject,
QuoteDetailsInterface $quoteDetails,
$storeId = null,
$round = true
): array {
if ($storeId === null) {
return [$quoteDetails, $storeId, $round];
}
$storeId = (int)$storeId;
$shippingCountryId = (string)($quoteDetails->getShippingAddress()?->getCountryId() ?? '');
$context = $this->contextResolver->resolve(
$storeId,
(int)$quoteDetails->getCustomerId(),
$shippingCountryId
);
if (!$context->exempt || $context->nominalRate <= 0) {
return [$quoteDetails, $storeId, $round];
}
$taxClassKey = $quoteDetails->getCustomerTaxClassKey();
if ($taxClassKey) {
$taxClassKey->setValue($this->getExemptClassId());
$quoteDetails->setCustomerTaxClassKey($taxClassKey);
}
$divisor = 1 + ($context->nominalRate / 100);
foreach ($quoteDetails->getItems() ?? [] as $item) {
$item->setUnitPrice($this->divide((float)$item->getUnitPrice(), $divisor));
$item->setDiscountAmount($this->divide((float)$item->getDiscountAmount(), $divisor));
$item->setIsTaxIncluded(false);
$extensionAttributes = $item->getExtensionAttributes();
if ($extensionAttributes && $extensionAttributes->getPriceForTaxCalculation() !== null) {
$extensionAttributes->setPriceForTaxCalculation(
$this->divide((float)$extensionAttributes->getPriceForTaxCalculation(), $divisor)
);
$item->setExtensionAttributes($extensionAttributes);
}
}
return [$quoteDetails, $storeId, $round];
}
private function getExemptClassId(): int
{
if ($this->exemptClassId !== null) {
return $this->exemptClassId;
}
$connection = $this->resourceConnection->getConnection();
$this->exemptClassId = (int)$connection->fetchOne(
$connection->select()->from($this->resourceConnection->getTableName('tax_class'), 'class_id')
->where('class_name = ?', ConfigureTaxRules::EXEMPT_TAX_CLASS)
->where('class_type = ?', 'CUSTOMER')
);
return $this->exemptClassId;
}
private function divide(float $amount, float $divisor): float
{
return round($amount / $divisor, 8);
}
}
@@ -0,0 +1,184 @@
<?php
declare(strict_types=1);
namespace Esun\CustomerVat\Setup\Patch\Data;
use Esun\CustomerVat\Model\EuCountries;
use Magento\Framework\Setup\ModuleDataSetupInterface;
use Magento\Framework\Setup\Patch\DataPatchInterface;
class ConfigureTaxRules implements DataPatchInterface
{
public const EXEMPT_TAX_CLASS = 'eSUN EU VAT Exempt Customer';
public function __construct(private readonly ModuleDataSetupInterface $moduleDataSetup)
{
}
public function apply(): self
{
$setup = $this->moduleDataSetup;
$connection = $setup->getConnection();
$setup->startSetup();
$taxClassTable = $setup->getTable('tax_class');
$rateTable = $setup->getTable('tax_calculation_rate');
$ruleTable = $setup->getTable('tax_calculation_rule');
$calculationTable = $setup->getTable('tax_calculation');
$this->ensureTaxClass($taxClassTable, self::EXEMPT_TAX_CLASS, 'CUSTOMER');
$customerClassIds = array_map('intval', $connection->fetchCol(
$connection->select()->from($taxClassTable, 'class_id')->where('class_type = ?', 'CUSTOMER')
));
$productClassIds = array_map('intval', $connection->fetchCol(
$connection->select()->from($taxClassTable, 'class_id')->where('class_type = ?', 'PRODUCT')
));
$euStandardRule = $this->ensureRule(
$ruleTable,
'eSUN EU Calculated VAT',
['eSUN EU Standard VAT 19']
);
$ukRule = $this->ensureRule($ruleTable, 'eSUN UK VAT 20');
$legacyRuleIds = array_map('intval', $connection->fetchCol(
$connection->select()->from($ruleTable, 'tax_calculation_rule_id')
->where('code IN (?)', ['eSUN EU VAT Exempt 0'])
));
$connection->delete(
$calculationTable,
['tax_calculation_rule_id IN (?)' => array_merge([$euStandardRule, $ukRule], $legacyRuleIds)]
);
foreach (EuCountries::CODES as $countryId) {
$nominalRate = EuCountries::RATES[$countryId] ?? 19.0;
$standardRateId = $this->ensureRate(
$rateTable,
sprintf('ESUN-EU-%s-NOMINAL-%s', $countryId, (int)$nominalRate),
$countryId,
EuCountries::toAppliedRate($nominalRate)
);
$this->link($calculationTable, $standardRateId, $euStandardRule, $customerClassIds, $productClassIds);
}
$ukRateId = $this->ensureRate(
$rateTable,
'ESUN-GB-NOMINAL-20',
'GB',
EuCountries::toAppliedRate(20.0)
);
$this->link($calculationTable, $ukRateId, $ukRule, $customerClassIds, $productClassIds);
// The database initially contains Magento sample US state tax data. These markets must be tax-free.
$noTaxRateIds = $connection->fetchCol(
$connection->select()->from($rateTable, 'tax_calculation_rate_id')->where('tax_country_id IN (?)', ['US', 'CA', 'AU'])
);
if ($noTaxRateIds) {
$connection->delete($calculationTable, ['tax_calculation_rate_id IN (?)' => $noTaxRateIds]);
}
$this->configureWebsites();
$setup->endSetup();
return $this;
}
private function ensureTaxClass(string $table, string $name, string $type): int
{
$connection = $this->moduleDataSetup->getConnection();
$id = $connection->fetchOne($connection->select()->from($table, 'class_id')
->where('class_name = ?', $name)->where('class_type = ?', $type));
if ($id) {
return (int)$id;
}
$connection->insert($table, ['class_name' => $name, 'class_type' => $type]);
return (int)$connection->lastInsertId($table);
}
private function ensureRate(string $table, string $code, string $countryId, float $rate): int
{
$connection = $this->moduleDataSetup->getConnection();
$id = $connection->fetchOne($connection->select()->from($table, 'tax_calculation_rate_id')->where('code = ?', $code));
$data = ['tax_country_id' => $countryId, 'tax_region_id' => 0, 'tax_postcode' => '*', 'code' => $code,
'rate' => $rate, 'zip_is_range' => null, 'zip_from' => null, 'zip_to' => null];
if ($id) {
$connection->update($table, $data, ['tax_calculation_rate_id = ?' => (int)$id]);
return (int)$id;
}
$connection->insert($table, $data);
return (int)$connection->lastInsertId($table);
}
private function ensureRule(string $table, string $code, array $legacyCodes = []): int
{
$connection = $this->moduleDataSetup->getConnection();
$id = $connection->fetchOne(
$connection->select()->from($table, 'tax_calculation_rule_id')
->where('code IN (?)', array_merge([$code], $legacyCodes))
->order('tax_calculation_rule_id ASC')
);
if ($id) {
$connection->update($table, ['code' => $code], ['tax_calculation_rule_id = ?' => (int)$id]);
return (int)$id;
}
$connection->insert($table, ['code' => $code, 'priority' => 0, 'position' => 0, 'calculate_subtotal' => 0]);
return (int)$connection->lastInsertId($table);
}
private function link(string $table, int $rateId, int $ruleId, array $customerClassIds, array $productClassIds): void
{
$rows = [];
foreach ($customerClassIds as $customerClassId) {
foreach ($productClassIds as $productClassId) {
$rows[] = ['tax_calculation_rate_id' => $rateId, 'tax_calculation_rule_id' => $ruleId,
'customer_tax_class_id' => $customerClassId, 'product_tax_class_id' => $productClassId];
}
}
if ($rows) {
$this->moduleDataSetup->getConnection()->insertMultiple($table, $rows);
}
}
private function configureWebsites(): void
{
$connection = $this->moduleDataSetup->getConnection();
$websiteTable = $this->moduleDataSetup->getTable('store_website');
$configTable = $this->moduleDataSetup->getTable('core_config_data');
$countries = [
'eu' => 'DE',
'eu_site' => 'DE',
'uk' => 'GB',
'gb_site' => 'GB',
'us_site' => 'US',
'au' => 'AU',
'au_site' => 'AU',
];
foreach ($countries as $websiteCode => $countryId) {
$websiteId = (int)$connection->fetchOne(
$connection->select()->from($websiteTable, 'website_id')->where('code = ?', $websiteCode)
);
if (!$websiteId) {
continue;
}
$values = [
'tax/calculation/price_includes_tax' => '0',
'tax/calculation/shipping_includes_tax' => '0',
'tax/calculation/based_on' => 'shipping',
'tax/calculation/cross_border_trade_enabled' => '1',
'tax/calculation/apply_after_discount' => '1',
'tax/defaults/country' => $countryId,
'tax/display/type' => '1',
'tax/cart_display/price' => '1',
'tax/cart_display/subtotal' => '1',
'tax/cart_display/shipping' => '1',
'tax/sales_display/price' => '1',
'tax/sales_display/subtotal' => '1',
'tax/sales_display/shipping' => '1',
];
foreach ($values as $path => $value) {
$connection->insertOnDuplicate($configTable,
['scope' => 'websites', 'scope_id' => $websiteId, 'path' => $path, 'value' => $value], ['value']);
}
}
}
public static function getDependencies(): array { return []; }
public function getAliases(): array { return []; }
}
@@ -0,0 +1,28 @@
<?php
declare(strict_types=1);
namespace Esun\CustomerVat\Setup\Patch\Data;
use Magento\Framework\Setup\ModuleDataSetupInterface;
use Magento\Framework\Setup\Patch\DataPatchInterface;
class FixTaxRatePostcodeFlags implements DataPatchInterface
{
public function __construct(private readonly ModuleDataSetupInterface $moduleDataSetup)
{
}
public function apply(): self
{
$connection = $this->moduleDataSetup->getConnection();
$connection->update(
$this->moduleDataSetup->getTable('tax_calculation_rate'),
['zip_is_range' => null, 'zip_from' => null, 'zip_to' => null],
['code LIKE ?' => 'ESUN-%']
);
return $this;
}
public static function getDependencies(): array { return [ConfigureTaxRules::class]; }
public function getAliases(): array { return []; }
}
@@ -0,0 +1,77 @@
<?php
declare(strict_types=1);
namespace Esun\CustomerVat\Setup\Patch\Data;
use Magento\Framework\App\ResourceConnection;
use Magento\Framework\Serialize\Serializer\Json;
use Magento\Framework\Setup\Patch\DataPatchInterface;
class MoveVatSelectionColumnFirst implements DataPatchInterface
{
private const GRID_NAMESPACE = 'esun_customer_vat_listing';
public function __construct(
private readonly ResourceConnection $resourceConnection,
private readonly Json $json
) {
}
public function apply(): self
{
$connection = $this->resourceConnection->getConnection();
$table = $this->resourceConnection->getTableName('ui_bookmark');
$bookmarks = $connection->fetchAll(
$connection->select()
->from($table, ['bookmark_id', 'config'])
->where('namespace = ?', self::GRID_NAMESPACE)
);
foreach ($bookmarks as $bookmark) {
$config = $this->json->unserialize((string)$bookmark['config']);
if (!is_array($config) || !$this->moveSelectionFirst($config)) {
continue;
}
$connection->update(
$table,
['config' => $this->json->serialize($config)],
['bookmark_id = ?' => (int)$bookmark['bookmark_id']]
);
}
return $this;
}
private function moveSelectionFirst(array &$config): bool
{
$changed = false;
if (isset($config['positions']) && is_array($config['positions'])
&& array_key_exists('ids', $config['positions'])) {
asort($config['positions'], SORT_NUMERIC);
$columns = array_keys($config['positions']);
$columns = array_values(array_diff($columns, ['ids']));
array_unshift($columns, 'ids');
$config['positions'] = array_flip($columns);
$changed = true;
}
foreach ($config as $key => &$value) {
if ($key !== 'positions' && is_array($value)) {
$changed = $this->moveSelectionFirst($value) || $changed;
}
}
unset($value);
return $changed;
}
public static function getDependencies(): array
{
return [];
}
public function getAliases(): array
{
return [];
}
}
@@ -0,0 +1,29 @@
<?php
declare(strict_types=1);
namespace Esun\CustomerVat\Setup\Patch\Data;
use Magento\Framework\Setup\Patch\DataPatchInterface;
class ReconfigureTaxRulesV2 implements DataPatchInterface
{
public function __construct(private readonly ConfigureTaxRules $configureTaxRules)
{
}
public function apply(): self
{
$this->configureTaxRules->apply();
return $this;
}
public static function getDependencies(): array
{
return [ConfigureTaxRules::class];
}
public function getAliases(): array
{
return [];
}
}
@@ -0,0 +1,37 @@
<?php
declare(strict_types=1);
namespace Esun\CustomerVat\Ui\Component\Listing\Column;
use Magento\Framework\UrlInterface;
use Magento\Framework\View\Element\UiComponent\ContextInterface;
use Magento\Framework\View\Element\UiComponentFactory;
use Magento\Ui\Component\Listing\Columns\Column;
class Actions extends Column
{
public function __construct(ContextInterface $context, UiComponentFactory $factory,
private readonly UrlInterface $url, array $components = [], array $data = [])
{
parent::__construct($context, $factory, $components, $data);
}
public function prepareDataSource(array $dataSource): array
{
if (!isset($dataSource['data']['items']) || !is_array($dataSource['data']['items'])) {
return $dataSource;
}
foreach ($dataSource['data']['items'] as &$item) {
if (!isset($item['entity_id'])) {
continue;
}
$item[$this->getData('name')]['view'] = [
'href' => $this->url->getUrl('esun_customer_vat/application/view', ['id' => $item['entity_id']]),
'label' => __('Review'),
];
}
unset($item);
return $dataSource;
}
}
+11
View File
@@ -0,0 +1,11 @@
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:Acl/etc/acl.xsd">
<acl><resources><resource id="Magento_Backend::admin">
<resource id="Magento_Customer::customer">
<resource id="Esun_CustomerVat::applications" title="VAT Number Applications" sortOrder="80">
<resource id="Esun_CustomerVat::review" title="Review VAT Applications" sortOrder="10"/>
</resource>
</resource>
</resource></resources></acl>
</config>
@@ -0,0 +1,9 @@
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Backend:etc/menu.xsd">
<menu>
<add id="Esun_CustomerVat::applications" title="VAT Number Applications"
module="Esun_CustomerVat" sortOrder="80" parent="Magento_Customer::customer"
action="esun_customer_vat/application/index" resource="Esun_CustomerVat::applications"/>
</menu>
</config>
@@ -0,0 +1,9 @@
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:App/etc/routes.xsd">
<router id="admin">
<route id="esun_customer_vat" frontName="esun_customer_vat">
<module name="Esun_CustomerVat" before="Magento_Backend"/>
</route>
</router>
</config>
@@ -0,0 +1,51 @@
<?xml version="1.0"?>
<schema xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:Setup/Declaration/Schema/etc/schema.xsd">
<table name="esun_customer_vat" resource="default" engine="innodb" comment="eSUN Customer VAT Applications">
<column xsi:type="int" name="entity_id" unsigned="true" nullable="false" identity="true" comment="Entity ID"/>
<column xsi:type="int" name="customer_id" unsigned="true" nullable="false" comment="Customer ID"/>
<column xsi:type="varchar" name="company_name" nullable="false" length="255" comment="Company Name"/>
<column xsi:type="varchar" name="country_id" nullable="false" length="2" comment="VAT Country"/>
<column xsi:type="varchar" name="vat_number" nullable="false" length="64" comment="VAT Number"/>
<column xsi:type="varchar" name="normalized_vat_number" nullable="false" length="64" comment="Normalized VAT Number"/>
<column xsi:type="varchar" name="status" nullable="false" length="16" default="pending" comment="Review Status"/>
<column xsi:type="text" name="review_note" nullable="true" comment="Review Note"/>
<column xsi:type="int" name="reviewed_by" unsigned="true" nullable="true" comment="Admin User ID"/>
<column xsi:type="timestamp" name="reviewed_at" on_update="false" nullable="true" comment="Reviewed At"/>
<column xsi:type="timestamp" name="created_at" on_update="false" nullable="false" default="CURRENT_TIMESTAMP" comment="Created At"/>
<column xsi:type="timestamp" name="updated_at" on_update="true" nullable="false" default="CURRENT_TIMESTAMP" comment="Updated At"/>
<constraint xsi:type="primary" referenceId="PRIMARY"><column name="entity_id"/></constraint>
<constraint xsi:type="foreign" referenceId="ESUN_CUSTOMER_VAT_CUSTOMER_ID_CUSTOMER_ENTITY_ENTITY_ID"
table="esun_customer_vat" column="customer_id" referenceTable="customer_entity"
referenceColumn="entity_id" onDelete="CASCADE"/>
<constraint xsi:type="unique" referenceId="ESUN_CUSTOMER_VAT_CUSTOMER_COUNTRY_NUMBER">
<column name="customer_id"/><column name="country_id"/><column name="normalized_vat_number"/>
</constraint>
<index referenceId="ESUN_CUSTOMER_VAT_CUSTOMER_STATUS_COUNTRY" indexType="btree">
<column name="customer_id"/><column name="status"/><column name="country_id"/>
</index>
<index referenceId="ESUN_CUSTOMER_VAT_STATUS_CREATED" indexType="btree">
<column name="status"/><column name="created_at"/>
</index>
</table>
<table name="quote" resource="checkout">
<column xsi:type="int" name="esun_vat_id" unsigned="true" nullable="true" comment="Matched VAT Application ID"/>
<column xsi:type="varchar" name="esun_vat_number" nullable="true" length="64" comment="VAT Number Snapshot"/>
<column xsi:type="varchar" name="esun_vat_country_id" nullable="true" length="2" comment="VAT Country Snapshot"/>
<column xsi:type="varchar" name="esun_vat_company_name" nullable="true" length="255" comment="VAT Company Snapshot"/>
<column xsi:type="smallint" name="esun_vat_exempt" unsigned="true" nullable="false" default="0" comment="VAT Exempt"/>
<column xsi:type="decimal" name="esun_nominal_tax_rate" scale="4" precision="12" nullable="false" default="0" comment="Nominal Tax Rate"/>
<column xsi:type="varchar" name="esun_tax_mode" nullable="false" length="32" default="" comment="Tax Mode"/>
</table>
<table name="sales_order" resource="sales">
<column xsi:type="int" name="esun_vat_id" unsigned="true" nullable="true" comment="Matched VAT Application ID"/>
<column xsi:type="varchar" name="esun_vat_number" nullable="true" length="64" comment="VAT Number Snapshot"/>
<column xsi:type="varchar" name="esun_vat_country_id" nullable="true" length="2" comment="VAT Country Snapshot"/>
<column xsi:type="varchar" name="esun_vat_company_name" nullable="true" length="255" comment="VAT Company Snapshot"/>
<column xsi:type="smallint" name="esun_vat_exempt" unsigned="true" nullable="false" default="0" comment="VAT Exempt"/>
<column xsi:type="decimal" name="esun_nominal_tax_rate" scale="4" precision="12" nullable="false" default="0" comment="Nominal Tax Rate"/>
<column xsi:type="varchar" name="esun_tax_mode" nullable="false" length="32" default="" comment="Tax Mode"/>
</table>
</schema>
@@ -0,0 +1,49 @@
{
"esun_customer_vat": {
"column": {
"entity_id": true,
"customer_id": true,
"company_name": true,
"country_id": true,
"vat_number": true,
"normalized_vat_number": true,
"status": true,
"review_note": true,
"reviewed_by": true,
"reviewed_at": true,
"created_at": true,
"updated_at": true
},
"index": {
"ESUN_CUSTOMER_VAT_CUSTOMER_ID_STATUS_COUNTRY_ID": true,
"ESUN_CUSTOMER_VAT_STATUS_CREATED_AT": true
},
"constraint": {
"PRIMARY": true,
"ESUN_CUSTOMER_VAT_CUSTOMER_ID_CUSTOMER_ENTITY_ENTITY_ID": true,
"ESUN_CUSTOMER_VAT_CUSTOMER_ID_COUNTRY_ID_NORMALIZED_VAT_NUMBER": true
}
},
"quote": {
"column": {
"esun_vat_id": true,
"esun_vat_number": true,
"esun_vat_country_id": true,
"esun_vat_company_name": true,
"esun_vat_exempt": true,
"esun_nominal_tax_rate": true,
"esun_tax_mode": true
}
},
"sales_order": {
"column": {
"esun_vat_id": true,
"esun_vat_number": true,
"esun_vat_country_id": true,
"esun_vat_company_name": true,
"esun_vat_exempt": true,
"esun_nominal_tax_rate": true,
"esun_tax_mode": true
}
}
}
+15
View File
@@ -0,0 +1,15 @@
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="Magento\Framework\View\Element\UiComponent\DataProvider\CollectionFactory">
<arguments><argument name="collections" xsi:type="array">
<item name="esun_customer_vat_listing_data_source" xsi:type="string">EsunCustomerVatGridCollection</item>
</argument></arguments>
</type>
<virtualType name="EsunCustomerVatGridCollection" type="Magento\Framework\View\Element\UiComponent\DataProvider\SearchResult">
<arguments>
<argument name="mainTable" xsi:type="string">esun_customer_vat</argument>
<argument name="resourceModel" xsi:type="string">Esun\CustomerVat\Model\ResourceModel\VatApplication</argument>
</arguments>
</virtualType>
</config>
+12
View File
@@ -0,0 +1,12 @@
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
<event name="sales_quote_collect_totals_before">
<observer name="esun_customer_vat_update_quote_context"
instance="Esun\CustomerVat\Observer\UpdateQuoteVatContext"/>
</event>
<event name="sales_model_service_quote_submit_before">
<observer name="esun_customer_vat_copy_context_to_order"
instance="Esun\CustomerVat\Observer\CopyVatContextToOrder"/>
</event>
</config>
@@ -0,0 +1,8 @@
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="Magento\Checkout\CustomerData\Cart">
<plugin name="esun_customer_vat_cart_prompt"
type="Esun\CustomerVat\Plugin\CustomerData\CartVatPromptPlugin" sortOrder="50"/>
</type>
</config>
@@ -0,0 +1,9 @@
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:App/etc/routes.xsd">
<router id="standard">
<route id="esun_customer_vat" frontName="esun_customer_vat">
<module name="Esun_CustomerVat"/>
</route>
</router>
</config>
+12
View File
@@ -0,0 +1,12 @@
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Esun_CustomerVat">
<sequence>
<module name="Esun_Customer"/>
<module name="Esun_Cart"/>
<module name="Magento_Tax"/>
<module name="Magento_Sales"/>
</sequence>
</module>
</config>
@@ -0,0 +1,4 @@
<?php
use Magento\Framework\Component\ComponentRegistrar;
ComponentRegistrar::register(ComponentRegistrar::MODULE, 'Esun_CustomerVat', __DIR__);
@@ -0,0 +1,5 @@
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body><referenceContainer name="content"><uiComponent name="esun_customer_vat_listing"/></referenceContainer></body>
</page>
@@ -0,0 +1,8 @@
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body><referenceContainer name="content">
<block class="Esun\CustomerVat\Block\Adminhtml\Application\View" name="esun.customer.vat.admin.view"
template="Esun_CustomerVat::application/view.phtml"/>
</referenceContainer></body>
</page>
@@ -0,0 +1,38 @@
<?php
/** @var \Esun\CustomerVat\Block\Adminhtml\Application\View $block */
/** @var \Magento\Framework\Escaper $escaper */
$application = $block->getApplication();
$customer = $block->getCustomer();
?>
<div class="admin__page-section">
<div class="admin__page-section-title"><span class="title"><?= $escaper->escapeHtml(__('VAT Application')) ?></span></div>
<div class="admin__page-section-content"><table class="admin__table-secondary">
<tr><th><?= $escaper->escapeHtml(__('Customer')) ?></th><td><?= $escaper->escapeHtml($customer->getFirstname() . ' ' . $customer->getLastname()) ?> (#<?= (int)$customer->getId() ?>)</td></tr>
<tr><th><?= $escaper->escapeHtml(__('Email')) ?></th><td><?= $escaper->escapeHtml($customer->getEmail()) ?></td></tr>
<tr><th><?= $escaper->escapeHtml(__('Company Name')) ?></th><td><?= $escaper->escapeHtml((string)$application->getData('company_name')) ?></td></tr>
<tr><th><?= $escaper->escapeHtml(__('Country')) ?></th><td><?= $escaper->escapeHtml($block->getCountryName((string)$application->getData('country_id'))) ?> (<?= $escaper->escapeHtml((string)$application->getData('country_id')) ?>)</td></tr>
<tr><th><?= $escaper->escapeHtml(__('VAT Number')) ?></th><td><?= $escaper->escapeHtml((string)$application->getData('vat_number')) ?></td></tr>
<tr><th><?= $escaper->escapeHtml(__('Submitted At')) ?></th><td><?= $escaper->escapeHtml((string)$application->getData('created_at')) ?></td></tr>
<tr><th><?= $escaper->escapeHtml(__('Current Status')) ?></th><td><?= $escaper->escapeHtml((string)(\Esun\CustomerVat\Model\VatApplication::getStatuses()[$application->getData('status')] ?? $application->getData('status'))) ?></td></tr>
</table></div>
</div>
<div class="admin__page-section">
<form method="post" action="<?= $escaper->escapeUrl($block->getUrl('esun_customer_vat/application/review')) ?>">
<?= $block->getBlockHtml('formkey') ?>
<input type="hidden" name="id" value="<?= (int)$application->getId() ?>"/>
<div class="admin__field field">
<label class="admin__field-label" for="vat-status"><span><?= $escaper->escapeHtml(__('Status')) ?></span></label>
<div class="admin__field-control"><select class="admin__control-select" id="vat-status" name="status">
<?php foreach (\Esun\CustomerVat\Model\VatApplication::getStatuses() as $value => $label): ?>
<option value="<?= $escaper->escapeHtmlAttr($value) ?>" <?= $application->getData('status') === $value ? 'selected' : '' ?>><?= $escaper->escapeHtml($label) ?></option>
<?php endforeach; ?>
</select></div>
</div>
<div class="admin__field field">
<label class="admin__field-label" for="review-note"><span><?= $escaper->escapeHtml(__('Review Note')) ?></span></label>
<div class="admin__field-control"><textarea class="admin__control-textarea" id="review-note" name="review_note" rows="5"><?= $escaper->escapeHtml((string)$application->getData('review_note')) ?></textarea></div>
</div>
<div style="margin-top:20px"><button type="submit" class="action-primary"><span><?= $escaper->escapeHtml(__('Save Review')) ?></span></button>
<a class="action-secondary" href="<?= $escaper->escapeUrl($block->getUrl('esun_customer_vat/application/index')) ?>"><?= $escaper->escapeHtml(__('Back')) ?></a></div>
</form>
</div>
@@ -0,0 +1,64 @@
<?xml version="1.0"?>
<listing xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
<argument name="data" xsi:type="array"><item name="js_config" xsi:type="array">
<item name="provider" xsi:type="string">esun_customer_vat_listing.esun_customer_vat_listing_data_source</item>
</item></argument>
<settings><spinner>esun_customer_vat_columns</spinner><deps><dep>esun_customer_vat_listing.esun_customer_vat_listing_data_source</dep></deps></settings>
<dataSource name="esun_customer_vat_listing_data_source" component="Magento_Ui/js/grid/provider">
<settings><storageConfig><param name="indexField" xsi:type="string">entity_id</param></storageConfig><updateUrl path="mui/index/render"/></settings>
<aclResource>Esun_CustomerVat::applications</aclResource>
<dataProvider class="Magento\Framework\View\Element\UiComponent\DataProvider\DataProvider" name="esun_customer_vat_listing_data_source">
<settings><requestFieldName>id</requestFieldName><primaryFieldName>entity_id</primaryFieldName></settings>
</dataProvider>
</dataSource>
<listingToolbar name="listing_top">
<settings><sticky>true</sticky></settings>
<bookmark name="bookmarks"/>
<columnsControls name="columns_controls"/>
<filters name="listing_filters"/>
<massaction name="listing_massaction">
<action name="approve">
<settings>
<confirm>
<message translate="true">Are you sure you want to approve the selected VAT applications?</message>
<title translate="true">Approve VAT Applications</title>
</confirm>
<url path="esun_customer_vat/application/massApprove"/>
<type>approve</type>
<label translate="true">Approve</label>
</settings>
</action>
<action name="reject">
<settings>
<confirm>
<message translate="true">Are you sure you want to reject the selected VAT applications?</message>
<title translate="true">Reject VAT Applications</title>
</confirm>
<url path="esun_customer_vat/application/massReject"/>
<type>reject</type>
<label translate="true">Reject</label>
</settings>
</action>
</massaction>
<paging name="listing_paging"/>
</listingToolbar>
<columns name="esun_customer_vat_columns">
<selectionsColumn name="ids" sortOrder="0">
<settings>
<indexField>entity_id</indexField>
<resizeEnabled>false</resizeEnabled>
<resizeDefaultWidth>55</resizeDefaultWidth>
</settings>
</selectionsColumn>
<column name="entity_id" sortOrder="10"><settings><filter>textRange</filter><label translate="true">ID</label><sorting>desc</sorting></settings></column>
<column name="status" component="Magento_Ui/js/grid/columns/select" sortOrder="20"><settings><filter>select</filter><dataType>select</dataType><options class="Esun\CustomerVat\Model\Source\Status"/><label translate="true">Status</label></settings></column>
<column name="customer_id" sortOrder="30"><settings><filter>textRange</filter><label translate="true">Customer ID</label></settings></column>
<column name="company_name" sortOrder="40"><settings><filter>text</filter><label translate="true">Company Name</label></settings></column>
<column name="country_id" sortOrder="50"><settings><filter>text</filter><label translate="true">Country</label></settings></column>
<column name="vat_number" sortOrder="60"><settings><filter>text</filter><label translate="true">VAT Number</label></settings></column>
<column name="created_at" class="Magento\Ui\Component\Listing\Columns\Date" sortOrder="70"><settings><filter>dateRange</filter><dataType>date</dataType><label translate="true">Submitted At</label></settings></column>
<column name="reviewed_at" class="Magento\Ui\Component\Listing\Columns\Date" sortOrder="80"><settings><filter>dateRange</filter><dataType>date</dataType><label translate="true">Reviewed At</label></settings></column>
<actionsColumn name="actions" class="Esun\CustomerVat\Ui\Component\Listing\Column\Actions" sortOrder="90"><settings><indexField>entity_id</indexField><resizeEnabled>false</resizeEnabled><resizeDefaultWidth>100</resizeDefaultWidth></settings></actionsColumn>
</columns>
</listing>
@@ -0,0 +1,9 @@
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<head><css src="Esun_CustomerVat::css/vat-prompt.css"/></head>
<body><referenceBlock name="checkout.cart">
<block class="Esun\CustomerVat\Block\Cart\VatPrompt" name="esun.cart.vat.prompt" as="vat_prompt"
template="Esun_CustomerVat::cart/vat-prompt.phtml" cacheable="false"/>
</referenceBlock></body>
</page>
@@ -0,0 +1,16 @@
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceBlock name="customer_account_navigation">
<block class="Magento\Customer\Block\Account\SortLinkInterface"
name="customer-account-navigation-vat-link">
<arguments>
<argument name="path" xsi:type="string">esun_customer_vat/vat/index</argument>
<argument name="label" xsi:type="string" translate="true">VAT Number Management</argument>
<argument name="sortOrder" xsi:type="number">245</argument>
</arguments>
</block>
</referenceBlock>
</body>
</page>
@@ -0,0 +1,5 @@
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<head><css src="Esun_CustomerVat::css/vat-prompt.css"/></head>
</page>
@@ -0,0 +1,5 @@
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<update handle="esun_customer_vat_vat_new"/>
</page>
@@ -0,0 +1,12 @@
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<update handle="customer_account"/>
<head><css src="Esun_CustomerVat::css/vat-account.css"/></head>
<body>
<referenceContainer name="content">
<block class="Esun\CustomerVat\Block\Account\Vat" name="esun.customer.vat.list"
template="Esun_CustomerVat::account/vat/list.phtml" cacheable="false"/>
</referenceContainer>
</body>
</page>
@@ -0,0 +1,12 @@
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<update handle="customer_account"/>
<head><css src="Esun_CustomerVat::css/vat-account.css"/></head>
<body>
<referenceContainer name="content">
<block class="Esun\CustomerVat\Block\Account\Vat" name="esun.customer.vat.form"
template="Esun_CustomerVat::account/vat/form.phtml" cacheable="false"/>
</referenceContainer>
</body>
</page>
@@ -0,0 +1,41 @@
<?php
/** @var \Esun\CustomerVat\Block\Account\Vat $block */
/** @var \Magento\Framework\Escaper $escaper */
$application = $block->getCurrentApplication();
?>
<div class="esun-vat-account esun-vat-form-page">
<?php if ($application && $application->getData('status') === 'approved'): ?>
<div class="message warning"><span><?= $escaper->escapeHtml(__('Changing an approved VAT number will return it to Pending Review and suspend its tax exemption eligibility.')) ?></span></div>
<?php endif; ?>
<form class="form vat-number-form" method="post"
action="<?= $escaper->escapeUrl($block->getUrl('esun_customer_vat/vat/save')) ?>"
data-mage-init='{"validation":{}}'>
<?= $block->getBlockHtml('formkey') ?>
<?php if ($application): ?><input type="hidden" name="id" value="<?= (int)$application->getId() ?>"/><?php endif; ?>
<fieldset class="fieldset esun-vat-form__fields">
<div class="field company-name required">
<label class="label" for="vat-company-name"><span><?= $escaper->escapeHtml(__('Company Name')) ?></span></label>
<div class="control"><input class="input-text" id="vat-company-name" name="company_name" required maxlength="255" value="<?= $escaper->escapeHtmlAttr((string)($application?->getData('company_name') ?? '')) ?>"/></div>
</div>
<div class="field country required">
<label class="label" for="vat-country"><span><?= $escaper->escapeHtml(__('Country')) ?></span></label>
<div class="control">
<select id="vat-country" name="country_id" required>
<option value=""><?= $escaper->escapeHtml(__('Please select a country')) ?></option>
<?php foreach ($block->getCountryOptions() as $option): ?>
<option value="<?= $escaper->escapeHtmlAttr((string)$option['value']) ?>" <?= $application?->getData('country_id') === $option['value'] ? 'selected' : '' ?>><?= $escaper->escapeHtml((string)$option['label']) ?></option>
<?php endforeach; ?>
</select>
</div>
</div>
<div class="field vat-number required">
<label class="label" for="vat-number"><span><?= $escaper->escapeHtml(__('VAT Number')) ?></span></label>
<div class="control"><input class="input-text" id="vat-number" name="vat_number" required maxlength="64" value="<?= $escaper->escapeHtmlAttr((string)($application?->getData('vat_number') ?? '')) ?>"/></div>
</div>
</fieldset>
<div class="actions-toolbar esun-vat-form__actions">
<div class="primary"><button type="submit" class="action primary"><span><?= $escaper->escapeHtml(__('Submit for Review')) ?></span></button></div>
<div class="secondary"><a class="action back" href="<?= $escaper->escapeUrl($block->getUrl('esun_customer_vat/vat/index')) ?>"><span><?= $escaper->escapeHtml(__('Back')) ?></span></a></div>
</div>
</form>
</div>
@@ -0,0 +1,56 @@
<?php
/** @var \Esun\CustomerVat\Block\Account\Vat $block */
/** @var \Magento\Framework\Escaper $escaper */
?>
<div class="esun-vat-account">
<div class="esun-vat-account__heading">
<p><?= $escaper->escapeHtml(__('Submit VAT numbers for review. You can register a different VAT number for each EU country.')) ?></p>
<a class="action primary" href="<?= $escaper->escapeUrl($block->getUrl('esun_customer_vat/vat/new')) ?>">
<span><?= $escaper->escapeHtml(__('Add VAT Number')) ?></span>
</a>
</div>
<?php if ($block->getApplications()->getSize()): ?>
<div class="table-wrapper vat-applications">
<table class="data table table-vat-applications">
<caption class="table-caption"><?= $escaper->escapeHtml(__('VAT Number Applications')) ?></caption>
<thead><tr>
<th scope="col"><?= $escaper->escapeHtml(__('Company Name')) ?></th>
<th scope="col"><?= $escaper->escapeHtml(__('VAT Number')) ?></th>
<th scope="col"><?= $escaper->escapeHtml(__('Country')) ?></th>
<th scope="col"><?= $escaper->escapeHtml(__('Status')) ?></th>
<th scope="col"><?= $escaper->escapeHtml(__('Actions')) ?></th>
</tr></thead>
<tbody>
<?php foreach ($block->getApplications() as $application): ?>
<tr>
<td data-th="<?= $escaper->escapeHtmlAttr(__('Company Name')) ?>"><?= $escaper->escapeHtml((string)$application->getData('company_name')) ?></td>
<td data-th="<?= $escaper->escapeHtmlAttr(__('VAT Number')) ?>"><?= $escaper->escapeHtml((string)$application->getData('vat_number')) ?></td>
<td data-th="<?= $escaper->escapeHtmlAttr(__('Country')) ?>"><?= $escaper->escapeHtml($block->getCountryName((string)$application->getData('country_id'))) ?></td>
<td data-th="<?= $escaper->escapeHtmlAttr(__('Status')) ?>">
<span class="vat-status vat-status--<?= $escaper->escapeHtmlAttr((string)$application->getData('status')) ?>">
<?= $escaper->escapeHtml($block->getStatusLabel((string)$application->getData('status'))) ?>
</span>
<?php if ($application->getData('review_note')): ?>
<small><?= $escaper->escapeHtml((string)$application->getData('review_note')) ?></small>
<?php endif; ?>
</td>
<td data-th="<?= $escaper->escapeHtmlAttr(__('Actions')) ?>" class="actions">
<a href="<?= $escaper->escapeUrl($block->getUrl('esun_customer_vat/vat/edit', ['id' => $application->getId()])) ?>"><?= $escaper->escapeHtml(__('Edit')) ?></a>
<form method="post" action="<?= $escaper->escapeUrl($block->getUrl('esun_customer_vat/vat/delete')) ?>" data-mage-init='{"validation":{}}'>
<?= $block->getBlockHtml('formkey') ?>
<input type="hidden" name="id" value="<?= (int)$application->getId() ?>"/>
<button type="submit" class="action delete" data-confirm="<?= $escaper->escapeHtmlAttr(__('Deleting an approved VAT number immediately removes its exemption eligibility. Continue?')) ?>">
<span><?= $escaper->escapeHtml(__('Delete')) ?></span>
</button>
</form>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
<?php else: ?>
<div class="message info empty"><span><?= $escaper->escapeHtml(__('You have not submitted any VAT numbers.')) ?></span></div>
<?php endif; ?>
</div>
@@ -0,0 +1,12 @@
<?php
/** @var \Esun\CustomerVat\Block\Cart\VatPrompt $block */
/** @var \Magento\Framework\Escaper $escaper */
$prompt = $block->getPromptData();
?>
<?php if (!empty($prompt['show'])): ?>
<div class="cart_list_tips">
<?= $escaper->escapeHtml(__('If you are an EU VAT registered business, please contact Customer Service to')) ?>
<a href="<?= $escaper->escapeUrl((string)$prompt['apply_url']) ?>"><?= $escaper->escapeHtml(__('Apply for Tax Exemption')) ?></a>
<?= $escaper->escapeHtml(__('and make your purchases through the B2B account to apply the appropriate tax exemption provisions.')) ?>
</div>
<?php endif; ?>
@@ -0,0 +1,232 @@
.esun-vat-account {
color: #333;
font-size: 16px;
}
.esun-vat-account__heading {
align-items: center;
display: flex;
gap: 28px;
justify-content: space-between;
margin-bottom: 30px;
}
.esun-vat-account__heading p {
color: #666;
line-height: 1.7;
margin: 0;
max-width: 720px;
}
.esun-vat-account__heading .action.primary,
.esun-vat-form__actions .action.primary {
border-radius: 24px;
box-sizing: border-box;
font-size: 16px;
font-weight: 600;
line-height: 22px;
min-height: 46px;
padding: 11px 28px;
white-space: nowrap;
}
.vat-number-form {
max-width: 860px;
}
.esun-vat-form-page > .message {
margin-bottom: 26px;
}
.esun-vat-form__fields {
border: 0;
display: grid;
gap: 24px 28px;
grid-template-columns: repeat(2, minmax(0, 1fr));
margin: 0;
padding: 0;
}
.esun-vat-form__fields .field {
margin: 0 !important;
}
.esun-vat-form__fields .company-name {
grid-column: 1 / -1;
}
.esun-vat-form__fields .field > .label {
box-sizing: border-box;
color: #555;
display: block !important;
float: none !important;
font-size: 15px;
font-weight: 400;
margin: 0 0 9px;
padding: 0 !important;
text-align: left !important;
width: 100% !important;
}
.esun-vat-form__fields .field > .control {
float: none !important;
width: 100% !important;
}
.esun-vat-form__fields input.input-text,
.esun-vat-form__fields select {
background-color: #fff;
border: 1px solid #d7d7d7;
border-radius: 4px;
box-shadow: none;
box-sizing: border-box;
color: #333;
font-size: 16px;
height: 48px;
padding: 0 15px;
width: 100%;
}
.esun-vat-form__fields input.input-text:focus,
.esun-vat-form__fields select:focus {
border-color: #18aa59;
box-shadow: 0 0 0 1px #18aa59;
outline: 0;
}
.esun-vat-form__actions {
align-items: center;
display: flex;
gap: 22px;
margin-left: 0 !important;
margin-top: 34px !important;
text-align: left;
width: 100% !important;
}
.esun-vat-form__actions::before,
.esun-vat-form__actions::after {
display: none !important;
}
.esun-vat-form__actions .primary,
.esun-vat-form__actions .secondary {
float: none !important;
margin: 0;
}
.esun-vat-form__actions .action.back {
color: #666;
font-size: 15px;
text-decoration: none;
}
.esun-vat-form__actions .action.back:hover,
.esun-vat-form__actions .action.back:focus {
color: #18aa59;
}
.table-vat-applications td,
.table-vat-applications th {
vertical-align: middle;
}
.table-vat-applications .actions {
white-space: nowrap;
}
.table-vat-applications .actions a {
color: #555;
text-decoration: none;
}
.table-vat-applications .actions a:hover,
.table-vat-applications .actions a:focus {
color: #18aa59;
}
.table-vat-applications .actions form {
display: inline;
margin-left: 14px;
}
.table-vat-applications .actions button {
background: none;
border: 0;
box-shadow: none;
color: #d32f2f;
font: inherit;
padding: 0;
}
.vat-status {
display: inline-block;
border-radius: 14px;
padding: 3px 10px;
font-size: 12px;
line-height: 18px;
}
.vat-status--pending {
background: #fff4d6;
color: #8a6200;
}
.vat-status--approved {
background: #dff5e8;
color: #14713c;
}
.vat-status--rejected {
background: #fde5e5;
color: #a12828;
}
.table-vat-applications small {
color: #777;
display: block;
margin-top: 5px;
max-width: 280px;
}
.esun-vat-account > .message.empty {
border: 0;
border-radius: 4px;
margin: 0;
padding: 28px 24px;
}
@media (max-width: 767px) {
.esun-vat-account__heading {
align-items: flex-start;
flex-direction: column;
gap: 18px;
}
.esun-vat-form__fields {
grid-template-columns: 1fr;
}
.esun-vat-form__fields .company-name {
grid-column: auto;
}
.esun-vat-form__actions {
align-items: stretch;
flex-direction: column;
gap: 16px;
}
.esun-vat-form__actions .primary,
.esun-vat-form__actions .action.primary {
width: 100%;
}
.esun-vat-form__actions .secondary {
text-align: center;
}
.table-vat-applications .actions form {
margin-left: 10px;
}
}
@@ -0,0 +1 @@
.cart_list_tips{font-size:14px;line-height:25px;color:#555;opacity:.7}.cart_list_tips a{color:inherit;text-decoration:underline}.cart_list_tips a:hover{color:inherit;opacity:.8}.esun-cart-page>.cart_list_tips{margin:-10px 0 20px}.esun-cart-drawer__contents>.cart_list_tips{padding:8px 20px 10px}