Skip to content

Commit 7a0516a

Browse files
committed
ACP2E-182: Error while validating Store VAT Number
1 parent 940c9c0 commit 7a0516a

File tree

9 files changed

+58
-228
lines changed

9 files changed

+58
-228
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Config\Helper;
8+
9+
use Magento\Framework\App\Helper\AbstractHelper;
10+
use Magento\Store\Model\ScopeInterface;
11+
12+
class Country extends AbstractHelper
13+
{
14+
/**
15+
* Config path to UE country list
16+
*/
17+
const XML_PATH_EU_COUNTRIES_LIST = 'general/country/eu_countries';
18+
19+
/**
20+
* Fetch EU countries list
21+
*
22+
* @param null $storeId
23+
* @return false|string[]
24+
*/
25+
public function getEuCountryList($storeId=null)
26+
{
27+
$euCountries = explode(
28+
',',
29+
$this->scopeConfig->getValue(
30+
self::XML_PATH_EU_COUNTRIES_LIST,
31+
ScopeInterface::SCOPE_STORE,
32+
$storeId
33+
)
34+
);
35+
36+
return $euCountries;
37+
}
38+
}

app/code/Magento/Config/view/adminhtml/templates/system/config/js.phtml

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,16 @@ require([
1414
'prototype'
1515
], function () {
1616
17+
function inArray(arr, value)
18+
{
19+
for (var i = 0; i < arr.length; i++) {
20+
if (arr[i] === value) {
21+
return true;
22+
}
23+
}
24+
return false;
25+
}
26+
1727
var freeModel = Class.create();
1828
freeModel.prototype = {
1929
initialize : function()
@@ -76,7 +86,9 @@ originModel.prototype = {
7686
script;
7787

7888
$scriptString .= 'this.regionsUrl = "' . $block->escapeJs($block->getUrl('directory/json/countryRegion')) . '";';
79-
$scriptString .= 'this.euCountryUrl = "' . $block->escapeJs($block->getUrl('directory/json/isEuCountry')) . '";';
89+
$euCountries = $this->helper(\Magento\Config\Helper\Country::class)->getEuCountryList();
90+
$scriptString .= 'this.euCountryList = ' . json_encode($euCountries);
91+
8092
$scriptString .= <<<script
8193
8294
this.bindCountryRegionRelation();
@@ -137,11 +149,12 @@ $scriptString .= <<<script
137149
if (regionElement) {
138150
this.regionElement = regionElement;
139151
if (countryElement.value.length) {
140-
var objThis = this;
141-
setTimeout(function(){
142-
var euUrl = objThis.euCountryUrl+'countryCode/'+countryElement.value;
143-
objThis.loader.load(euUrl, {}, objThis.validateVatNumber.bind(objThis));
144-
}, 1000);
152+
var isEUCountry = false;
153+
if ( inArray(this.euCountryList, countryElement.value)) {
154+
isEUCountry = true;
155+
}
156+
this.validateVatNumber(isEUCountry);
157+
145158
var url = this.regionsUrl+'parent/'+countryElement.value;
146159
this.loader.load(url, {}, this.refreshRegionField.bind(this));
147160
} else {
@@ -209,7 +222,7 @@ $scriptString .= <<<script
209222
var resultElement = document.getElementById("validation_result");
210223
var btnVatNumber = document.getElementById(this.regionElement.id.replace(/region_id/, 'validate_vat_number'));
211224
212-
if (serverResponse === 'true') {
225+
if (serverResponse === true) {
213226
btnVatNumber.classList.remove('disabled');
214227
if (resultElement) {
215228
resultElement.style.display = "block";

app/code/Magento/Customer/Model/EuCountryProvider.php

Lines changed: 0 additions & 51 deletions
This file was deleted.

app/code/Magento/Customer/etc/di.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@
6565
<preference for="Magento\Customer\Api\SessionCleanerInterface" type="Magento\Customer\Model\Session\SessionCleaner"/>
6666
<preference for="Magento\Customer\Api\GroupExcludedWebsiteRepositoryInterface"
6767
type="Magento\Customer\Model\ResourceModel\GroupExcludedWebsiteRepository" />
68-
<preference for="Magento\Directory\Controller\Adminhtml\Json\EuCountryProviderInterface" type="Magento\Customer\Model\EuCountryProvider" />
6968
<virtualType name="SessionValidator" type="Magento\Framework\Session\CompositeValidator">
7069
<arguments>
7170
<argument name="validators" xsi:type="array">

app/code/Magento/Directory/Controller/Adminhtml/Json/EuCountryProviderInterface.php

Lines changed: 0 additions & 19 deletions
This file was deleted.

app/code/Magento/Directory/Controller/Adminhtml/Json/IsEuCountry.php

Lines changed: 0 additions & 58 deletions
This file was deleted.

app/code/Magento/Directory/Model/EuCountryProvider.php

Lines changed: 0 additions & 36 deletions
This file was deleted.

app/code/Magento/Directory/etc/di.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
<preference for="Magento\Directory\Api\CountryInformationAcquirerInterface" type="Magento\Directory\Model\CountryInformationAcquirer" />
4848
<preference for="Magento\Directory\Api\Data\CountryInformationInterface" type="Magento\Directory\Model\Data\CountryInformation" />
4949
<preference for="Magento\Directory\Api\Data\RegionInformationInterface" type="Magento\Directory\Model\Data\RegionInformation" />
50-
<preference for="Magento\Directory\Controller\Adminhtml\Json\EuCountryProviderInterface" type="Magento\Directory\Model\EuCountryProvider" />
5150
<type name="Magento\Config\Model\Config\TypePool">
5251
<arguments>
5352
<argument name="sensitive" xsi:type="array">

dev/tests/integration/testsuite/Magento/Directory/Controller/Adminhtml/Json/IsEuCountryTest.php

Lines changed: 0 additions & 55 deletions
This file was deleted.

0 commit comments

Comments
 (0)