本文整理汇总了PHP中Magento\Customer\Api\AccountManagementInterface::activate方法的典型用法代码示例。如果您正苦于以下问题:PHP AccountManagementInterface::activate方法的具体用法?PHP AccountManagementInterface::activate怎么用?PHP AccountManagementInterface::activate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Customer\Api\AccountManagementInterface
的用法示例。
在下文中一共展示了AccountManagementInterface::activate方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: execute
/**
* Confirm customer account by id and confirmation key
*
* @return \Magento\Framework\Controller\Result\Redirect
*/
public function execute()
{
/** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */
$resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
if ($this->_getSession()->isLoggedIn()) {
$resultRedirect->setPath('*/*/');
return $resultRedirect;
}
try {
$customerId = $this->getRequest()->getParam('id', false);
$key = $this->getRequest()->getParam('key', false);
if (empty($customerId) || empty($key)) {
throw new \Exception(__('Bad request.'));
}
// log in and send greeting email
$customerEmail = $this->customerRepository->getById($customerId)->getEmail();
$customer = $this->customerAccountManagement->activate($customerEmail, $key);
$this->_getSession()->setCustomerDataAsLoggedIn($customer);
$this->messageManager->addSuccess($this->getSuccessMessage());
$resultRedirect->setUrl($this->getSuccessRedirect());
return $resultRedirect;
} catch (StateException $e) {
$this->messageManager->addException($e, __('This confirmation key is invalid or has expired.'));
} catch (\Exception $e) {
$this->messageManager->addException($e, __('There was an error confirming the account'));
}
$url = $this->urlModel->getUrl('*/*/index', ['_secure' => true]);
return $resultRedirect->setUrl($this->_redirect->error($url));
}
示例2: testActivateCustomerAlreadyActive
/**
* @magentoDataFixture Magento/Customer/_files/inactive_customer.php
* @magentoAppArea frontend
* @expectedException \Magento\Framework\Exception\State\InvalidTransitionException
*/
public function testActivateCustomerAlreadyActive()
{
/** @var \Magento\Customer\Model\Customer $customerModel */
$customerModel = $this->objectManager->create('Magento\\Customer\\Model\\Customer');
$customerModel->load(1);
$key = $customerModel->getConfirmation();
$this->accountManagement->activate($customerModel->getEmail(), $key);
// activate it one more time to produce an exception
$this->accountManagement->activate($customerModel->getEmail(), $key);
}
示例3: execute
/**
* Confirm customer account by id and confirmation key
*
* @return \Magento\Framework\Controller\Result\Redirect
* @throws \Exception
*/
public function execute()
{
/** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */
$resultRedirect = $this->resultRedirectFactory->create();
if ($this->_getSession()->isLoggedIn()) {
$resultRedirect->setPath('*/*/');
return $resultRedirect;
}
$customerId = $this->getRequest()->getParam('id', false);
$key = $this->getRequest()->getParam('key', false);
if (empty($customerId) || empty($key)) {
throw new \Exception(__('Bad request.'));
}
// log in and send greeting email
$customerEmail = $this->customerRepository->getById($customerId)->getEmail();
$customer = $this->customerAccountManagement->activate($customerEmail, $key);
$this->_getSession()->setCustomerDataAsLoggedIn($customer);
$this->messageManager->addSuccess($this->getSuccessMessage());
$resultRedirect->setUrl($this->getSuccessRedirect());
return $resultRedirect;
}