Skip to content

Commit 63d33c5

Browse files
MAGETWO-90280: Could not create customer via API without store_id
1 parent 56eae2a commit 63d33c5

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

app/code/Magento/Customer/Model/AccountManagement.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -781,6 +781,7 @@ public function createAccountWithPasswordHash(CustomerInterface $customer, $hash
781781
if ($customer->getWebsiteId()) {
782782
$storeId = $this->storeManager->getWebsite($customer->getWebsiteId())->getDefaultStore()->getId();
783783
} else {
784+
$this->storeManager->setCurrentStore(null);
784785
$storeId = $this->storeManager->getStore()->getId();
785786
}
786787
$customer->setStoreId($storeId);

dev/tests/api-functional/testsuite/Magento/Customer/Api/AccountManagementTest.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,34 @@ public function testCreateCustomerWithErrors()
213213
}
214214
}
215215

216+
public function testCreateCustomerWithoutOptionalFields()
217+
{
218+
$serviceInfo = [
219+
'rest' => [
220+
'resourcePath' => self::RESOURCE_PATH,
221+
'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_POST, ],
222+
'soap' => [
223+
'service' => self::SERVICE_NAME,
224+
'serviceVersion' => self::SERVICE_VERSION,
225+
'operation' => self::SERVICE_NAME . 'CreateAccount',
226+
],
227+
];
228+
229+
$customerDataArray = $this->dataObjectProcessor->buildOutputDataArray(
230+
$this->customerHelper->createSampleCustomerDataObject(),
231+
\Magento\Customer\Api\Data\CustomerInterface::class
232+
);
233+
unset($customerDataArray['store_id']);
234+
unset($customerDataArray['website_id']);
235+
$requestData = ['customer' => $customerDataArray, 'password' => CustomerHelper::PASSWORD];
236+
try {
237+
$customerData = $this->_webApiCall($serviceInfo, $requestData, null, 'all');
238+
$this->assertNotNull($customerData['id']);
239+
} catch (\Exception $e) {
240+
$this->fail('Customer should be created without optional fields.');
241+
}
242+
}
243+
216244
/**
217245
* Test customer activation when it is required
218246
*

0 commit comments

Comments
 (0)