Skip to content

Commit 7164d34

Browse files
committed
MAGETWO-53811: Region Names are not Translated on Checkout Shipping Form
1 parent 4a3a58e commit 7164d34

File tree

2 files changed

+119
-6
lines changed

2 files changed

+119
-6
lines changed

app/code/Magento/Directory/Model/ResourceModel/Region/Collection.php

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ public function __construct(
4949
\Magento\Framework\Model\ResourceModel\Db\AbstractDb $resource = null
5050
) {
5151
$this->_localeResolver = $localeResolver;
52+
$this->_resource = $resource;
5253
parent::__construct($entityFactory, $logger, $fetchStrategy, $eventManager, $connection, $resource);
5354
}
5455

@@ -186,15 +187,26 @@ public function addRegionCodeOrNameFilter($region)
186187
*/
187188
public function toOptionArray()
188189
{
189-
$options = $this->_toOptionArray(
190-
'region_id',
191-
'default_name',
192-
['title' => 'default_name', 'country_id' => 'country_id']
193-
);
190+
$options = [];
191+
$propertyMap = [
192+
'value' => 'region_id',
193+
'title' => 'default_name',
194+
'country_id' => 'country_id',
195+
];
196+
197+
foreach ($this as $item) {
198+
$option = [];
199+
foreach ($propertyMap as $code => $field) {
200+
$option[$code] = $item->getData($field);
201+
}
202+
$option['label'] = $item->getName();
203+
$options[] = $option;
204+
}
205+
194206
if (count($options) > 0) {
195207
array_unshift(
196208
$options,
197-
['title ' => null, 'value' => null, 'label' => __('Please select a region, state or province.')]
209+
['title' => null, 'value' => null, 'label' => __('Please select a region, state or province.')]
198210
);
199211
}
200212
return $options;
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Directory\Test\Unit\Model\ResourceModel\Region;
7+
8+
use Magento\Directory\Model\ResourceModel\Region\Collection;
9+
use Magento\Framework\DB\Adapter\Pdo\Mysql;
10+
use Magento\Framework\DB\Select;
11+
use Magento\Framework\Model\ResourceModel\Db\AbstractDb;
12+
use Magento\Framework\Event\ManagerInterface;
13+
use Magento\Framework\Data\Collection\Db\FetchStrategyInterface;
14+
use Magento\Framework\Data\Collection\EntityFactory;
15+
use Magento\Framework\Locale\ResolverInterface;
16+
use Magento\Framework\DataObject;
17+
use Psr\Log\LoggerInterface;
18+
19+
class CollectionTest extends \PHPUnit_Framework_TestCase
20+
{
21+
/**
22+
* @var Collection
23+
*/
24+
private $collection;
25+
26+
protected function setUp()
27+
{
28+
$entityFactoryMock = $this->getMock(EntityFactory::class, [], [], '', false);
29+
$loggerMock = $this->getMock(LoggerInterface::class);
30+
$fetchStrategyMock = $this->getMock(FetchStrategyInterface::class);
31+
$eventManagerMock = $this->getMock(ManagerInterface::class);
32+
$localeResolverMock = $this->getMock(ResolverInterface::class);
33+
$connectionMock = $this->getMock(Mysql::class, [], [], '', false);
34+
$resourceMock = $this->getMockForAbstractClass(AbstractDb::class,
35+
[],
36+
'',
37+
false,
38+
true,
39+
true,
40+
['getConnection', 'getMainTable', 'getTable', '__wakeup']
41+
);
42+
43+
$selectMock = $this->getMock(Select::class, [], [], '', false);
44+
$connectionMock->expects($this->any())->method('select')->will($this->returnValue($selectMock));
45+
$resourceMock->expects($this->any())->method('getConnection')->will($this->returnValue($connectionMock));
46+
$resourceMock->expects($this->any())->method('getTable')->will($this->returnArgument(0));
47+
48+
$this->collection = new Collection(
49+
$entityFactoryMock,
50+
$loggerMock,
51+
$fetchStrategyMock,
52+
$eventManagerMock,
53+
$localeResolverMock,
54+
$connectionMock,
55+
$resourceMock
56+
);
57+
}
58+
59+
public function testToOptionArray()
60+
{
61+
$items = [
62+
[
63+
'name' => 'Region Name 1',
64+
'default_name' => 'Default Region Name 1',
65+
'region_id' => 1,
66+
'country_id' => 1,
67+
],
68+
[
69+
'name' => 'Region Name 2',
70+
'default_name' => 'Default Region Name 2',
71+
'region_id' => 2,
72+
'country_id' => 1,
73+
],
74+
];
75+
foreach ($items as $itemData) {
76+
$this->collection->addItem(new DataObject($itemData));
77+
}
78+
79+
$expectedResult = [
80+
[
81+
'label' => __('Please select a region, state or province.'),
82+
'value' => null,
83+
'title' => null,
84+
],
85+
[
86+
'value' => 1,
87+
'title' => 'Default Region Name 1',
88+
'country_id' => 1,
89+
'label' => 'Region Name 1',
90+
],
91+
[
92+
'value' => 2,
93+
'title' => 'Default Region Name 2',
94+
'country_id' => 1,
95+
'label' => 'Region Name 2',
96+
],
97+
];
98+
99+
$this->assertEquals($expectedResult, $this->collection->toOptionArray());
100+
}
101+
}

0 commit comments

Comments
 (0)