Skip to content

Commit a4e1c4a

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

File tree

2 files changed

+21
-23
lines changed

2 files changed

+21
-23
lines changed

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

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

12931293
return $customerForm;
@@ -1568,13 +1568,11 @@ public function setAccountData($accountData)
15681568
{
15691569
$customer = $this->getQuote()->getCustomer();
15701570
$form = $this->_createCustomerForm($customer);
1571-
$customerData = $this->customerMapper->toFlatArray($customer);
15721571

15731572
// emulate request
15741573
$request = $form->prepareRequest($accountData);
15751574
$data = $form->extractData($request);
15761575
$data = $form->restoreData($data);
1577-
$data = array_merge($customerData, array_filter($data));
15781576
$customer = $this->customerFactory->create();
15791577
$this->dataObjectHelper->populateWithArray(
15801578
$customer,
@@ -1583,6 +1581,7 @@ public function setAccountData($accountData)
15831581
$this->getQuote()->updateCustomerData($customer);
15841582
$data = [];
15851583

1584+
$customerData = $this->customerMapper->toFlatArray($customer);
15861585
foreach ($form->getAttributes() as $attribute) {
15871586
$code = sprintf('customer_%s', $attribute->getAttributeCode());
15881587
$data[$code] = isset($customerData[$attribute->getAttributeCode()])

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

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -100,14 +100,14 @@ protected function setUp()
100100
$loggerMock = $this->getMock(\Psr\Log\LoggerInterface::class);
101101
$copyMock = $this->getMock(\Magento\Framework\DataObject\Copy::class, [], [], '', false);
102102
$messageManagerMock = $this->getMock(\Magento\Framework\Message\ManagerInterface::class);
103-
$this->formFactoryMock = $this->getMock(
103+
$this->formFactoryMock = $this->getMock(
104104
\Magento\Customer\Model\Metadata\FormFactory::class,
105105
['create'],
106106
[],
107107
'',
108108
false
109109
);
110-
$this->customerFactoryMock = $this->getMock(
110+
$this->customerFactoryMock = $this->getMock(
111111
\Magento\Customer\Api\Data\CustomerInterfaceFactory::class,
112112
['create'],
113113
[],
@@ -122,56 +122,56 @@ protected function setUp()
122122
->setMethods(['create'])
123123
->getMock();
124124

125-
$this->customerMapper = $this->getMockBuilder(
125+
$this->customerMapper = $this->getMockBuilder(
126126
\Magento\Customer\Model\Customer\Mapper::class
127127
)->setMethods(['toFlatArray'])->disableOriginalConstructor()->getMock();
128128

129-
$this->quoteInitializerMock = $this->getMock(
129+
$this->quoteInitializerMock = $this->getMock(
130130
\Magento\Sales\Model\AdminOrder\Product\Quote\Initializer::class,
131131
[],
132132
[],
133133
'',
134134
false
135135
);
136-
$this->customerRepositoryMock = $this->getMockForAbstractClass(
136+
$this->customerRepositoryMock = $this->getMockForAbstractClass(
137137
\Magento\Customer\Api\CustomerRepositoryInterface::class,
138138
[],
139139
'',
140140
false
141141
);
142-
$this->addressRepositoryMock = $this->getMockForAbstractClass(
142+
$this->addressRepositoryMock = $this->getMockForAbstractClass(
143143
\Magento\Customer\Api\AddressRepositoryInterface::class,
144144
[],
145145
'',
146146
false
147147
);
148-
$this->addressFactoryMock = $this->getMock(
148+
$this->addressFactoryMock = $this->getMock(
149149
\Magento\Customer\Api\Data\AddressInterfaceFactory::class,
150150
[],
151151
[],
152152
'',
153153
false
154154
);
155-
$this->groupRepositoryMock = $this->getMockForAbstractClass(
155+
$this->groupRepositoryMock = $this->getMockForAbstractClass(
156156
\Magento\Customer\Api\GroupRepositoryInterface::class,
157157
[],
158158
'',
159159
false
160160
);
161-
$this->scopeConfigMock = $this->getMockForAbstractClass(
161+
$this->scopeConfigMock = $this->getMockForAbstractClass(
162162
\Magento\Framework\App\Config\ScopeConfigInterface::class,
163163
[],
164164
'',
165165
false
166166
);
167-
$this->emailSenderMock = $this->getMock(
167+
$this->emailSenderMock = $this->getMock(
168168
\Magento\Sales\Model\AdminOrder\EmailSender::class,
169169
[],
170170
[],
171171
'',
172172
false
173173
);
174-
$this->accountManagementMock = $this->getMockForAbstractClass(
174+
$this->accountManagementMock = $this->getMockForAbstractClass(
175175
\Magento\Customer\Api\AccountManagementInterface::class,
176176
[],
177177
'',
@@ -182,7 +182,7 @@ protected function setUp()
182182
->getMock();
183183

184184
$objectManagerHelper = new ObjectManagerHelper($this);
185-
$this->adminOrderCreate = $objectManagerHelper->getObject(
185+
$this->adminOrderCreate = $objectManagerHelper->getObject(
186186
\Magento\Sales\Model\AdminOrder\Create::class,
187187
[
188188
'objectManager' => $objectManagerMock,
@@ -219,7 +219,7 @@ public function testSetAccountData()
219219
$attributeMocks = [];
220220

221221
foreach ($attributes as $attribute) {
222-
$attributeMock = $this->getMock(
222+
$attributeMock = $this->getMock(
223223
\Magento\Customer\Api\Data\AttributeMetadataInterface::class,
224224
[],
225225
[],
@@ -232,7 +232,7 @@ public function testSetAccountData()
232232
$attributeMocks[] = $attributeMock;
233233
}
234234

235-
$customerGroupMock = $this->getMockForAbstractClass(
235+
$customerGroupMock = $this->getMockForAbstractClass(
236236
\Magento\Customer\Api\Data\GroupInterface::class,
237237
[],
238238
'',
@@ -243,9 +243,9 @@ public function testSetAccountData()
243243
);
244244
$customerGroupMock->expects($this->once())->method('getTaxClassId')->will($this->returnValue($taxClassId));
245245
$customerFormMock = $this->getMock(\Magento\Customer\Model\Metadata\Form::class, [], [], '', false);
246-
$customerFormMock->expects($this->any())->method('getAttributes')->will($this->returnValue($attributeMocks));
246+
$customerFormMock->expects($this->any())->method('getAttributes')->will($this->returnValue([$attributeMocks[1]]));
247247
$customerFormMock->expects($this->any())->method('extractData')->will($this->returnValue([]));
248-
$customerFormMock->expects($this->any())->method('restoreData')->will($this->returnValue([]));
248+
$customerFormMock->expects($this->any())->method('restoreData')->will($this->returnValue(['group_id' => 1]));
249249

250250
$customerFormMock->expects($this->any())
251251
->method('prepareRequest')
@@ -254,7 +254,7 @@ public function testSetAccountData()
254254
$customerMock = $this->getMock(\Magento\Customer\Api\Data\CustomerInterface::class, [], [], '', false);
255255
$this->customerMapper->expects($this->atLeastOnce())
256256
->method('toFlatArray')
257-
->willReturn(['email' => '[email protected]', 'group_id' => 1, 'gender' => 1]);
257+
->willReturn(['group_id' => 1]);
258258

259259

260260
$quoteMock = $this->getMock(\Magento\Quote\Model\Quote::class, [], [], '', false);
@@ -263,7 +263,6 @@ public function testSetAccountData()
263263
->method('addData')
264264
->with(
265265
[
266-
'customer_email' => $attributes[0][1],
267266
'customer_group_id' => $attributes[1][1],
268267
'customer_tax_class_id' => $taxClassId
269268
]
@@ -272,7 +271,7 @@ public function testSetAccountData()
272271
->method('populateWithArray')
273272
->with(
274273
$customerMock,
275-
['email' => '[email protected]', 'group_id' => 1, 'gender' => 1], \Magento\Customer\Api\Data\CustomerInterface::class
274+
['group_id' => 1], \Magento\Customer\Api\Data\CustomerInterface::class
276275
);
277276

278277
$this->formFactoryMock->expects($this->any())->method('create')->will($this->returnValue($customerFormMock));
@@ -283,7 +282,7 @@ public function testSetAccountData()
283282
->method('getById')
284283
->will($this->returnValue($customerGroupMock));
285284

286-
$this->adminOrderCreate->setAccountData([]);
285+
$this->adminOrderCreate->setAccountData(['group_id' => 1]);
287286
}
288287

289288
public function testUpdateQuoteItemsNotArray()

0 commit comments

Comments
 (0)