@@ -313,6 +313,11 @@ class Order extends AbstractModel implements EntityInterface, OrderInterface
313
313
*/
314
314
private $ regionFactory ;
315
315
316
+ /**
317
+ * @var array
318
+ */
319
+ private $ regionItems ;
320
+
316
321
/**
317
322
* @param \Magento\Framework\Model\Context $context
318
323
* @param \Magento\Framework\Registry $registry
@@ -412,6 +417,7 @@ public function __construct(
412
417
->get (SearchCriteriaBuilder::class);
413
418
$ this ->scopeConfig = $ scopeConfig ?: ObjectManager::getInstance ()->get (ScopeConfigInterface::class);
414
419
$ this ->regionFactory = $ regionFactory ?: ObjectManager::getInstance ()->get (RegionFactory::class);
420
+ $ this ->regionItems = [];
415
421
416
422
parent ::__construct (
417
423
$ context ,
@@ -1337,6 +1343,7 @@ public function getTrackingNumbers()
1337
1343
*/
1338
1344
public function getShippingMethod ($ asObject = false )
1339
1345
{
1346
+ // phpstan:ignore "Call to an undefined static method"
1340
1347
$ shippingMethod = parent ::getShippingMethod ();
1341
1348
if (!$ asObject || !$ shippingMethod ) {
1342
1349
return $ shippingMethod ;
@@ -1359,9 +1366,16 @@ public function getAddressesCollection()
1359
1366
$ collection = $ this ->_addressCollectionFactory ->create ()->setOrderFilter ($ this );
1360
1367
if ($ this ->getId ()) {
1361
1368
foreach ($ collection as $ address ) {
1362
- $ region ->loadByName ($ address ->getRegion (), $ address ->getCountryId ());
1363
- if ($ region ->getName ()) {
1364
- $ address ->setRegion ($ region ->getName ());
1369
+ if (isset ($ this ->regionItems [$ address ->getCountryId ()][$ address ->getRegion ()])) {
1370
+ if ($ this ->regionItems [$ address ->getCountryId ()][$ address ->getRegion ()]) {
1371
+ $ address ->setRegion ($ this ->regionItems [$ address ->getCountryId ()][$ address ->getRegion ()]);
1372
+ }
1373
+ } else {
1374
+ $ region ->loadByName ($ address ->getRegion (), $ address ->getCountryId ());
1375
+ $ this ->regionItems [$ address ->getCountryId ()][$ address ->getRegion ()] = $ region ->getName ();
1376
+ if ($ region ->getName ()) {
1377
+ $ address ->setRegion ($ region ->getName ());
1378
+ }
1365
1379
}
1366
1380
$ address ->setOrder ($ this );
1367
1381
}
0 commit comments