当前位置: 首页>>代码示例>>PHP>>正文


PHP AccountManagementInterface::createAccount方法代码示例

本文整理汇总了PHP中Magento\Customer\Api\AccountManagementInterface::createAccount方法的典型用法代码示例。如果您正苦于以下问题:PHP AccountManagementInterface::createAccount方法的具体用法?PHP AccountManagementInterface::createAccount怎么用?PHP AccountManagementInterface::createAccount使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Magento\Customer\Api\AccountManagementInterface的用法示例。


在下文中一共展示了AccountManagementInterface::createAccount方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: create

 /**
  * {@inheritdoc}
  */
 public function create($orderId)
 {
     $order = $this->orderRepository->get($orderId);
     if ($order->getCustomerId()) {
         throw new AlreadyExistsException(__("This order already has associated customer account"));
     }
     $customerData = $this->objectCopyService->copyFieldsetToTarget('order_address', 'to_customer', $order->getBillingAddress(), []);
     $addresses = $order->getAddresses();
     foreach ($addresses as $address) {
         $addressData = $this->objectCopyService->copyFieldsetToTarget('order_address', 'to_customer_address', $address, []);
         /** @var \Magento\Customer\Api\Data\AddressInterface $customerAddress */
         $customerAddress = $this->addressFactory->create(['data' => $addressData]);
         if (is_string($address->getRegion())) {
             /** @var \Magento\Customer\Api\Data\RegionInterface $region */
             $region = $this->regionFactory->create();
             $region->setRegion($address->getRegion());
             $region->setRegionCode($address->getRegionCode());
             $region->setRegionId($address->getRegionId());
             $customerAddress->setRegion($region);
         }
         $customerData['addresses'][] = $customerAddress;
     }
     /** @var \Magento\Customer\Api\Data\CustomerInterface $customer */
     $customer = $this->customerFactory->create(['data' => $customerData]);
     $account = $this->accountManagement->createAccount($customer);
     $order->setCustomerId($account->getId());
     $this->orderRepository->save($order);
     return $account;
 }
开发者ID:nja78,项目名称:magento2,代码行数:32,代码来源:Management.php

示例2: testCustomerCreatedNotSubscribed

 /**
  * @magentoAppArea adminhtml
  * @magentoDbIsolation enabled
  */
 public function testCustomerCreatedNotSubscribed()
 {
     $this->verifySubscriptionNotExist('customer@example.com');
     $objectManager = Bootstrap::getObjectManager();
     /** @var \Magento\Customer\Api\Data\CustomerInterfaceFactory $customerFactory */
     $customerFactory = $objectManager->get('Magento\\Customer\\Api\\Data\\CustomerInterfaceFactory');
     $customerDataObject = $customerFactory->create()->setFirstname('Firstname')->setLastname('Lastname')->setEmail('customer@example.com');
     $this->accountManagement->createAccount($customerDataObject);
     $this->verifySubscriptionNotExist('customer@example.com');
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:14,代码来源:PluginTest.php

示例3: run

 /**
  * {@inheritdoc}
  */
 public function run()
 {
     $this->logger->log('Installing customers:');
     foreach ($this->fixtures as $file) {
         /** @var \Magento\SampleData\Helper\Csv\Reader $csvReader */
         $fileName = $this->fixtureHelper->getPath($file);
         $csvReader = $this->csvReaderFactory->create(['fileName' => $fileName, 'mode' => 'r']);
         foreach ($csvReader as $row) {
             // Collect customer profile and addresses data
             $customerData['profile'] = $this->convertRowData($row, $this->getDefaultCustomerProfile());
             if (!$this->accountManagement->isEmailAvailable($customerData['profile']['email'])) {
                 continue;
             }
             $customerData['address'] = $this->convertRowData($row, $this->getDefaultCustomerAddress());
             $customerData['address']['region_id'] = $this->getRegionId($customerData['address']);
             $address = $customerData['address'];
             $regionData = [RegionInterface::REGION_ID => $address['region_id'], RegionInterface::REGION => !empty($address['region']) ? $address['region'] : null, RegionInterface::REGION_CODE => !empty($address['region_code']) ? $address['region_code'] : null];
             $region = $this->regionFactory->create();
             $this->dataObjectHelper->populateWithArray($region, $regionData, '\\Magento\\Customer\\Api\\Data\\RegionInterface');
             $addresses = $this->addressFactory->create();
             unset($customerData['address']['region']);
             $this->dataObjectHelper->populateWithArray($addresses, $customerData['address'], '\\Magento\\Customer\\Api\\Data\\AddressInterface');
             $addresses->setRegion($region)->setIsDefaultBilling(true)->setIsDefaultShipping(true);
             $customer = $this->customerFactory->create();
             $this->dataObjectHelper->populateWithArray($customer, $customerData['profile'], '\\Magento\\Customer\\Api\\Data\\CustomerInterface');
             $customer->setAddresses([$addresses]);
             $this->accountManagement->createAccount($customer, $row['password']);
             $this->logger->logInline('.');
         }
     }
 }
开发者ID:vinai-drive-by-commits,项目名称:magento2-sample-data,代码行数:34,代码来源:Customer.php

示例4: createCustomer

 public function createCustomer(\BelVG\FacebookFree\Model\Customer $customerFb)
 {
     $this->_request->setParams($customerFb->prepareData());
     $customer = $this->customerExtractor->extract('customer_account_create', $this->_request);
     $customer->setAddresses(null);
     $customer = $this->accountManagement->createAccount($customer, $customerFb->generatePassword(), '');
     $this->_eventManager->dispatch('customer_register_success', ['account_controller' => $this, 'customer' => $customer]);
     $this->getSession()->setCustomerDataAsLoggedIn($customer);
     $this->messageManager->addSuccess($this->getSuccessMessage());
     return $customer;
 }
开发者ID:wclabhinav,项目名称:Magento2,代码行数:11,代码来源:Index.php

示例5: testCreateNewCustomerFromClone

 /**
  * @magentoAppArea frontend
  * @magentoDataFixture Magento/Customer/_files/customer.php
  */
 public function testCreateNewCustomerFromClone()
 {
     $email = 'savecustomer@example.com';
     $firstName = 'Firstsave';
     $lastname = 'Lastsave';
     $existingCustId = 1;
     $existingCustomer = $this->customerRepository->getById($existingCustId);
     $customerEntity = $this->customerFactory->create();
     $this->dataObjectHelper->mergeDataObjects('\\Magento\\Customer\\Api\\Data\\CustomerInterface', $customerEntity, $existingCustomer);
     $customerEntity->setEmail($email)->setFirstname($firstName)->setLastname($lastname)->setId(null);
     $customer = $this->accountManagement->createAccount($customerEntity, 'aPassword');
     $this->assertNotEmpty($customer->getId());
     $this->assertEquals($email, $customer->getEmail());
     $this->assertEquals($firstName, $customer->getFirstname());
     $this->assertEquals($lastname, $customer->getLastname());
     $this->accountManagement->authenticate($customer->getEmail(), 'aPassword', true);
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:21,代码来源:AccountManagementTest.php

示例6: createOrUpdateAndLogin

 /**
  * Create or update user by using data from facebook and login to store
  *
  * @param GraphUser   $facebookUser
  * @param AccessToken $accessToken
  *
  * @return CustomerInterface
  */
 private function createOrUpdateAndLogin(GraphUser $facebookUser, AccessToken $accessToken)
 {
     if (!$this->customer->getId()) {
         $this->customer->setEmail($facebookUser->getEmail());
         $this->customer->setFirstname($facebookUser->getFirstName());
         $this->customer->setLastname($facebookUser->getLastName());
         $this->customer->setMiddlename($facebookUser->getMiddleName());
         $this->customer->setGender((int) ($facebookUser->getGender() == 'male'));
     }
     $this->customer->setCustomAttribute('sf_id', $facebookUser->getId());
     $this->customer->setCustomAttribute('sf_access_token', serialize($accessToken));
     if ($this->customer->getId()) {
         $customer = $this->customerRepository->save($this->customer);
     } else {
         $customer = $this->accountManagement->createAccount($this->customer);
     }
     $this->login($customer->getId());
     return $customer;
 }
开发者ID:Viktor-V,项目名称:Facebook-Login,代码行数:27,代码来源:Index.php

示例7: execute

 /**
  * Create customer account action
  *
  * @return void
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  */
 public function execute()
 {
     /** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */
     $resultRedirect = $this->resultRedirectFactory->create();
     if ($this->session->isLoggedIn() || !$this->registration->isAllowed()) {
         $resultRedirect->setPath('*/*/');
         return $resultRedirect;
     }
     if (!$this->getRequest()->isPost()) {
         $url = $this->urlModel->getUrl('*/*/create', ['_secure' => true]);
         $resultRedirect->setUrl($this->_redirect->error($url));
         return $resultRedirect;
     }
     $this->session->regenerateId();
     try {
         $address = $this->extractAddress();
         $addresses = $address === null ? [] : [$address];
         $customer = $this->customerExtractor->extract('customer_account_create', $this->_request);
         $customer->setAddresses($addresses);
         $password = $this->getRequest()->getParam('password');
         $confirmation = $this->getRequest()->getParam('password_confirmation');
         $redirectUrl = $this->session->getBeforeAuthUrl();
         $this->checkPasswordConfirmation($password, $confirmation);
         $customer = $this->accountManagement->createAccount($customer, $password, $redirectUrl);
         if ($this->getRequest()->getParam('is_subscribed', false)) {
             $this->subscriberFactory->create()->subscribeCustomerById($customer->getId());
         }
         $this->_eventManager->dispatch('customer_register_success', ['account_controller' => $this, 'customer' => $customer]);
         $confirmationStatus = $this->accountManagement->getConfirmationStatus($customer->getId());
         if ($confirmationStatus === AccountManagementInterface::ACCOUNT_CONFIRMATION_REQUIRED) {
             $email = $this->customerUrl->getEmailConfirmationUrl($customer->getEmail());
             // @codingStandardsIgnoreStart
             $this->messageManager->addSuccess(__('You must confirm your account. Please check your email for the confirmation link or <a href="%1">click here</a> for a new link.', $email));
             // @codingStandardsIgnoreEnd
             $url = $this->urlModel->getUrl('*/*/index', ['_secure' => true]);
             $resultRedirect->setUrl($this->_redirect->success($url));
         } else {
             $this->session->setCustomerDataAsLoggedIn($customer);
             $this->messageManager->addSuccess($this->getSuccessMessage());
             $resultRedirect = $this->accountRedirect->getRedirect();
         }
         return $resultRedirect;
     } catch (StateException $e) {
         $url = $this->urlModel->getUrl('customer/account/forgotpassword');
         // @codingStandardsIgnoreStart
         $message = __('There is already an account with this email address. If you are sure that it is your email address, <a href="%1">click here</a> to get your password and access your account.', $url);
         // @codingStandardsIgnoreEnd
         $this->messageManager->addError($message);
     } catch (InputException $e) {
         $this->messageManager->addError($this->escaper->escapeHtml($e->getMessage()));
         foreach ($e->getErrors() as $error) {
             $this->messageManager->addError($this->escaper->escapeHtml($error->getMessage()));
         }
     } catch (\Exception $e) {
         $this->messageManager->addException($e, __('We can\'t save the customer.'));
     }
     $this->session->setCustomerFormData($this->getRequest()->getPostValue());
     $defaultUrl = $this->urlModel->getUrl('*/*/create', ['_secure' => true]);
     $resultRedirect->setUrl($this->_redirect->error($defaultUrl));
     return $resultRedirect;
 }
开发者ID:whoople,项目名称:magento2-testing,代码行数:67,代码来源:CreatePost.php


注:本文中的Magento\Customer\Api\AccountManagementInterface::createAccount方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。