PrestaShop / vatnumber

Enables you to enter the intra-community VAT number when creating the address.
https://www.prestashop.com
Academic Free License v3.0
6 stars 42 forks source link

Fixes negative validation result not being respected… #9

Closed ckubitza closed 5 years ago

ckubitza commented 5 years ago

…, because boolean false is casted to empty string like when no hook is executed. Should fix: https://github.com/PrestaShop/PrestaShop/issues/9884

PierreRambaud commented 5 years ago

Not sure it is the right solution to change a boolean value to integer.. The problem is the cast I think.

ckubitza commented 5 years ago

Another possibility would be to fix it not in the module but in the function which uses the hook. So here https://github.com/PrestaShop/PrestaShop/blob/da467fbb8b5fcbb26f98c87041a8fcf23fe9c374/classes/form/CustomerAddressForm.php#L123-L125 the Hook::exec() call should have another two parameters to enable the array_return and then iterate over them instead of checking for the string. Maybe something like this:

$hookModuleReturns = Hook::exec('actionValidateCustomerAddressForm', array('form' => $this), null, true);
if (count($hookModuleReturns) > 0) {`
    $hookReturn = true;
    foreach ($hookModuleReturns as $hookModuleReturn) {
        $hookReturn &= (bool) $hookModuleReturn;
    }
    $is_valid &= $hookReturn;
}
PierreRambaud commented 5 years ago

I think it's where we must fix it and not here. You're right we must have a check where the hook is called.

ckubitza commented 5 years ago

I just realized that there are already changes made which address this problem: https://github.com/PrestaShop/PrestaShop/blob/335851e5523b19aac49a65e5173414cfbc7df083/classes/form/CustomerAddressForm.php#L123 (it's the strict string comaprison).