/** * @param string $formCode * @param RequestInterface $request * @return \Magento\Customer\Service\V1\Data\Customer */ public function extract($formCode, RequestInterface $request) { $customerForm = $this->formFactory->create('customer', $formCode); $allowedAttributes = $customerForm->getAllowedAttributes(); $isGroupIdEmpty = true; $customerData = array(); foreach ($allowedAttributes as $attribute) { // confirmation in request param is the repeated password, not a confirmation code. if ($attribute === 'confirmation') { continue; } $attributeCode = $attribute->getAttributeCode(); if ($attributeCode == 'group_id') { $isGroupIdEmpty = false; } $customerData[$attributeCode] = $request->getParam($attributeCode); } $this->customerBuilder->populateWithArray($customerData); $store = $this->storeManager->getStore(); if ($isGroupIdEmpty) { $this->customerBuilder->setGroupId($this->groupService->getDefaultGroup($store->getId())->getId()); } $this->customerBuilder->setWebsiteId($store->getWebsiteId()); $this->customerBuilder->setStoreId($store->getId()); return $this->customerBuilder->create(); }
/** * Sample customer data * * @return CustomerData */ private function getSampleCustomerEntity() { $email = '*****@*****.**'; $storeId = 1; $firstname = 'Tester'; $lastname = 'McTest'; $groupId = 1; $this->_customerBuilder->setStoreId($storeId)->setEmail($email)->setFirstname($firstname)->setLastname($lastname)->setGroupId($groupId); return $this->_customerBuilder->create(); }
/** * @magentoDbIsolation enabled */ public function testCreateCustomerNewThenUpdateFirstName() { $email = '*****@*****.**'; $storeId = 1; $firstname = 'Tester'; $lastname = 'McTest'; $groupId = 1; $this->_customerBuilder->setStoreId($storeId)->setEmail($email)->setFirstname($firstname)->setLastname($lastname)->setGroupId($groupId); $newCustomerEntity = $this->_customerBuilder->create(); $customerDetails = $this->_customerDetailsBuilder->setCustomer($newCustomerEntity)->create(); $customer = $this->_customerAccountService->createCustomer($customerDetails, 'aPassword'); $this->_customerBuilder->populate($customer); $this->_customerBuilder->setFirstname('Tested'); $customerDetails = $this->_customerDetailsBuilder->setCustomer($this->_customerBuilder->create())->create(); $this->_customerAccountService->updateCustomer($customerDetails); $customer = $this->_customerAccountService->getCustomer($customer->getId()); $this->assertEquals('Tested', $customer->getFirstname()); $this->assertEquals($lastname, $customer->getLastname()); }