Skip to content

Commit

Permalink
MAGETWO-48021: State value is not saved in customer account address o…
Browse files Browse the repository at this point in the history
…n storefront
  • Loading branch information
Oleksandr Karpenko committed Feb 3, 2016
1 parent 03ec736 commit 7750415
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
4 changes: 1 addition & 3 deletions app/code/Magento/Customer/Controller/Address/FormPost.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,12 +146,10 @@ protected function getExistingAddressData()
*/
protected function updateRegionData(&$attributeValues)
{
if ($this->helperData->isRegionRequired($attributeValues['country_id'])) {
if (!empty($attributeValues['region_id'])) {
$newRegion = $this->regionFactory->create()->load($attributeValues['region_id']);
$attributeValues['region_code'] = $newRegion->getCode();
$attributeValues['region'] = $newRegion->getDefaultName();
} else {
$attributeValues['region_id'] = null;
}

$regionData = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,13 +287,20 @@ private function _validate(CustomerAddressModel $customerAddressModel)
$exception->addError(__(InputException::REQUIRED_FIELD, ['fieldName' => 'countryId']));
}

if ($customerAddressModel->getCountryModel()->getRegionCollection()->getSize()
&& !\Zend_Validate::is($customerAddressModel->getRegionId(), 'NotEmpty')
&& $this->directoryData->isRegionRequired($customerAddressModel->getCountryId())
) {
$exception->addError(__(InputException::REQUIRED_FIELD, ['fieldName' => 'regionId']));
if ($this->directoryData->isRegionRequired($customerAddressModel->getCountryId())) {
$regionCollection = $customerAddressModel->getCountryModel()->getRegionCollection();
if (!$regionCollection->count() && empty($attributeValues['region'])) {
$exception->addError(__(InputException::REQUIRED_FIELD, ['fieldName' => 'region']));
} elseif (
$regionCollection->count()
&& !in_array(
$customerAddressModel->getRegionId(),
array_column($regionCollection->getData(), 'region_id')
)
) {
$exception->addError(__(InputException::REQUIRED_FIELD, ['fieldName' => 'regionId']));
}
}

return $exception;
}
}

0 comments on commit 7750415

Please sign in to comment.