Jump to content

Vat number field


lsantana12

Recommended Posts

Hello,

 

Can you help me? I´m creating a shop on Prestashop 1.6 and I need to include on registration form a field named Vat number under Company Information block. I already comment SIRET and APE fiels as I don´t need them (in fact I even don´t know what they are as I am in Portugal and they are not used).

 

So, now I only have two fieds under Company Information block, the name and the site name and I must to include a field for tha Vat number. I don´t need any number validation, I just need to be a required field.

 

I will appreciate your help,

 

Thanks a lot

 

Luisa

Link to comment
Share on other sites

  • 3 months later...
  • 1 year later...
  • 1 year later...

My answer is late but maybe it will help other people :-)

(and it's a homemade solution but it works fine for me...)

 

You have 2 different solutions:

 

1) You can set PrestaShop to register with address included directly from back office and then install free / default / official module "European VAT number v2.0.0 - by PrestaShop" which make a VAT field appear when you fill "company name" and it test it on VIES or accept it directly without testing.

 

2) Enable B2B mode, in localisation/Translation you rename "Siret" in "VAT number" and add one of those code in \classes\Validate.php :

 

INSTEAD OF:

    /**
     * Validate SIRET Code
     *
     * @param string $siret SIRET Code
     * @return bool Return true if is valid
     */
    public static function isSiret($siret)
    {
        if (Tools::strlen($siret) != 14) {
            return false;
        }
        $sum = 0;
        for ($i = 0; $i != 14; $i++) {
            $tmp = ((($i + 1) % 2) + 1) * intval($siret[$i]);
            if ($tmp >= 10) {
                $tmp -= 9;
            }
            $sum += $tmp;
        }
        return ($sum % 10 === 0);
    }

PUT FOR VIES CHECKING:

 

public static function isSiret($siret)
    {
        $vatid = $siret; // replace for the VAT-ID you would like to check

$vatid = str_replace(array(' ', '.', '-', ',', ', '), '', trim($vatid));
$cc = substr($vatid, 0, 2);
$vn = substr($vatid, 2);
$client = new SoapClient("http://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl");

if($client){
    $params = array('countryCode' => $cc, 'vatNumber' => $vn);
    try{
        $r = $client->checkVat($params);
        if($r->valid == true){
            // VAT-ID is valid
            return (1);
        } else {
            // VAT-ID is NOT valid
            return (0);
        }

        // This foreach shows every single line of the returned information
        foreach($r as $k=>$prop){
            echo $k . ': ' . $prop;
        }

    } catch(SoapFault $e) {
        echo 'Error, see message: '.$e->faultstring;
        return (0);
        
    }
} else {return (0);
    // Connection to host not possible, europe.eu down?
    
}
    }

OR JUST CHECK IF NUMBER LOOKS RIGHT:

    public static function isSiret($siret)
    {
    $cc = strtoupper(substr($siret, 0, 2));
    $vn = substr($siret, 2);
    $os = array('AT', 'BE', 'DK', 'FI', 'FR', 'DE', 'GR', 'EL', 'IE', 'IT', 'LU', 'NL', 'PT', 'ES', 'SE', 'GB', 'CY', 'EE', 'HU', 'LV', 'LT', 'MT', 'PL', 'SK', 'CZ', 'SI', 'BG', 'HR');
    if ($cc== 'RO') {if (strlen($vn) < 11 AND strlen($vn) > 1 ) {return true;[spam-filter]
    elseif (in_array($cc, $os)) {if (strlen($vn) < 13 AND strlen($vn) > 7 ) {return true;[spam-filter]
    else {return false;}
    }

 

Note that VIES is highly restrictive on "automated request" more than 5 request per day and you are blacklisted...

Link to comment
Share on other sites

  • 3 years later...

check out while customer registering his address that time VAT option is there , can rewrite GST no. instead of VAT ?
means suppose while customer registering during check out , needs to enter all address , company name & VAT no. etc, my point can i change the word GST no. instead of VAT no. , this text , i want to change coz in India , GST applicable not VAT .

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...