Skip to content

Commit ba948d2

Browse files
MAGETWO-57077: [GITHUB] Can't set customer group when creating a new order in the admin. #6162
1 parent 8f0e5b0 commit ba948d2

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

app/code/Magento/Sales/Model/AdminOrder/Create.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1284,7 +1284,7 @@ protected function _createCustomerForm(\Magento\Customer\Api\Data\CustomerInterf
12841284
'adminhtml_checkout',
12851285
$this->customerMapper->toFlatArray($customer),
12861286
false,
1287-
CustomerForm::DONT_IGNORE_INVISIBLE
1287+
CustomerForm::IGNORE_INVISIBLE
12881288
);
12891289

12901290
return $customerForm;
@@ -1559,13 +1559,11 @@ public function setAccountData($accountData)
15591559
{
15601560
$customer = $this->getQuote()->getCustomer();
15611561
$form = $this->_createCustomerForm($customer);
1562-
$customerData = $this->customerMapper->toFlatArray($customer);
15631562

15641563
// emulate request
15651564
$request = $form->prepareRequest($accountData);
15661565
$data = $form->extractData($request);
15671566
$data = $form->restoreData($data);
1568-
$data = array_merge($customerData, array_filter($data));
15691567
$customer = $this->customerFactory->create();
15701568
$this->dataObjectHelper->populateWithArray(
15711569
$customer,
@@ -1575,6 +1573,7 @@ public function setAccountData($accountData)
15751573
$this->getQuote()->updateCustomerData($customer);
15761574
$data = [];
15771575

1576+
$customerData = $this->customerMapper->toFlatArray($customer);
15781577
foreach ($form->getAttributes() as $attribute) {
15791578
$code = sprintf('customer_%s', $attribute->getAttributeCode());
15801579
$data[$code] = isset($customerData[$attribute->getAttributeCode()])

app/code/Magento/Sales/Test/Unit/Model/AdminOrder/CreateTest.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -243,9 +243,11 @@ public function testSetAccountData()
243243
);
244244
$customerGroupMock->expects($this->once())->method('getTaxClassId')->will($this->returnValue($taxClassId));
245245
$customerFormMock = $this->getMock('Magento\Customer\Model\Metadata\Form', [], [], '', false);
246-
$customerFormMock->expects($this->any())->method('getAttributes')->will($this->returnValue($attributeMocks));
246+
$customerFormMock->expects($this->any())
247+
->method('getAttributes')
248+
->will($this->returnValue([$attributeMocks[1]]));
247249
$customerFormMock->expects($this->any())->method('extractData')->will($this->returnValue([]));
248-
$customerFormMock->expects($this->any())->method('restoreData')->will($this->returnValue([]));
250+
$customerFormMock->expects($this->any())->method('restoreData')->will($this->returnValue(['group_id' => 1]));
249251

250252
$customerFormMock->expects($this->any())
251253
->method('prepareRequest')
@@ -254,7 +256,7 @@ public function testSetAccountData()
254256
$customerMock = $this->getMock('Magento\Customer\Api\Data\CustomerInterface', [], [], '', false);
255257
$this->customerMapper->expects($this->atLeastOnce())
256258
->method('toFlatArray')
257-
->willReturn(['email' => '[email protected]', 'group_id' => 1, 'gender' => 1]);
259+
->willReturn(['group_id' => 1]);
258260

259261

260262
$quoteMock = $this->getMock('Magento\Quote\Model\Quote', [], [], '', false);
@@ -263,7 +265,6 @@ public function testSetAccountData()
263265
->method('addData')
264266
->with(
265267
[
266-
'customer_email' => $attributes[0][1],
267268
'customer_group_id' => $attributes[1][1],
268269
'customer_tax_class_id' => $taxClassId
269270
]
@@ -272,7 +273,7 @@ public function testSetAccountData()
272273
->method('populateWithArray')
273274
->with(
274275
$customerMock,
275-
['email' => '[email protected]', 'group_id' => 1, 'gender' => 1],
276+
['group_id' => 1],
276277
'\Magento\Customer\Api\Data\CustomerInterface'
277278
);
278279

@@ -284,7 +285,7 @@ public function testSetAccountData()
284285
->method('getById')
285286
->will($this->returnValue($customerGroupMock));
286287

287-
$this->adminOrderCreate->setAccountData([]);
288+
$this->adminOrderCreate->setAccountData(['group_id' => 1]);
288289
}
289290

290291
public function testUpdateQuoteItemsNotArray()

0 commit comments

Comments
 (0)