Skip to content

Commit 8991de3

Browse files
committed
MAGETWO-60248: Billing Address and Default Shipping Address checkboxes on Customer page are saved incorrectly
1 parent 2afafac commit 8991de3

File tree

2 files changed

+37
-93
lines changed
  • app/code/Magento/Customer

2 files changed

+37
-93
lines changed

app/code/Magento/Customer/Controller/Adminhtml/Index/Save.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@
1313
use Magento\Customer\Model\Metadata\Form;
1414
use Magento\Framework\Exception\LocalizedException;
1515

16-
/**
17-
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
18-
*/
16+
1917
class Save extends \Magento\Customer\Controller\Adminhtml\Index
2018
{
2119
/**
@@ -81,6 +79,7 @@ protected function _extractData(
8179
) {
8280
$metadataForm = $metadataForm ? $metadataForm : $this->getMetadataForm($entityType, $formCode, $scope);
8381
$formData = $metadataForm->extractData($request, $scope);
82+
$formData = $metadataForm->compactData($formData);
8483

8584
// Initialize additional attributes
8685
/** @var \Magento\Framework\DataObject $object */
@@ -90,11 +89,6 @@ protected function _extractData(
9089
$formData[$attributeCode] = isset($requestData[$attributeCode]) ? $requestData[$attributeCode] : false;
9190
}
9291

93-
$result = $metadataForm->compactData($formData);
94-
95-
// Re-initialize additional attributes
96-
$formData = array_replace($formData, $result);
97-
9892
// Unset unused attributes
9993
$formAttributes = $metadataForm->getAttributes();
10094
foreach ($formAttributes as $attribute) {

app/code/Magento/Customer/Test/Unit/Controller/Adminhtml/Index/SaveTest.php

Lines changed: 35 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -302,33 +302,30 @@ public function testExecuteWithExistentCustomer()
302302
],
303303
'subscription' => $subscription,
304304
];
305-
$filteredData = [
305+
$extractedData = [
306306
'entity_id' => $customerId,
307307
'code' => 'value',
308308
'coolness' => false,
309309
'disable_auto_group_change' => 'false',
310310
];
311-
$dataToCompact = [
311+
$compactedData = [
312312
'entity_id' => $customerId,
313313
'code' => 'value',
314314
'coolness' => false,
315315
'disable_auto_group_change' => 'false',
316-
CustomerInterface::DEFAULT_BILLING => false,
317-
CustomerInterface::DEFAULT_SHIPPING => false,
318-
'confirmation' => false,
319-
'sendemail_store_id' => false,
320-
'extension_attributes' => false,
316+
CustomerInterface::DEFAULT_BILLING => 2,
317+
CustomerInterface::DEFAULT_SHIPPING => 2
321318
];
322-
$addressFilteredData = [
319+
$addressExtractedData = [
323320
'entity_id' => $addressId,
324-
'default_billing' => 'true',
325-
'default_shipping' => 'true',
321+
/* 'default_billing' => 'true',
322+
'default_shipping' => 'true',*/
326323
'code' => 'value',
327324
'coolness' => false,
328325
'region' => 'region',
329326
'region_id' => 'region_id',
330327
];
331-
$addressDataToCompact = [
328+
$addressCompactedData = [
332329
'entity_id' => $addressId,
333330
'default_billing' => 'true',
334331
'default_shipping' => 'true',
@@ -428,11 +425,11 @@ public function testExecuteWithExistentCustomer()
428425
$customerFormMock->expects($this->once())
429426
->method('extractData')
430427
->with($this->requestMock, 'customer')
431-
->willReturn($filteredData);
428+
->willReturn($extractedData);
432429
$customerFormMock->expects($this->once())
433430
->method('compactData')
434-
->with($dataToCompact)
435-
->willReturn($filteredData);
431+
->with($extractedData)
432+
->willReturn($compactedData);
436433
$customerFormMock->expects($this->once())
437434
->method('getAttributes')
438435
->willReturn($attributes);
@@ -443,11 +440,11 @@ public function testExecuteWithExistentCustomer()
443440
$customerAddressFormMock->expects($this->once())
444441
->method('extractData')
445442
->with($this->requestMock, 'address/' . $addressId)
446-
->willReturn($addressFilteredData);
443+
->willReturn($addressExtractedData);
447444
$customerAddressFormMock->expects($this->once())
448445
->method('compactData')
449-
->with($addressDataToCompact)
450-
->willReturn($addressFilteredData);
446+
->with($addressExtractedData)
447+
->willReturn($addressCompactedData);
451448
$customerAddressFormMock->expects($this->once())
452449
->method('getAttributes')
453450
->willReturn($attributes);
@@ -635,33 +632,13 @@ public function testExecuteWithNewCustomer()
635632
],
636633
'subscription' => $subscription,
637634
];
638-
$filteredData = [
635+
$extractedData = [
639636
'coolness' => false,
640637
'disable_auto_group_change' => 'false',
641638
];
642-
$dataToCompact = [
643-
'coolness' => false,
644-
'disable_auto_group_change' => 'false',
645-
CustomerInterface::DEFAULT_BILLING => false,
646-
CustomerInterface::DEFAULT_SHIPPING => false,
647-
'confirmation' => false,
648-
'sendemail_store_id' => false,
649-
'extension_attributes' => false,
650-
];
651-
$addressFilteredData = [
639+
$addressExtractedData = [
652640
'entity_id' => $addressId,
653-
'default_billing' => 'false',
654-
'default_shipping' => 'false',
655-
'code' => 'value',
656-
'coolness' => false,
657-
'region' => 'region',
658-
'region_id' => 'region_id',
659-
];
660-
$addressDataToCompact = [
661-
'entity_id' => $addressId,
662-
'default_billing' => 'false',
663-
'default_shipping' => 'false',
664-
'code' => 'value',
641+
'code' => 'value',
665642
'coolness' => false,
666643
'region' => 'region',
667644
'region_id' => 'region_id',
@@ -739,11 +716,11 @@ public function testExecuteWithNewCustomer()
739716
$customerFormMock->expects($this->once())
740717
->method('extractData')
741718
->with($this->requestMock, 'customer')
742-
->willReturn($filteredData);
719+
->willReturn($extractedData);
743720
$customerFormMock->expects($this->once())
744721
->method('compactData')
745-
->with($dataToCompact)
746-
->willReturn($filteredData);
722+
->with($extractedData)
723+
->willReturn($extractedData);
747724
$customerFormMock->expects($this->once())
748725
->method('getAttributes')
749726
->willReturn($attributes);
@@ -754,11 +731,11 @@ public function testExecuteWithNewCustomer()
754731
$customerAddressFormMock->expects($this->once())
755732
->method('extractData')
756733
->with($this->requestMock, 'address/' . $addressId)
757-
->willReturn($addressFilteredData);
734+
->willReturn($addressExtractedData);
758735
$customerAddressFormMock->expects($this->once())
759736
->method('compactData')
760-
->with($addressDataToCompact)
761-
->willReturn($addressFilteredData);
737+
->with($addressExtractedData)
738+
->willReturn($addressExtractedData);
762739
$customerAddressFormMock->expects($this->once())
763740
->method('getAttributes')
764741
->willReturn($attributes);
@@ -912,19 +889,10 @@ public function testExecuteWithNewCustomerAndValidationException()
912889
],
913890
'subscription' => $subscription,
914891
];
915-
$filteredData = [
892+
$extractedData = [
916893
'coolness' => false,
917894
'disable_auto_group_change' => 'false',
918895
];
919-
$dataToCompact = [
920-
'coolness' => false,
921-
'disable_auto_group_change' => 'false',
922-
CustomerInterface::DEFAULT_BILLING => false,
923-
CustomerInterface::DEFAULT_SHIPPING => false,
924-
'confirmation' => false,
925-
'sendemail_store_id' => false,
926-
'extension_attributes' => false,
927-
];
928896

929897
/** @var AttributeMetadataInterface|\PHPUnit_Framework_MockObject_MockObject $customerFormMock */
930898
$attributeMock = $this->getMockBuilder('Magento\Customer\Api\Data\AttributeMetadataInterface')
@@ -973,11 +941,11 @@ public function testExecuteWithNewCustomerAndValidationException()
973941
$customerFormMock->expects($this->once())
974942
->method('extractData')
975943
->with($this->requestMock, 'customer')
976-
->willReturn($filteredData);
944+
->willReturn($extractedData);
977945
$customerFormMock->expects($this->once())
978946
->method('compactData')
979-
->with($dataToCompact)
980-
->willReturn($filteredData);
947+
->with($extractedData)
948+
->willReturn($extractedData);
981949
$customerFormMock->expects($this->once())
982950
->method('getAttributes')
983951
->willReturn($attributes);
@@ -1064,18 +1032,9 @@ public function testExecuteWithNewCustomerAndLocalizedException()
10641032
],
10651033
'subscription' => $subscription,
10661034
];
1067-
$filteredData = [
1068-
'coolness' => false,
1069-
'disable_auto_group_change' => 'false',
1070-
];
1071-
$dataToCompact = [
1035+
$extractedData = [
10721036
'coolness' => false,
10731037
'disable_auto_group_change' => 'false',
1074-
CustomerInterface::DEFAULT_BILLING => false,
1075-
CustomerInterface::DEFAULT_SHIPPING => false,
1076-
'confirmation' => false,
1077-
'sendemail_store_id' => false,
1078-
'extension_attributes' => false,
10791038
];
10801039

10811040
/** @var AttributeMetadataInterface|\PHPUnit_Framework_MockObject_MockObject $customerFormMock */
@@ -1126,11 +1085,11 @@ public function testExecuteWithNewCustomerAndLocalizedException()
11261085
$customerFormMock->expects($this->once())
11271086
->method('extractData')
11281087
->with($this->requestMock, 'customer')
1129-
->willReturn($filteredData);
1088+
->willReturn($extractedData);
11301089
$customerFormMock->expects($this->once())
11311090
->method('compactData')
1132-
->with($dataToCompact)
1133-
->willReturn($filteredData);
1091+
->with($extractedData)
1092+
->willReturn($extractedData);
11341093
$customerFormMock->expects($this->once())
11351094
->method('getAttributes')
11361095
->willReturn($attributes);
@@ -1216,19 +1175,10 @@ public function testExecuteWithNewCustomerAndException()
12161175
],
12171176
'subscription' => $subscription,
12181177
];
1219-
$filteredData = [
1178+
$extractedData = [
12201179
'coolness' => false,
12211180
'disable_auto_group_change' => 'false',
12221181
];
1223-
$dataToCompact = [
1224-
'coolness' => false,
1225-
'disable_auto_group_change' => 'false',
1226-
CustomerInterface::DEFAULT_BILLING => false,
1227-
CustomerInterface::DEFAULT_SHIPPING => false,
1228-
'confirmation' => false,
1229-
'sendemail_store_id' => false,
1230-
'extension_attributes' => false,
1231-
];
12321182

12331183
/** @var AttributeMetadataInterface|\PHPUnit_Framework_MockObject_MockObject $customerFormMock */
12341184
$attributeMock = $this->getMockBuilder('Magento\Customer\Api\Data\AttributeMetadataInterface')
@@ -1277,11 +1227,11 @@ public function testExecuteWithNewCustomerAndException()
12771227
$customerFormMock->expects($this->once())
12781228
->method('extractData')
12791229
->with($this->requestMock, 'customer')
1280-
->willReturn($filteredData);
1230+
->willReturn($extractedData);
12811231
$customerFormMock->expects($this->once())
12821232
->method('compactData')
1283-
->with($dataToCompact)
1284-
->willReturn($filteredData);
1233+
->with($extractedData)
1234+
->willReturn($extractedData);
12851235
$customerFormMock->expects($this->once())
12861236
->method('getAttributes')
12871237
->willReturn($attributes);

0 commit comments

Comments
 (0)