Skip to content

Commit

Permalink
add matching for countrycode in VAT against selected country from add…
Browse files Browse the repository at this point in the history
…ress
  • Loading branch information
roman204 committed Dec 11, 2016
1 parent 48b914c commit 6295beb
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions Plugin/UidPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,20 @@
*/
namespace CopeX\VATFix\Plugin;

use Magento\Framework\Exception\ValidatorException;
use Magento\Customer\Model\Vat;

class UidPlugin
{
protected $_helper;

/**
* @param \CopeX\VATFix\Helper\Data $helper
*/
public function __construct(\CopeX\VATFix\Helper\Data $helper)
public function __construct(\CopeX\VATFix\Helper\Data $helper, \Magento\Framework\Message\ManagerInterface $messageManager )
{
$this->_helper = $helper;
$this->_messageManager = $messageManager;
}

/**
Expand All @@ -36,16 +40,19 @@ public function __construct(\CopeX\VATFix\Helper\Data $helper)
* @param string $requesterVatNumber
* @return array
*/
public function beforeCheckVatNumber(\Magento\Customer\Model\Vat $subject, $countryCode, $vatNumber, $requesterCountryCode = '', $requesterVatNumber = '')
public function beforeCheckVatNumber(Vat $subject, $countryCode, $vatNumber, $requesterCountryCode = '', $requesterVatNumber = '')
{
if($countryCode != $this->_helper->getCountryCodeFromVAT($vatNumber)){
$this->_messageManager->addError(__('Your selected country does not match the countrycode in VAT.'));
return array();
}
$newVatNumber = $vatNumber;
$newRequesterVatNumber = $requesterVatNumber;

if ($requesterVatNumber !== '' && $this->_helper->isCountryCodeInVAT($requesterVatNumber)) {
$newRequesterVatNumber = substr(str_replace(' ', '', trim($requesterVatNumber)), 2);
}


if ($this->_helper->isCountryCodeInVAT($newVatNumber)) {
$newVatNumber = substr(str_replace(' ', '', trim($vatNumber)), 2);
}
Expand Down

0 comments on commit 6295beb

Please sign in to comment.