Skip to content
This repository has been archived by the owner on Oct 20, 2023. It is now read-only.

Commit

Permalink
Merge pull request #6 from maximebiloe/fix-b2b
Browse files Browse the repository at this point in the history
Make VAT number validation in PrestaShop 1.7
  • Loading branch information
mickaelandrieu authored Aug 30, 2016
2 parents 296a322 + 9a6f120 commit 7abf9d7
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
9 changes: 9 additions & 0 deletions upgrade/install-2.0.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

if (!defined('_PS_VERSION_'))
exit;

function upgrade_module_2_0($object)
{
return ($object->registerHook('actionValidateCustomerAddressForm'));
}
23 changes: 21 additions & 2 deletions vatnumber.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,15 @@ public function __construct()

$this->displayName = $this->l('European VAT number');
$this->description = $this->l('Enables you to enter the intra-community VAT number when creating the address. You must fill in the company field to allow entering the VAT number.');
$this->ps_versions_compliancy = array('min' => '1.6', 'max' => '1.6.99.99');
$this->ps_versions_compliancy = array('min' => '1.6', 'max' => _PS_VERSION_);
}

public function install()
{
return (parent::install() && Configuration::updateValue('VATNUMBER_MANAGEMENT', 1));
return
parent::install()
&& Configuration::updateValue('VATNUMBER_MANAGEMENT', 1)
&& $this->registerHook('actionValidateCustomerAddressForm');
}

public function uninstall()
Expand Down Expand Up @@ -291,4 +294,20 @@ public function getConfigFieldsValues()
'VATNUMBER_CHECKING' => Tools::getValue('VATNUMBER_CHECKING', Configuration::get('VATNUMBER_CHECKING')),
);
}

public function hookActionValidateCustomerAddressForm(&$params)
{
$form = $params['form'];
$is_valid = true;

if (($vatNumber = $form->getField('vat_number')) && Configuration::get('VATNUMBER_MANAGEMENT') && Configuration::get('VATNUMBER_CHECKING')) {
$isAVatNumber = VatNumber::WebServiceCheck($vatNumber->getValue());
if (is_array($isAVatNumber) && count($isAVatNumber) > 0) {
$vatNumber->addError($isAVatNumber[0]);
$is_valid = false;
}
}

return $is_valid;
}
}

0 comments on commit 7abf9d7

Please sign in to comment.