Skip to content

Commit 42d0c1a

Browse files
committed
MC-31256: Admin: Create/update/delete customer addresses
1 parent ba8fae3 commit 42d0c1a

File tree

5 files changed

+838
-0
lines changed

5 files changed

+838
-0
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\TestFramework\Directory\Model;
9+
10+
use Magento\Directory\Model\RegionFactory;
11+
12+
/**
13+
* Return region ID by region default name and country code.
14+
*/
15+
class GetRegionIdByName
16+
{
17+
/**
18+
* @var RegionFactory
19+
*/
20+
private $regionFactory;
21+
22+
/**
23+
* @var array
24+
*/
25+
private $regionIdsCache;
26+
27+
/**
28+
* @param RegionFactory $regionFactory
29+
*/
30+
public function __construct(
31+
RegionFactory $regionFactory
32+
) {
33+
$this->regionFactory = $regionFactory;
34+
}
35+
36+
/**
37+
* Get region ID from cache property if region id exist or load it.
38+
*
39+
* @param string $regionName
40+
* @param string $countryId
41+
* @return int|null
42+
*/
43+
public function execute(string $regionName, string $countryId): ?int
44+
{
45+
$cacheKey = "{$regionName}_{$countryId}";
46+
47+
if (!isset($this->regionIdsCache[$cacheKey])) {
48+
$region = $this->regionFactory->create()->loadByName($regionName, $countryId);
49+
$this->regionIdsCache[$cacheKey] = $region->getRegionId() ? (int)$region->getRegionId() : null;
50+
}
51+
52+
return $this->regionIdsCache[$cacheKey];
53+
}
54+
}

0 commit comments

Comments
 (0)