Herzlich willkommen

Developer

This page is aimed at developers who want to extend the module or integrate it into their own workflows. Module namespace: Geissweb\Euvat.

Events

The module provides its own event hook and at the same time takes over the handling of a number of standard Magento events.

Custom event: vat_validation_after

Dispatched after every VAT ID check in Geissweb\Euvat\Validator\BaseValidator – regardless of whether the number is valid, invalid or technically failed. Use it to react to check results (e.g. custom logging, ERP sync, notifications).

Payload:

Key Type
validation_result Geissweb\Euvat\Api\Data\ValidationResultInterface

Register your own observer (etc/events.xml):

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
    <event name="vat_validation_after">
        <observer name="mycompany_vat_validation_after"
                  instance="MyCompany\Module\Observer\VatValidationAfter"/>
    </event>
</config>
declare(strict_types=1);

namespace MyCompany\Module\Observer;

use Geissweb\Euvat\Api\Data\ValidationResultInterface;
use Magento\Framework\Event\Observer;
use Magento\Framework\Event\ObserverInterface;

class VatValidationAfter implements ObserverInterface
{
    public function execute(Observer $observer): void
    {
        /** @var ValidationResultInterface $result */
        $result = $observer->getEvent()->getData('validation_result');

        if ($result->getVatIsValid()) {
            // e.g. further process the registered company name
            $name = $result->getVatTraderName();
        }
    }
}

Observed standard Magento events

Event Observer Purpose
customer_login Observer\CustomerLogin Revalidation on login.
sales_quote_address_save_before Observer\QuoteAddressSaveBefore Write validation data to the quote address.
estimate_tax_based_on_country Observer\AfterEstimateTaxBasedOnCountry Pseudo-registry for the tax country.
customer_address_save_before Observer\BeforeAddressSaveObserver Replaces the core VIV observer.
customer_address_save_after Observer\AfterAddressSaveObserver Replaces the core VIV observer.
admin_system_config_changed_section_euvat Observer\Adminhtml\ConfigObserver Reacts to configuration changes.

Service Contracts (API)

The public interfaces are located under Geissweb\Euvat\Api. Prefer these over concrete model classes.

ValidationRepositoryInterface

Access to the validation cache (vat_validation).

namespace Geissweb\Euvat\Api;

interface ValidationRepositoryInterface
{
    public function save(Data\ValidationInterface $validation): Data\ValidationInterface;
    public function get(int $validationId): Data\ValidationInterface;
    public function getList(SearchCriteriaInterface $searchCriteria): SearchResults;
    public function delete(Data\ValidationInterface $validation): bool;
    public function deleteById(int $validationId): bool;
    /** @return Data\ValidationInterface|AbstractModel  (false, wenn nicht vorhanden) */
    public function getByVatId(string $vatId);
}

Example – read the cached result for a number:

public function __construct(
    private readonly \Geissweb\Euvat\Api\ValidationRepositoryInterface $validationRepository
) {
}

public function isCachedValid(string $vatId): bool
{
    $entry = $this->validationRepository->getByVatId($vatId);

    return $entry !== false
        && $entry->getVatIsValid()
        && $entry->getVatRequestSuccess();
}

Further interfaces

Interface Purpose
Api\Data\ValidationInterface Persisted cache record (getters/setters, field constants).
Api\Data\ValidationResultInterface Result of a single check (incl. warning, error, retry_available, trader data).
Api\Data\ValidationSearchResultsInterface Search result container for getList().
Api\CaseIdentifierInterface Determines the customer tax class (identifyCustomerTaxClass()) and the tax destination (identifyTaxDestination()) from the billing/shipping address.

DI preferences (etc/di.xml): ValidationRepositoryInterface → Model\ValidationRepository, Data\ValidationInterface → Model\Validation.

Console commands

geissweb:clean:vatnumbers

Cleans up existing VAT IDs in customer addresses (removes spaces/special characters and duplicate country prefixes) and removes syntactically invalid numbers. Additionally cleans up records in the vat_validation table.

# Dry run – only displays, changes nothing
bin/magento geissweb:clean:vatnumbers

# Actually apply the changes
bin/magento geissweb:clean:vatnumbers execute

Without the execute argument, no changes are made. Run the dry run first and review the output before using execute. Create a database backup beforehand.

geissweb:selftest:vatcalc

Self-test: calculates the tax for the supported scenarios and displays the results as a table. Useful for checking, after configuration, whether the tax rules and classes take effect as expected.

bin/magento geissweb:selftest:vatcalc