/** * Return region code by id * * @param $regionId * @return string|null * @throws LocalizedException */ protected function getRegionCodeById($regionId) { if (!$regionId) { return null; } /** @var \Magento\Directory\Model\Region $region */ $region = $this->regionCollection->getItemById($regionId); if (!$region instanceof Region) { throw new LocalizedException(__('Region "%1" was not found.', [$regionId])); } return $region->getCode(); }