本文整理汇总了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;
}
示例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;
}
示例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;
}