Example #1
0
 /**
  * Edit/View Existing Customer form fields
  *
  * @param \Magento\Framework\Data\Form\Element\Fieldset $fieldset
  * @return string[] Values to set on the form
  */
 protected function _addEditCustomerFormFields($fieldset)
 {
     $fieldset->getForm()->getElement('created_in')->setDisabled('disabled');
     $fieldset->getForm()->getElement('website_id')->setDisabled('disabled');
     $customerData = $this->_getCustomerDataObject();
     if ($customerData->getId() && !$this->_customerAccountService->canModify($customerData->getId())) {
         return array();
     }
     // Prepare customer confirmation control (only for existing customers)
     $confirmationStatus = $this->_customerAccountService->getConfirmationStatus($customerData->getId());
     $confirmationKey = $customerData->getConfirmation();
     if ($confirmationStatus != CustomerAccountServiceInterface::ACCOUNT_CONFIRMED) {
         $confirmationAttr = $this->_customerMetadataService->getCustomerAttributeMetadata('confirmation');
         if (!$confirmationKey) {
             $confirmationKey = $this->_getRandomConfirmationKey();
         }
         $element = $fieldset->addField('confirmation', 'select', array('name' => 'confirmation', 'label' => __($confirmationAttr->getFrontendLabel())));
         $element->setEntityAttribute($confirmationAttr);
         $element->setValues(array('' => 'Confirmed', $confirmationKey => 'Not confirmed'));
         // Prepare send welcome email checkbox if customer is not confirmed
         // no need to add it, if website ID is empty
         if ($customerData->getConfirmation() && $customerData->getWebsiteId()) {
             $fieldset->addField('sendemail', 'checkbox', array('name' => 'sendemail', 'label' => __('Send Welcome Email after Confirmation')));
             return array('sendemail' => '1');
         }
     }
     return array();
 }
Example #2
0
 /**
  * @return string
  */
 public function getIsConfirmedStatus()
 {
     $id = $this->getCustomerId();
     switch ($this->_accountService->getConfirmationStatus($id)) {
         case CustomerAccountServiceInterface::ACCOUNT_CONFIRMED:
             return __('Confirmed');
         case CustomerAccountServiceInterface::ACCOUNT_CONFIRMATION_REQUIRED:
             return __('Confirmation Required');
         case CustomerAccountServiceInterface::ACCOUNT_CONFIRMATION_NOT_REQUIRED:
             return __('Confirmation Not Required');
     }
     return __('Indeterminate');
 }
Example #3
0
 /**
  * Involve new customer to system
  *
  * @return $this
  */
 protected function _involveNewCustomer()
 {
     $customer = $this->_quote->getCustomerData();
     $confirmationStatus = $this->_customerAccountService->getConfirmationStatus($customer->getId());
     if ($confirmationStatus === CustomerAccountServiceInterface::ACCOUNT_CONFIRMATION_REQUIRED) {
         $url = $this->_customerData->getEmailConfirmationUrl($customer->getEmail());
         $this->_messageManager->addSuccess(__('Account confirmation is required. Please, check your e-mail for confirmation link. To resend confirmation email please <a href="%1">click here</a>.', $url));
     } else {
         $this->getCustomerSession()->regenerateId();
         $this->getCustomerSession()->loginById($customer->getId());
     }
     return $this;
 }
Example #4
0
 /**
  * Saving customer subscription status
  *
  * @param int $customerId
  * @param bool $subscribe indicates whether the customer should be subscribed or unsubscribed
  * @return  $this
  *
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 protected function _updateCustomerSubscription($customerId, $subscribe)
 {
     try {
         $customerData = $this->_customerAccountService->getCustomer($customerId);
     } catch (NoSuchEntityException $e) {
         return $this;
     }
     $this->loadByCustomerId($customerId);
     if (!$subscribe && !$this->getId()) {
         return $this;
     }
     if (!$this->getId()) {
         $this->setSubscriberConfirmCode($this->randomSequence());
     }
     $sendInformationEmail = false;
     $status = self::STATUS_SUBSCRIBED;
     if ($subscribe) {
         if (CustomerAccountServiceInterface::ACCOUNT_CONFIRMATION_REQUIRED == $this->_customerAccountService->getConfirmationStatus($customerId)) {
             $status = self::STATUS_UNCONFIRMED;
         }
     } else {
         $status = self::STATUS_UNSUBSCRIBED;
     }
     /**
      * If subscription status has been changed then send email to the customer
      */
     if ($status != self::STATUS_UNCONFIRMED && $status != $this->getStatus()) {
         $sendInformationEmail = true;
     }
     if ($status != $this->getStatus()) {
         $this->setStatusChanged(true);
     }
     $this->setStatus($status);
     if (!$this->getId()) {
         $storeId = $customerData->getStoreId();
         if ($customerData->getStoreId() == 0) {
             $storeId = $this->_storeManager->getWebsite($customerData->getWebsiteId())->getDefaultStore()->getId();
         }
         $this->setStoreId($storeId)->setCustomerId($customerData->getId())->setEmail($customerData->getEmail());
     } else {
         $this->setStoreId($customerData->getStoreId())->setEmail($customerData->getEmail());
     }
     $this->save();
     $sendSubscription = $sendInformationEmail;
     if (is_null($sendSubscription) xor $sendSubscription) {
         try {
             if ($this->isStatusChanged() && $status == self::STATUS_UNSUBSCRIBED) {
                 $this->sendUnsubscriptionEmail();
             } elseif ($this->isStatusChanged() && $status == self::STATUS_SUBSCRIBED) {
                 $this->sendConfirmationSuccessEmail();
             }
         } catch (MailException $e) {
             // If we are not able to send a new account email, this should be ignored
             $this->_logger->logException($e);
         }
     }
     return $this;
 }