Skip to content

Commit 0ccea38

Browse files
author
Oleksandr Iegorov
committed
MAGETWO-99451: Custom customer address attribute values are empty when address is changed in admin checkout
1 parent 93a8162 commit 0ccea38

File tree

2 files changed

+26
-19
lines changed

2 files changed

+26
-19
lines changed

app/code/Magento/Sales/view/adminhtml/templates/order/create/form/address.phtml

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,6 @@
66

77
// @codingStandardsIgnoreFile
88

9-
/**
10-
* @var \Magento\Customer\Model\ResourceModel\Address\Collection $addressCollection
11-
*/
12-
$addressCollection = $block->getData('customerAddressCollection');
13-
14-
$addressArray = [];
15-
if ($block->getCustomerId()) {
16-
$addressArray = $addressCollection->setCustomerFilter([$block->getCustomerId()])->toArray();
17-
}
18-
199
/**
2010
* @var \Magento\Sales\ViewModel\Customer\AddressFormatter $customerAddressFormatter
2111
*/
@@ -32,7 +22,7 @@ if ($block->getIsShipping()):
3222
require(["Magento_Sales/order/create/form"], function(){
3323

3424
order.shippingAddressContainer = '<?= /* @escapeNotVerified */ $_fieldsContainerId ?>';
35-
order.setAddresses(<?= /* @escapeNotVerified */ $customerAddressFormatter->getAddressesJson($addressArray) ?>);
25+
order.setAddresses(<?= /* @escapeVerfied */ $block->getAddressCollectionJson() ?>);
3626

3727
});
3828
</script>

lib/internal/Magento/Framework/Api/ExtensibleDataObjectConverter.php

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,28 @@ public function toNestedArray(
4545
}
4646
$dataObjectArray = $this->dataObjectProcessor->buildOutputDataArray($dataObject, $dataObjectType);
4747
//process custom attributes if present
48+
$dataObjectArray = $this->processCustomAttributes($dataObjectArray, $skipAttributes);
49+
50+
if (!empty($dataObjectArray[ExtensibleDataInterface::EXTENSION_ATTRIBUTES_KEY])) {
51+
/** @var array $extensionAttributes */
52+
$extensionAttributes = $dataObjectArray[ExtensibleDataInterface::EXTENSION_ATTRIBUTES_KEY];
53+
unset($dataObjectArray[ExtensibleDataInterface::EXTENSION_ATTRIBUTES_KEY]);
54+
foreach ($extensionAttributes as $attributeKey => $attributeValue) {
55+
if (!in_array($attributeKey, $skipAttributes)) {
56+
$dataObjectArray[$attributeKey] = $attributeValue;
57+
}
58+
}
59+
}
60+
return $dataObjectArray;
61+
}
62+
63+
/**
64+
* @param array $dataObjectArray
65+
* @param array $skipAttributes
66+
* @return array
67+
*/
68+
private function processCustomAttributes(array $dataObjectArray, array $skipAttributes): array
69+
{
4870
if (!empty($dataObjectArray[AbstractExtensibleObject::CUSTOM_ATTRIBUTES_KEY])) {
4971
/** @var AttributeValue[] $customAttributes */
5072
$customAttributes = $dataObjectArray[AbstractExtensibleObject::CUSTOM_ATTRIBUTES_KEY];
@@ -56,14 +78,9 @@ public function toNestedArray(
5678
}
5779
}
5880
}
59-
if (!empty($dataObjectArray[ExtensibleDataInterface::EXTENSION_ATTRIBUTES_KEY])) {
60-
/** @var array $extensionAttributes */
61-
$extensionAttributes = $dataObjectArray[ExtensibleDataInterface::EXTENSION_ATTRIBUTES_KEY];
62-
unset($dataObjectArray[ExtensibleDataInterface::EXTENSION_ATTRIBUTES_KEY]);
63-
foreach ($extensionAttributes as $attributeKey => $attributeValue) {
64-
if (!in_array($attributeKey, $skipAttributes)) {
65-
$dataObjectArray[$attributeKey] = $attributeValue;
66-
}
81+
foreach ($dataObjectArray as $key => $value) {
82+
if (is_array($value)) {
83+
$dataObjectArray[$key] = $this->processCustomAttributes($value, $skipAttributes);
6784
}
6885
}
6986
return $dataObjectArray;

0 commit comments

Comments
 (0)