/** * @magentoAppArea frontend * @magentoDataFixture Magento/Customer/_files/customer.php * @expectedException \Magento\Framework\Exception\StateException */ public function testUpdateCustomerDetailsByEmailWithException() { $customerId = 1; $customerDetails = $this->_customerAccountService->getCustomerDetails($customerId); $email = $customerDetails->getCustomer()->getEmail(); $customerData = array_merge($customerDetails->getCustomer()->__toArray(), ['firstname' => 'fname', 'id' => 1234567]); $this->_customerBuilder->populateWithArray($customerData); $this->_customerDetailsBuilder->setCustomer($this->_customerBuilder->create())->setAddresses([]); $this->_customerAccountService->updateCustomerDetailsByEmail($email, $this->_customerDetailsBuilder->create()); }
/** * Change customer password action * * @return void * @SuppressWarnings(PHPMD.CyclomaticComplexity) */ public function execute() { if (!$this->_formKeyValidator->validate($this->getRequest())) { $this->_redirect('*/*/edit'); return; } if ($this->getRequest()->isPost()) { $customerId = $this->_getSession()->getCustomerId(); $customer = $this->customerExtractor->extract('customer_account_edit', $this->_request); $this->_customerBuilder->populate($customer); $this->_customerBuilder->setId($customerId); $customer = $this->_customerBuilder->create(); if ($this->getRequest()->getParam('change_password')) { $currPass = $this->getRequest()->getPost('current_password'); $newPass = $this->getRequest()->getPost('password'); $confPass = $this->getRequest()->getPost('confirmation'); if (strlen($newPass)) { if ($newPass == $confPass) { try { $this->_customerAccountService->changePassword($customerId, $currPass, $newPass); } catch (AuthenticationException $e) { $this->messageManager->addError($e->getMessage()); } catch (\Exception $e) { $this->messageManager->addException($e, __('A problem was encountered trying to change password.')); } } else { $this->messageManager->addError(__('Confirm your new password')); } } else { $this->messageManager->addError(__('New password field cannot be empty.')); } } try { $this->_customerDetailsBuilder->setCustomer($customer); $this->_customerAccountService->updateCustomer($this->_customerDetailsBuilder->create()); } catch (AuthenticationException $e) { $this->messageManager->addError($e->getMessage()); } catch (InputException $e) { $this->messageManager->addException($e, __('Invalid input')); } catch (\Exception $e) { $this->messageManager->addException($e, __('Cannot save the customer.') . $e->getMessage() . '<pre>' . $e->getTraceAsString() . '</pre>'); } if ($this->messageManager->getMessages()->getCount() > 0) { $this->_getSession()->setCustomerFormData($this->getRequest()->getPost()); $this->_redirect('*/*/edit'); return; } $this->messageManager->addSuccess(__('The account information has been saved.')); $this->_redirect('customer/account'); return; } $this->_redirect('*/*/edit'); }
public function connectByFacebookId($facebookId, \stdClass $token, $customerId) { $customerDetailsObject = $this->_customerAccountService->getCustomerDetails($customerId); /* @var $customerDetailsObject \Magento\Customer\Service\V1\Data\CustomerDetails */ $customerDataObject = $customerDetailsObject->getCustomer(); /* @var $customerDetailsObject \Magento\Customer\Service\V1\Data\Customer */ // Merge old and new data $customerDetailsArray = array_merge($customerDataObject->__toArray(), array('custom_attributes' => array(array(\Magento\Framework\Service\Data\AttributeValue::ATTRIBUTE_CODE => 'inchoo_socialconnect_fid', \Magento\Framework\Service\Data\AttributeValue::VALUE => $facebookId), array(\Magento\Framework\Service\Data\AttributeValue::ATTRIBUTE_CODE => 'inchoo_socialconnect_ftoken', \Magento\Framework\Service\Data\AttributeValue::VALUE => serialize($token))))); // Pass result to customerBuilder $this->_customerBuilder->populateWithArray($customerDetailsArray); // Pass result to customerDetailsBuilder $this->_customerDetailsBuilder->setCustomer($this->_customerBuilder->create()); // Update customer $this->_customerAccountService->updateCustomer($customerId, $this->_customerDetailsBuilder->create()); // Set customer as logged in $this->_customerSession->setCustomerDataAsLoggedIn($customerDataObject); }