2017-08-08 1 views

Répondre

1

La fonction est:

fournisseur/magento/module bulletin/Modèle/Subscriber.php

public function subscribe($email) 
    { 
     $this->loadByEmail($email); 

     if (!$this->getId()) { 
      $this->setSubscriberConfirmCode($this->randomSequence()); 
     } 
     $isConfirmNeed = $this->_scopeConfig->getValue(
      self::XML_PATH_CONFIRMATION_FLAG, 
      \Magento\Store\Model\ScopeInterface::SCOPE_STORE 
     ) == 1 ? true : false; 
     $isOwnSubscribes = false; 
     $isSubscribeOwnEmail = $this->_customerSession->isLoggedIn() 
      && $this->_customerSession->getCustomerDataObject()->getEmail() == $email; 

     if (!$this->getId() || $this->getStatus() == self::STATUS_UNSUBSCRIBED 
      || $this->getStatus() == self::STATUS_NOT_ACTIVE 
     ) { 
      if ($isConfirmNeed === true) { 
       // if user subscribes own login email - confirmation is not needed 
       $isOwnSubscribes = $isSubscribeOwnEmail; 
       if ($isOwnSubscribes == true) { 
        $this->setStatus(self::STATUS_SUBSCRIBED); 
       } else { 
        $this->setStatus(self::STATUS_NOT_ACTIVE); 
       } 
      } else { 
       $this->setStatus(self::STATUS_SUBSCRIBED); 
      } 
      $this->setSubscriberEmail($email); 
     } 
     if ($isSubscribeOwnEmail) { 
      try { 
       $customer = $this->customerRepository->getById($this->_customerSession->getCustomerId()); 
       $this->setStoreId($customer->getStoreId()); 
       $this->setCustomerId($customer->getId()); 
      } catch (NoSuchEntityException $e) { 
       $this->setStoreId($this->_storeManager->getStore()->getId()); 
       $this->setCustomerId(0); 
      } 
     } else { 
      $this->setStoreId($this->_storeManager->getStore()->getId()); 
      $this->setCustomerId(0); 
     } 

     $this->setStatusChanged(true); 
     try { 
      $this->save(); 
      if ($isConfirmNeed === true 
       && $isOwnSubscribes === false 
      ) { 
       $this->sendConfirmationRequestEmail(); 
      } else { 
       $this->sendConfirmationSuccessEmail(); 
      } 
      return $this->getStatus(); 
     } catch (\Exception $e) { 
      throw new \Exception($e->getMessage()); 
     } 
    }