Skip to content

Commit

Permalink
Merge remote-tracking branch 'tango/MAGETWO-99451' into PR-05
Browse files Browse the repository at this point in the history
  • Loading branch information
dhorytskyi committed May 6, 2019
2 parents f270f29 + 149d8eb commit 4109cdb
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ if ($block->getIsShipping()):
require(["Magento_Sales/order/create/form"], function(){

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

});
</script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,30 @@ public function toNestedArray(
}
$dataObjectArray = $this->dataObjectProcessor->buildOutputDataArray($dataObject, $dataObjectType);
//process custom attributes if present
$dataObjectArray = $this->processCustomAttributes($dataObjectArray, $skipAttributes);

if (!empty($dataObjectArray[ExtensibleDataInterface::EXTENSION_ATTRIBUTES_KEY])) {
/** @var array $extensionAttributes */
$extensionAttributes = $dataObjectArray[ExtensibleDataInterface::EXTENSION_ATTRIBUTES_KEY];
unset($dataObjectArray[ExtensibleDataInterface::EXTENSION_ATTRIBUTES_KEY]);
foreach ($extensionAttributes as $attributeKey => $attributeValue) {
if (!in_array($attributeKey, $skipAttributes)) {
$dataObjectArray[$attributeKey] = $attributeValue;
}
}
}
return $dataObjectArray;
}

/**
* Recursive process array to process customer attributes
*
* @param array $dataObjectArray
* @param array $skipAttributes
* @return array
*/
private function processCustomAttributes(array $dataObjectArray, array $skipAttributes): array
{
if (!empty($dataObjectArray[AbstractExtensibleObject::CUSTOM_ATTRIBUTES_KEY])) {
/** @var AttributeValue[] $customAttributes */
$customAttributes = $dataObjectArray[AbstractExtensibleObject::CUSTOM_ATTRIBUTES_KEY];
Expand All @@ -56,14 +80,9 @@ public function toNestedArray(
}
}
}
if (!empty($dataObjectArray[ExtensibleDataInterface::EXTENSION_ATTRIBUTES_KEY])) {
/** @var array $extensionAttributes */
$extensionAttributes = $dataObjectArray[ExtensibleDataInterface::EXTENSION_ATTRIBUTES_KEY];
unset($dataObjectArray[ExtensibleDataInterface::EXTENSION_ATTRIBUTES_KEY]);
foreach ($extensionAttributes as $attributeKey => $attributeValue) {
if (!in_array($attributeKey, $skipAttributes)) {
$dataObjectArray[$attributeKey] = $attributeValue;
}
foreach ($dataObjectArray as $key => $value) {
if (is_array($value)) {
$dataObjectArray[$key] = $this->processCustomAttributes($value, $skipAttributes);
}
}
return $dataObjectArray;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,17 @@ public function testToNestedArrayCustom()
AttributeValue::VALUE => 'custom_attribute_value_skip',
],
],
'test' => [
0 => [
'3rd_attribute_key' => '3rd_attribute_value',
AbstractExtensibleObject::CUSTOM_ATTRIBUTES_KEY => [
[
AttributeValue::ATTRIBUTE_CODE => 'another_custom_attribute_code',
AttributeValue::VALUE => 'another_custom_attribute_value',
]
]
]
]
];

$resultArray = [
Expand All @@ -92,6 +103,12 @@ public function testToNestedArrayCustom()
'custom_attribute_value_multi_1',
'custom_attribute_value_multi_2',
],
'test' => [
0 => [
'3rd_attribute_key' => '3rd_attribute_value',
'another_custom_attribute_code' => 'another_custom_attribute_value',
]
]
];

$this->processor->expects($this->any())
Expand Down

0 comments on commit 4109cdb

Please sign in to comment.