Skip to content

Commit 8ee5c38

Browse files
author
Hayder Sharhan
committed
MAGETWO-51296: [Github] Multiple calls to getCountryInfo result in a fatal error #3858
- To provide correct error message.
1 parent 4f6f313 commit 8ee5c38

File tree

3 files changed

+6
-7
lines changed

3 files changed

+6
-7
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,16 +97,16 @@ public function getCountryInfo($countryId)
9797
);
9898

9999
$countriesCollection = $this->directoryHelper->getCountryCollection($store)->load();
100+
$regions = $this->directoryHelper->getRegionData();
101+
$country = $countriesCollection->getItemById($countryId);
100102

101-
if ($countriesCollection->count() == 0) {
103+
if (!$country) {
102104
throw new NoSuchEntityException(
103105
__(
104106
'Requested country is not available.'
105107
)
106108
);
107109
}
108-
$regions = $this->directoryHelper->getRegionData();
109-
$country = $countriesCollection->getItemById($countryId);
110110
$countryInfo = $this->setCountryInfo($country, $regions, $storeLocale);
111111

112112
return $countryInfo;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ public function loadByStore($store = null)
143143
* Loads Item By Id
144144
*
145145
* @param string $countryId
146-
* @return \Magento\Directory\Model\ResourceModel\Country
146+
* @return \Magento\Directory\Model\ResourceModel\Country|null
147147
*/
148148
public function getItemById($countryId)
149149
{
@@ -152,7 +152,7 @@ public function getItemById($countryId)
152152
return $country;
153153
}
154154
}
155-
return $this->_countryFactory->create();
155+
return null;
156156
}
157157

158158
/**

app/code/Magento/Directory/Test/Unit/Model/CountryInformationAcquirerTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,6 @@ public function testGetCountryInfo()
130130
false
131131
);
132132
$countryCollection->expects($this->once())->method('load')->willReturnSelf();
133-
$countryCollection->expects($this->once())->method('count')->willReturn(1);
134133
$countryCollection->expects($this->once())->method('getItemById')->with('AE')->willReturn($testCountryInfo);
135134

136135
$this->directoryHelper->expects($this->once())->method('getCountryCollection')->willReturn($countryCollection);
@@ -174,9 +173,9 @@ public function testGetCountryInfoNotFound()
174173
false
175174
);
176175
$countryCollection->expects($this->once())->method('load')->willReturnSelf();
177-
$countryCollection->expects($this->once())->method('count')->willReturn(0);
178176

179177
$this->directoryHelper->expects($this->once())->method('getCountryCollection')->willReturn($countryCollection);
178+
$countryCollection->expects($this->once())->method('getItemById')->willReturn(null);
180179
$this->model->getCountryInfo('AE');
181180
}
182181
}

0 commit comments

Comments
 (0)