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


PHP AccountManagementInterface::validate方法代码示例

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


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

示例1: _preDispatchValidateCustomer

 /**
  * Make sure customer is valid, if logged in
  *
  * By default will add error messages and redirect to customer edit form
  *
  * @param bool $redirect - stop dispatch and redirect?
  * @param bool $addErrors - add error messages?
  * @return bool|\Magento\Framework\Controller\Result\Redirect
  */
 protected function _preDispatchValidateCustomer($redirect = true, $addErrors = true)
 {
     try {
         $customer = $this->customerRepository->getById($this->_customerSession->getCustomerId());
     } catch (NoSuchEntityException $e) {
         return true;
     }
     if (isset($customer)) {
         $validationResult = $this->accountManagement->validate($customer);
         if (!$validationResult->isValid()) {
             if ($addErrors) {
                 foreach ($validationResult->getMessages() as $error) {
                     $this->messageManager->addError($error);
                 }
             }
             if ($redirect) {
                 $this->_actionFlag->set('', self::FLAG_NO_DISPATCH, true);
                 return $this->resultRedirectFactory->create()->setPath('customer/account/edit');
             }
             return false;
         }
     }
     return true;
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:33,代码来源:Action.php

示例2: _validateCustomerData

 /**
  * Validate customer data and set some its data for further usage in quote
  *
  * Will return either true or array with error messages
  *
  * @param array $data
  * @return bool|array
  */
 protected function _validateCustomerData(array $data)
 {
     $quote = $this->getQuote();
     $isCustomerNew = !$quote->getCustomerId();
     $customer = $quote->getCustomer();
     $customerData = $this->extensibleDataObjectConverter->toFlatArray($customer, [], '\\Magento\\Customer\\Api\\Data\\CustomerInterface');
     /** @var Form $customerForm */
     $customerForm = $this->_formFactory->create(\Magento\Customer\Api\CustomerMetadataInterface::ENTITY_TYPE_CUSTOMER, 'checkout_register', $customerData, $this->_request->isAjax(), Form::IGNORE_INVISIBLE, []);
     if ($isCustomerNew) {
         $customerRequest = $customerForm->prepareRequest($data);
         $customerData = $customerForm->extractData($customerRequest);
     }
     $customerErrors = $customerForm->validateData($customerData);
     if ($customerErrors !== true) {
         return ['error' => -1, 'message' => implode(', ', $customerErrors)];
     }
     if (!$isCustomerNew) {
         return true;
     }
     $customer = $this->customerDataFactory->create();
     $this->dataObjectHelper->populateWithArray($customer, $customerData, '\\Magento\\Customer\\Api\\Data\\CustomerInterface');
     if ($quote->getCheckoutMethod() == self::METHOD_REGISTER) {
         // We always have $customerRequest here, otherwise we would have been kicked off the function several
         // lines above
         $password = $customerRequest->getParam('customer_password');
         if ($password != $customerRequest->getParam('confirm_password')) {
             return ['error' => -1, 'message' => __('Password and password confirmation are not equal.')];
         }
         $quote->setPasswordHash($this->accountManagement->getPasswordHash($password));
     } else {
         // set NOT LOGGED IN group id explicitly,
         // otherwise copyFieldsetToTarget('customer_account', 'to_quote') will fill it with default group id value
         $customer->setGroupId(GroupInterface::NOT_LOGGED_IN_ID);
     }
     //validate customer
     $result = $this->accountManagement->validate($customer);
     if (!$result->isValid()) {
         return ['error' => -1, 'message' => implode(', ', $result->getMessages())];
     }
     // copy customer/guest email to address
     $quote->getBillingAddress()->setEmail($customer->getEmail());
     // copy customer data to quote
     $this->_objectCopyService->copyFieldsetToTarget('customer_account', 'to_quote', $this->extensibleDataObjectConverter->toFlatArray($customer, [], '\\Magento\\Customer\\Api\\Data\\CustomerInterface'), $quote);
     return true;
 }
开发者ID:nja78,项目名称:magento2,代码行数:53,代码来源:Onepage.php

示例3: _validateCustomerData

 /**
  * Set and validate Customer data. Return the updated Data Object merged with the account data
  *
  * @param \Magento\Customer\Api\Data\CustomerInterface $customer
  * @return \Magento\Customer\Api\Data\CustomerInterface
  */
 protected function _validateCustomerData(\Magento\Customer\Api\Data\CustomerInterface $customer)
 {
     $form = $this->_createCustomerForm($customer);
     // emulate request
     $request = $form->prepareRequest(['order' => $this->getData()]);
     $data = $form->extractData($request, 'order/account');
     $validationResults = $this->accountManagement->validate($customer);
     if (!$validationResults->isValid()) {
         $errors = $validationResults->getMessages();
         if (is_array($errors)) {
             foreach ($errors as $error) {
                 $this->_errors[] = $error;
             }
         }
     }
     $data = $form->restoreData($data);
     foreach ($data as $key => $value) {
         if (!is_null($value)) {
             unset($data[$key]);
         }
     }
     $this->dataObjectHelper->populateWithArray($customer, $data, '\\Magento\\Customer\\Api\\Data\\CustomerInterface');
     return $customer;
 }
开发者ID:whoople,项目名称:magento2-testing,代码行数:30,代码来源:Create.php


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