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


PHP Session::setCustomerFormData方法代码示例

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


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

示例1: execute

 /**
  * Change customer email or password action
  *
  * @return \Magento\Framework\Controller\Result\Redirect
  */
 public function execute()
 {
     /** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */
     $resultRedirect = $this->resultRedirectFactory->create();
     if (!$this->formKeyValidator->validate($this->getRequest())) {
         return $resultRedirect->setPath('*/*/edit');
     }
     if ($this->getRequest()->isPost()) {
         $currentCustomerDataObject = $this->getCurrentCustomerDataObject();
         $customerCandidateDataObject = $this->populateNewCustomerDataObject($this->_request, $currentCustomerDataObject);
         try {
             // whether a customer enabled change email option
             $this->changeEmail($currentCustomerDataObject);
             // whether a customer enabled change password option
             $isPasswordChanged = $this->changePassword($currentCustomerDataObject);
             $this->customerRepository->save($customerCandidateDataObject);
             $this->getEmailNotification()->sendNotificationEmailsIfRequired($currentCustomerDataObject, $customerCandidateDataObject, $isPasswordChanged);
             $this->dispatchSuccessEvent($customerCandidateDataObject);
             $this->messageManager->addSuccess(__('You saved the account information.'));
             return $resultRedirect->setPath('customer/account');
         } catch (InvalidEmailOrPasswordException $e) {
             $this->messageManager->addError($e->getMessage());
         } catch (UserLockedException $e) {
             $this->session->logout();
             $this->session->start();
             $this->messageManager->addError($e->getMessage());
             return $resultRedirect->setPath('customer/account/login');
         } catch (InputException $e) {
             $this->messageManager->addError($e->getMessage());
             foreach ($e->getErrors() as $error) {
                 $this->messageManager->addError($error->getMessage());
             }
         } catch (\Magento\Framework\Exception\LocalizedException $e) {
             $this->messageManager->addError($e->getMessage());
         } catch (\Exception $e) {
             $this->messageManager->addException($e, __('We can\'t save the customer.'));
         }
         $this->session->setCustomerFormData($this->getRequest()->getPostValue());
         return $resultRedirect->setPath('*/*/edit');
     }
     return $resultRedirect->setPath('*/*/edit');
 }
开发者ID:BlackIkeEagle,项目名称:magento2-continuousphp,代码行数:47,代码来源:EditPost.php

示例2: executeInternal

 /**
  * Change customer password action
  *
  * @return \Magento\Framework\Controller\Result\Redirect
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  */
 public function executeInternal()
 {
     /** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */
     $resultRedirect = $this->resultRedirectFactory->create();
     if (!$this->formKeyValidator->validate($this->getRequest())) {
         return $resultRedirect->setPath('*/*/edit');
     }
     if ($this->getRequest()->isPost()) {
         $customerId = $this->session->getCustomerId();
         $currentCustomer = $this->customerRepository->getById($customerId);
         // Prepare new customer data
         $customer = $this->customerExtractor->extract('customer_account_edit', $this->_request);
         $customer->setId($customerId);
         if ($customer->getAddresses() == null) {
             $customer->setAddresses($currentCustomer->getAddresses());
         }
         // Change customer password
         if ($this->getRequest()->getParam('change_password')) {
             $this->changeCustomerPassword($currentCustomer->getEmail());
         }
         try {
             $this->customerRepository->save($customer);
         } catch (AuthenticationException $e) {
             $this->messageManager->addError($e->getMessage());
         } catch (InputException $e) {
             $this->messageManager->addException($e, __('Invalid input'));
         } catch (\Exception $e) {
             $message = __('We can\'t save the customer.') . $e->getMessage() . '<pre>' . $e->getTraceAsString() . '</pre>';
             $this->messageManager->addException($e, $message);
         }
         if ($this->messageManager->getMessages()->getCount() > 0) {
             $this->session->setCustomerFormData($this->getRequest()->getPostValue());
             return $resultRedirect->setPath('*/*/edit');
         }
         $this->messageManager->addSuccess(__('You saved the account information.'));
         return $resultRedirect->setPath('customer/account');
     }
     return $resultRedirect->setPath('*/*/edit');
 }
开发者ID:nblair,项目名称:magescotch,代码行数:45,代码来源:EditPost.php

示例3: 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\Model\Session::setCustomerFormData方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。