Skip to content

Commit cec25e1

Browse files
author
Stanislav Idolov
committed
MAGETWO-59258: [Github] Override module-directory/etc/zip_codes.xml only the last code of a country gets included #6694
1 parent c7d18bd commit cec25e1

File tree

5 files changed

+87
-1
lines changed

5 files changed

+87
-1
lines changed

app/code/Magento/Directory/Model/Country/Postcode/Config/Reader.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ class Reader extends \Magento\Framework\Config\Reader\Filesystem
1212
*
1313
* @var array
1414
*/
15-
protected $_idAttributes = ['/config/zip' => 'countryCode'];
15+
protected $_idAttributes = [
16+
'/config/zip' => 'countryCode',
17+
'/config/zip/codes/code' => 'id',
18+
];
1619

1720
/**
1821
* Construct the FileSystem Reader Class
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
/**
4+
* Copyright © 2016 Magento. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
9+
<module name="Magento_TestModuleDirectoryZipCodes" setup_version="0.0.1" active="true">
10+
<sequence>
11+
<module name="Magento_Directory"/>
12+
</sequence>
13+
</module>
14+
</config>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0"?>
2+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Directory:etc/zip_codes.xsd">
3+
<zip countryCode="NL">
4+
<codes>
5+
<code id="pattern_1" active="true" example="test1">^[0-9]{4}[a-zA-Z]{2}$</code>
6+
<code id="pattern_2" active="true" example="test2">^[0-5]{4}[a-z]{2}$</code>
7+
</codes>
8+
</zip>
9+
<zip countryCode="NL_NEW">
10+
<codes>
11+
<code id="pattern_1" active="true" example="test1">^[0-2]{4}[A-Z]{2}$</code>
12+
</codes>
13+
</zip>
14+
</config>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
use Magento\Framework\Component\ComponentRegistrar;
8+
9+
$registrar = new ComponentRegistrar();
10+
if ($registrar->getPath(ComponentRegistrar::MODULE, 'Magento_TestModuleDirectoryZipCodes') === null) {
11+
ComponentRegistrar::register(ComponentRegistrar::MODULE, 'Magento_TestModuleDirectoryZipCodes', __DIR__);
12+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Directory\Model\Country\Postcode\Config;
8+
9+
class ReaderTest extends \PHPUnit_Framework_TestCase
10+
{
11+
/**
12+
* @var \Magento\Directory\Model\Country\Postcode\Config\Reader
13+
*/
14+
private $reader;
15+
16+
protected function setUp()
17+
{
18+
$this->reader = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
19+
\Magento\Directory\Model\Country\Postcode\Config\Reader::class
20+
);
21+
}
22+
23+
public function testRead()
24+
{
25+
$result = $this->reader->read();
26+
27+
$this->assertArrayHasKey('NL', $result);
28+
$this->assertArrayHasKey('pattern_1', $result['NL']);
29+
$this->assertArrayHasKey('pattern_2', $result['NL']);
30+
31+
$this->assertEquals('test1', $result['NL']['pattern_1']['example']);
32+
$this->assertEquals('^[0-9]{4}[a-zA-Z]{2}$', $result['NL']['pattern_1']['pattern']);
33+
34+
$this->assertEquals('test2', $result['NL']['pattern_2']['example']);
35+
$this->assertEquals('^[0-5]{4}[a-z]{2}$', $result['NL']['pattern_2']['pattern']);
36+
37+
$this->assertArrayHasKey('NL_NEW', $result);
38+
$this->assertArrayHasKey('pattern_1', $result['NL_NEW']);
39+
40+
$this->assertEquals('test1', $result['NL_NEW']['pattern_1']['example']);
41+
$this->assertEquals('^[0-2]{4}[A-Z]{2}$', $result['NL_NEW']['pattern_1']['pattern']);
42+
}
43+
}

0 commit comments

Comments
 (0)