diff --git a/VATNumberTaxManager.php b/VATNumberTaxManager.php index eb939cc..6f80c93 100755 --- a/VATNumberTaxManager.php +++ b/VATNumberTaxManager.php @@ -28,9 +28,37 @@ class VATNumberTaxManager implements TaxManagerInterface { public static function isAvailableForThisAddress(Address $address) { - return (!empty($address->vat_number) - && $address->id_country != Configuration::get('VATNUMBER_COUNTRY') - && Configuration::get('VATNUMBER_MANAGEMENT') + /* + HOTFIX + + For some reason, this check is called 6 times (?) + + 1 w. the real address + 2 w.o. the real address + + 1 w. the real address + 2 w.o. the real address + + => [1 0 0 1 0 0] + + So we need to filter out the weird calls... + + We do this by caching the correct calls between calls; + by creating a static variable, which we save the address to, + if it does not contain NULL in some of the other fields. + */ + + static $cached_address = NULL; + + if ($address->id_customer != NULL) { + $cached_address = $address; + } + + // Now, check on the cached address object + return (!empty($cached_address->vat_number) + && !empty($cached_address->id_country) + && $cached_address->id_country != Configuration::get('VATNUMBER_COUNTRY') + && Configuration::get('VATNUMBER_MANAGEMENT') ); } diff --git a/config.xml b/config.xml index 67f9c8a..a4d3d19 100755 --- a/config.xml +++ b/config.xml @@ -2,7 +2,7 @@ vatnumber - + diff --git a/vatnumber.php b/vatnumber.php index 0f3afc7..ac5adc9 100644 --- a/vatnumber.php +++ b/vatnumber.php @@ -33,7 +33,7 @@ public function __construct() { $this->name = 'vatnumber'; $this->tab = 'billing_invoicing'; - $this->version = '2.0.0'; + $this->version = '2.1.0'; $this->author = 'PrestaShop'; $this->need_instance = 0;