Magento2: How to get guest email early in checkout? The Next CEO of Stack OverflowMagento2 : How to get guest email address after shipping address and before placeorder?Address removed on checkout in guest checkoutHow to get the checkout page register Entered value in core fileAfter rewrite MagentoCustomerModelAccountManagement giving me fatal error“Phone” is a required value on Guest CheckoutHow to Refresh/reload Magento 2 Quote Object in checkout session/pageMonolog Error After 2.2 UpgradeHow to get customer billing and shipping information in magento2 .phtml files?How to get checkout form data for logged in and guest customers in magento 2when click on place order then paypal showing error in Magento2Getting Errors after MySQL database import

Does Germany produce more waste than the US?

How to find if SQL server backup is encrypted with TDE without restoring the backup

Oldie but Goldie

Do I need to write [sic] when including a quotation with a number less than 10 that isn't written out?

Raspberry pi 3 B with Ubuntu 18.04 server arm64: what pi version

Is it possible to create a QR code using text?

How to pronounce fünf in 45

Why did early computer designers eschew integers?

Is it possible to make a 9x9 table fit within the default margins?

My boss doesn't want me to have a side project

How does a dynamic QR code work?

Is a linearly independent set whose span is dense a Schauder basis?

Is it okay to majorly distort historical facts while writing a fiction story?

pgfplots: How to draw a tangent graph below two others?

Simplify trigonometric expression using trigonometric identities

Mathematica command that allows it to read my intentions

Can Sri Krishna be called 'a person'?

How can the PCs determine if an item is a phylactery?

Incomplete cube

Compensation for working overtime on Saturdays

What happens if you break a law in another country outside of that country?

How seriously should I take size and weight limits of hand luggage?

Car headlights in a world without electricity

Is there a rule of thumb for determining the amount one should accept for a settlement offer?



Magento2: How to get guest email early in checkout?



The Next CEO of Stack OverflowMagento2 : How to get guest email address after shipping address and before placeorder?Address removed on checkout in guest checkoutHow to get the checkout page register Entered value in core fileAfter rewrite MagentoCustomerModelAccountManagement giving me fatal error“Phone” is a required value on Guest CheckoutHow to Refresh/reload Magento 2 Quote Object in checkout session/pageMonolog Error After 2.2 UpgradeHow to get customer billing and shipping information in magento2 .phtml files?How to get checkout form data for logged in and guest customers in magento 2when click on place order then paypal showing error in Magento2Getting Errors after MySQL database import










0















I need to get the customer e-mail address in the checkout.
I need it after the user went to Step 2 of the checkout (After he entered Address/before he can select his payment option).



I tried:



$quote->getCustomerEmail()
$this->session->getQuote()->getCustomerEmail();
$quote->getBillingAddress()->getEmail();


And many more.



The thing is: The e-mail is nowhere, I used XDebugg and looked deeply in Session, Quote and many more data. But the e-mail address is available after the user clicks on "place order", this is way to late.



I found unsolved questions with the same problem:



https://community.magento.com/t5/Magento-2-x-Programming/get-guest-quote-email/td-p/102751



Magento2 : How to get guest email address after shipping address and before placeorder?



Probably I have to change Magento checkout behavior, so that it also sends the e-mail together with the shipping address to the controller, because it only sends the address without the e-mail.



BUT, I've no idea, how I can do this.



Edit:
I've tried the answer (Method2) of Rakesh Jakhar, but it seems I do something wrong.



I created the File /app/code/Myself/Test/Model/Customer/AccountManagement.php:



<?php

namespace MyselfTestModelCustomer;

use /* same as original file */

/**
* Handle various customer account actions
*
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @SuppressWarnings(PHPMD.TooManyFields)
* @SuppressWarnings(PHPMD.ExcessiveClassComplexity)
*/
class AccountManagement extends MagentoCustomerModelAccountManagement

/**
* @var CustomerRepositoryInterface
*/
private $customerRepository;

/**
* @var MagentoStoreModelStoreManagerInterface
*/
private $storeManager;

/**
* @inheritdoc
*/
public function isEmailAvailable($customerEmail, $websiteId = null)

$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$checkoutSession = $objectManager->get('MagentoCheckoutModelSession');
$checkoutSession->setGuestCustomerEmail($customerEmail);

try
if ($websiteId === null)
$websiteId = $this->storeManager->getStore()->getWebsiteId();

$this->customerRepository->get($customerEmail, $websiteId);
return false;
catch (NoSuchEntityException $e)
return true;





I added to my di.xml:



<preference for="MagentoCustomerModelAccountManagement" type="MyselfTestModelCustomerAccountManagement" />


The class seems to get overridden, because in the checkout it now says "You already have an account with us. Sign in or continue as guest.".
So I think the method or class is broken now.



Edit2:



So I tried Rakesh Jakhar method 1. But I did it wrong.
Where did I the mistake?



I copied /vendor/magento/module-checkout/view/frontend/web/js/view/form/element/email.js to /app/code/Myself/Test/web/js/view/form/element/email.js.



I added the cookie:



/**
* Callback on changing email property
*/
emailHasChanged: function ()
var self = this;

clearTimeout(this.emailCheckTimeout);

if (self.validateEmail())
quote.guestEmail = self.email();
checkoutData.setValidatedEmailValue(self.email());
$.cookie("checkoutemail", self.email());

this.emailCheckTimeout = setTimeout(function ()
if (self.validateEmail())
self.checkEmailAvailability();
else
self.isPasswordVisible(false);

, self.checkDelay);

checkoutData.setInputFieldEmailValue(self.email());
,


Then I probably did the mistake.
I created /app/code/Myself/Test/view/frontend/requirejs-config.js
with the following content:



var config = 
map:
'*':

'Magento_Checkout/js/view/form/element/email.js':'Myself_Test/js/view/form/element/email.js'


;


The override don't work, the original email.js file is loaded in the checkout. (I executed the setup:upgrade command only, because I'm in developer mode.)










share|improve this question




























    0















    I need to get the customer e-mail address in the checkout.
    I need it after the user went to Step 2 of the checkout (After he entered Address/before he can select his payment option).



    I tried:



    $quote->getCustomerEmail()
    $this->session->getQuote()->getCustomerEmail();
    $quote->getBillingAddress()->getEmail();


    And many more.



    The thing is: The e-mail is nowhere, I used XDebugg and looked deeply in Session, Quote and many more data. But the e-mail address is available after the user clicks on "place order", this is way to late.



    I found unsolved questions with the same problem:



    https://community.magento.com/t5/Magento-2-x-Programming/get-guest-quote-email/td-p/102751



    Magento2 : How to get guest email address after shipping address and before placeorder?



    Probably I have to change Magento checkout behavior, so that it also sends the e-mail together with the shipping address to the controller, because it only sends the address without the e-mail.



    BUT, I've no idea, how I can do this.



    Edit:
    I've tried the answer (Method2) of Rakesh Jakhar, but it seems I do something wrong.



    I created the File /app/code/Myself/Test/Model/Customer/AccountManagement.php:



    <?php

    namespace MyselfTestModelCustomer;

    use /* same as original file */

    /**
    * Handle various customer account actions
    *
    * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
    * @SuppressWarnings(PHPMD.TooManyFields)
    * @SuppressWarnings(PHPMD.ExcessiveClassComplexity)
    */
    class AccountManagement extends MagentoCustomerModelAccountManagement

    /**
    * @var CustomerRepositoryInterface
    */
    private $customerRepository;

    /**
    * @var MagentoStoreModelStoreManagerInterface
    */
    private $storeManager;

    /**
    * @inheritdoc
    */
    public function isEmailAvailable($customerEmail, $websiteId = null)

    $objectManager = MagentoFrameworkAppObjectManager::getInstance();
    $checkoutSession = $objectManager->get('MagentoCheckoutModelSession');
    $checkoutSession->setGuestCustomerEmail($customerEmail);

    try
    if ($websiteId === null)
    $websiteId = $this->storeManager->getStore()->getWebsiteId();

    $this->customerRepository->get($customerEmail, $websiteId);
    return false;
    catch (NoSuchEntityException $e)
    return true;





    I added to my di.xml:



    <preference for="MagentoCustomerModelAccountManagement" type="MyselfTestModelCustomerAccountManagement" />


    The class seems to get overridden, because in the checkout it now says "You already have an account with us. Sign in or continue as guest.".
    So I think the method or class is broken now.



    Edit2:



    So I tried Rakesh Jakhar method 1. But I did it wrong.
    Where did I the mistake?



    I copied /vendor/magento/module-checkout/view/frontend/web/js/view/form/element/email.js to /app/code/Myself/Test/web/js/view/form/element/email.js.



    I added the cookie:



    /**
    * Callback on changing email property
    */
    emailHasChanged: function ()
    var self = this;

    clearTimeout(this.emailCheckTimeout);

    if (self.validateEmail())
    quote.guestEmail = self.email();
    checkoutData.setValidatedEmailValue(self.email());
    $.cookie("checkoutemail", self.email());

    this.emailCheckTimeout = setTimeout(function ()
    if (self.validateEmail())
    self.checkEmailAvailability();
    else
    self.isPasswordVisible(false);

    , self.checkDelay);

    checkoutData.setInputFieldEmailValue(self.email());
    ,


    Then I probably did the mistake.
    I created /app/code/Myself/Test/view/frontend/requirejs-config.js
    with the following content:



    var config = 
    map:
    '*':

    'Magento_Checkout/js/view/form/element/email.js':'Myself_Test/js/view/form/element/email.js'


    ;


    The override don't work, the original email.js file is loaded in the checkout. (I executed the setup:upgrade command only, because I'm in developer mode.)










    share|improve this question


























      0












      0








      0








      I need to get the customer e-mail address in the checkout.
      I need it after the user went to Step 2 of the checkout (After he entered Address/before he can select his payment option).



      I tried:



      $quote->getCustomerEmail()
      $this->session->getQuote()->getCustomerEmail();
      $quote->getBillingAddress()->getEmail();


      And many more.



      The thing is: The e-mail is nowhere, I used XDebugg and looked deeply in Session, Quote and many more data. But the e-mail address is available after the user clicks on "place order", this is way to late.



      I found unsolved questions with the same problem:



      https://community.magento.com/t5/Magento-2-x-Programming/get-guest-quote-email/td-p/102751



      Magento2 : How to get guest email address after shipping address and before placeorder?



      Probably I have to change Magento checkout behavior, so that it also sends the e-mail together with the shipping address to the controller, because it only sends the address without the e-mail.



      BUT, I've no idea, how I can do this.



      Edit:
      I've tried the answer (Method2) of Rakesh Jakhar, but it seems I do something wrong.



      I created the File /app/code/Myself/Test/Model/Customer/AccountManagement.php:



      <?php

      namespace MyselfTestModelCustomer;

      use /* same as original file */

      /**
      * Handle various customer account actions
      *
      * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
      * @SuppressWarnings(PHPMD.TooManyFields)
      * @SuppressWarnings(PHPMD.ExcessiveClassComplexity)
      */
      class AccountManagement extends MagentoCustomerModelAccountManagement

      /**
      * @var CustomerRepositoryInterface
      */
      private $customerRepository;

      /**
      * @var MagentoStoreModelStoreManagerInterface
      */
      private $storeManager;

      /**
      * @inheritdoc
      */
      public function isEmailAvailable($customerEmail, $websiteId = null)

      $objectManager = MagentoFrameworkAppObjectManager::getInstance();
      $checkoutSession = $objectManager->get('MagentoCheckoutModelSession');
      $checkoutSession->setGuestCustomerEmail($customerEmail);

      try
      if ($websiteId === null)
      $websiteId = $this->storeManager->getStore()->getWebsiteId();

      $this->customerRepository->get($customerEmail, $websiteId);
      return false;
      catch (NoSuchEntityException $e)
      return true;





      I added to my di.xml:



      <preference for="MagentoCustomerModelAccountManagement" type="MyselfTestModelCustomerAccountManagement" />


      The class seems to get overridden, because in the checkout it now says "You already have an account with us. Sign in or continue as guest.".
      So I think the method or class is broken now.



      Edit2:



      So I tried Rakesh Jakhar method 1. But I did it wrong.
      Where did I the mistake?



      I copied /vendor/magento/module-checkout/view/frontend/web/js/view/form/element/email.js to /app/code/Myself/Test/web/js/view/form/element/email.js.



      I added the cookie:



      /**
      * Callback on changing email property
      */
      emailHasChanged: function ()
      var self = this;

      clearTimeout(this.emailCheckTimeout);

      if (self.validateEmail())
      quote.guestEmail = self.email();
      checkoutData.setValidatedEmailValue(self.email());
      $.cookie("checkoutemail", self.email());

      this.emailCheckTimeout = setTimeout(function ()
      if (self.validateEmail())
      self.checkEmailAvailability();
      else
      self.isPasswordVisible(false);

      , self.checkDelay);

      checkoutData.setInputFieldEmailValue(self.email());
      ,


      Then I probably did the mistake.
      I created /app/code/Myself/Test/view/frontend/requirejs-config.js
      with the following content:



      var config = 
      map:
      '*':

      'Magento_Checkout/js/view/form/element/email.js':'Myself_Test/js/view/form/element/email.js'


      ;


      The override don't work, the original email.js file is loaded in the checkout. (I executed the setup:upgrade command only, because I'm in developer mode.)










      share|improve this question
















      I need to get the customer e-mail address in the checkout.
      I need it after the user went to Step 2 of the checkout (After he entered Address/before he can select his payment option).



      I tried:



      $quote->getCustomerEmail()
      $this->session->getQuote()->getCustomerEmail();
      $quote->getBillingAddress()->getEmail();


      And many more.



      The thing is: The e-mail is nowhere, I used XDebugg and looked deeply in Session, Quote and many more data. But the e-mail address is available after the user clicks on "place order", this is way to late.



      I found unsolved questions with the same problem:



      https://community.magento.com/t5/Magento-2-x-Programming/get-guest-quote-email/td-p/102751



      Magento2 : How to get guest email address after shipping address and before placeorder?



      Probably I have to change Magento checkout behavior, so that it also sends the e-mail together with the shipping address to the controller, because it only sends the address without the e-mail.



      BUT, I've no idea, how I can do this.



      Edit:
      I've tried the answer (Method2) of Rakesh Jakhar, but it seems I do something wrong.



      I created the File /app/code/Myself/Test/Model/Customer/AccountManagement.php:



      <?php

      namespace MyselfTestModelCustomer;

      use /* same as original file */

      /**
      * Handle various customer account actions
      *
      * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
      * @SuppressWarnings(PHPMD.TooManyFields)
      * @SuppressWarnings(PHPMD.ExcessiveClassComplexity)
      */
      class AccountManagement extends MagentoCustomerModelAccountManagement

      /**
      * @var CustomerRepositoryInterface
      */
      private $customerRepository;

      /**
      * @var MagentoStoreModelStoreManagerInterface
      */
      private $storeManager;

      /**
      * @inheritdoc
      */
      public function isEmailAvailable($customerEmail, $websiteId = null)

      $objectManager = MagentoFrameworkAppObjectManager::getInstance();
      $checkoutSession = $objectManager->get('MagentoCheckoutModelSession');
      $checkoutSession->setGuestCustomerEmail($customerEmail);

      try
      if ($websiteId === null)
      $websiteId = $this->storeManager->getStore()->getWebsiteId();

      $this->customerRepository->get($customerEmail, $websiteId);
      return false;
      catch (NoSuchEntityException $e)
      return true;





      I added to my di.xml:



      <preference for="MagentoCustomerModelAccountManagement" type="MyselfTestModelCustomerAccountManagement" />


      The class seems to get overridden, because in the checkout it now says "You already have an account with us. Sign in or continue as guest.".
      So I think the method or class is broken now.



      Edit2:



      So I tried Rakesh Jakhar method 1. But I did it wrong.
      Where did I the mistake?



      I copied /vendor/magento/module-checkout/view/frontend/web/js/view/form/element/email.js to /app/code/Myself/Test/web/js/view/form/element/email.js.



      I added the cookie:



      /**
      * Callback on changing email property
      */
      emailHasChanged: function ()
      var self = this;

      clearTimeout(this.emailCheckTimeout);

      if (self.validateEmail())
      quote.guestEmail = self.email();
      checkoutData.setValidatedEmailValue(self.email());
      $.cookie("checkoutemail", self.email());

      this.emailCheckTimeout = setTimeout(function ()
      if (self.validateEmail())
      self.checkEmailAvailability();
      else
      self.isPasswordVisible(false);

      , self.checkDelay);

      checkoutData.setInputFieldEmailValue(self.email());
      ,


      Then I probably did the mistake.
      I created /app/code/Myself/Test/view/frontend/requirejs-config.js
      with the following content:



      var config = 
      map:
      '*':

      'Magento_Checkout/js/view/form/element/email.js':'Myself_Test/js/view/form/element/email.js'


      ;


      The override don't work, the original email.js file is loaded in the checkout. (I executed the setup:upgrade command only, because I'm in developer mode.)







      magento2 checkout email guest-checkout






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited 12 hours ago







      FuFu

















      asked Mar 28 at 16:46









      FuFuFuFu

      379




      379




















          1 Answer
          1






          active

          oldest

          votes


















          0














          Method 1.



          When a custom enter email the following file function are called to validate the email



          Magento_Checkout/web/js/view/form/element/email.js


          Look the function



          emailHasChanged: function () 
          var self = this;

          clearTimeout(this.emailCheckTimeout);

          if (self.validateEmail())
          quote.guestEmail = self.email();
          checkoutData.setValidatedEmailValue(self.email());

          this.emailCheckTimeout = setTimeout(function ()
          if (self.validateEmail())
          self.checkEmailAvailability();
          else
          self.isPasswordVisible(false);

          , self.checkDelay);

          checkoutData.setInputFieldEmailValue(self.email());
          ,


          Inside this function quote.guestEmail gives you the email, you can fire an ajax and save that in seesion and use.



          Another option saves the email in the browser cookie



          $.cookie("checkoutemail", self.email());


          and retrieve the cookie value.



          Method 2.



          Override the following file:-



          MagentoCustomerModelAccountManagement.php


          Replace the following function:-



          public function isEmailAvailable($customerEmail, $websiteId = null)

          $objectManager = MagentoFrameworkAppObjectManager::getInstance();
          $checkoutSession = $objectManager->get('MagentoCheckoutModelSession');
          $checkoutSession->setGuestCustomerEmail($customerEmail);
          try
          if ($websiteId === null)
          $websiteId = $this->storeManager->getStore()->getWebsiteId();


          $this->customerRepository->get($customerEmail, $websiteId);
          return false;
          catch (NoSuchEntityException $e)
          return true;




          Use the following to retrieve the email:-



          $objectManager = MagentoFrameworkAppObjectManager::getInstance();
          $checkoutSession = $objectManager->get('MagentoCheckoutModelSession');
          $guestEmail = $checkoutSession->getGuestCustomerEmail();


          Follow this to override model



          https://magenticians.com/override-model-magento-2/





          share|improve this answer

























          • Doc: devdocs.magento.com/guides/v2.0/javascript-dev-guide/javascript/… I tried this, but it does not work out for me. My Try: var config = map: '*': 'Magento_Checkout/web/js/view/form/element/email.js':'Vendor_Modul/web/js/view/checkout/form/element/email.js' ;

            – FuFu
            Mar 29 at 14:46











          • Do you need the whole code?

            – Rakesh Jakhar
            Mar 29 at 14:56











          • Please yes. It's hard to try it out, because after I run setup:something, magento 2 needs 20min to load the checkout :(

            – FuFu
            Mar 29 at 15:00











          • answer has been updated

            – Rakesh Jakhar
            Mar 29 at 15:24






          • 1





            It didn't worked out. Probably because of an other mistake done by myself. I edited my Answer. Probably the problem is that I extended the original class? I gonna try to not extend it on monday, but this is probably more problematic if the core-file changes....

            – FuFu
            Mar 29 at 17:05











          Your Answer








          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "479"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f267863%2fmagento2-how-to-get-guest-email-early-in-checkout%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          Method 1.



          When a custom enter email the following file function are called to validate the email



          Magento_Checkout/web/js/view/form/element/email.js


          Look the function



          emailHasChanged: function () 
          var self = this;

          clearTimeout(this.emailCheckTimeout);

          if (self.validateEmail())
          quote.guestEmail = self.email();
          checkoutData.setValidatedEmailValue(self.email());

          this.emailCheckTimeout = setTimeout(function ()
          if (self.validateEmail())
          self.checkEmailAvailability();
          else
          self.isPasswordVisible(false);

          , self.checkDelay);

          checkoutData.setInputFieldEmailValue(self.email());
          ,


          Inside this function quote.guestEmail gives you the email, you can fire an ajax and save that in seesion and use.



          Another option saves the email in the browser cookie



          $.cookie("checkoutemail", self.email());


          and retrieve the cookie value.



          Method 2.



          Override the following file:-



          MagentoCustomerModelAccountManagement.php


          Replace the following function:-



          public function isEmailAvailable($customerEmail, $websiteId = null)

          $objectManager = MagentoFrameworkAppObjectManager::getInstance();
          $checkoutSession = $objectManager->get('MagentoCheckoutModelSession');
          $checkoutSession->setGuestCustomerEmail($customerEmail);
          try
          if ($websiteId === null)
          $websiteId = $this->storeManager->getStore()->getWebsiteId();


          $this->customerRepository->get($customerEmail, $websiteId);
          return false;
          catch (NoSuchEntityException $e)
          return true;




          Use the following to retrieve the email:-



          $objectManager = MagentoFrameworkAppObjectManager::getInstance();
          $checkoutSession = $objectManager->get('MagentoCheckoutModelSession');
          $guestEmail = $checkoutSession->getGuestCustomerEmail();


          Follow this to override model



          https://magenticians.com/override-model-magento-2/





          share|improve this answer

























          • Doc: devdocs.magento.com/guides/v2.0/javascript-dev-guide/javascript/… I tried this, but it does not work out for me. My Try: var config = map: '*': 'Magento_Checkout/web/js/view/form/element/email.js':'Vendor_Modul/web/js/view/checkout/form/element/email.js' ;

            – FuFu
            Mar 29 at 14:46











          • Do you need the whole code?

            – Rakesh Jakhar
            Mar 29 at 14:56











          • Please yes. It's hard to try it out, because after I run setup:something, magento 2 needs 20min to load the checkout :(

            – FuFu
            Mar 29 at 15:00











          • answer has been updated

            – Rakesh Jakhar
            Mar 29 at 15:24






          • 1





            It didn't worked out. Probably because of an other mistake done by myself. I edited my Answer. Probably the problem is that I extended the original class? I gonna try to not extend it on monday, but this is probably more problematic if the core-file changes....

            – FuFu
            Mar 29 at 17:05















          0














          Method 1.



          When a custom enter email the following file function are called to validate the email



          Magento_Checkout/web/js/view/form/element/email.js


          Look the function



          emailHasChanged: function () 
          var self = this;

          clearTimeout(this.emailCheckTimeout);

          if (self.validateEmail())
          quote.guestEmail = self.email();
          checkoutData.setValidatedEmailValue(self.email());

          this.emailCheckTimeout = setTimeout(function ()
          if (self.validateEmail())
          self.checkEmailAvailability();
          else
          self.isPasswordVisible(false);

          , self.checkDelay);

          checkoutData.setInputFieldEmailValue(self.email());
          ,


          Inside this function quote.guestEmail gives you the email, you can fire an ajax and save that in seesion and use.



          Another option saves the email in the browser cookie



          $.cookie("checkoutemail", self.email());


          and retrieve the cookie value.



          Method 2.



          Override the following file:-



          MagentoCustomerModelAccountManagement.php


          Replace the following function:-



          public function isEmailAvailable($customerEmail, $websiteId = null)

          $objectManager = MagentoFrameworkAppObjectManager::getInstance();
          $checkoutSession = $objectManager->get('MagentoCheckoutModelSession');
          $checkoutSession->setGuestCustomerEmail($customerEmail);
          try
          if ($websiteId === null)
          $websiteId = $this->storeManager->getStore()->getWebsiteId();


          $this->customerRepository->get($customerEmail, $websiteId);
          return false;
          catch (NoSuchEntityException $e)
          return true;




          Use the following to retrieve the email:-



          $objectManager = MagentoFrameworkAppObjectManager::getInstance();
          $checkoutSession = $objectManager->get('MagentoCheckoutModelSession');
          $guestEmail = $checkoutSession->getGuestCustomerEmail();


          Follow this to override model



          https://magenticians.com/override-model-magento-2/





          share|improve this answer

























          • Doc: devdocs.magento.com/guides/v2.0/javascript-dev-guide/javascript/… I tried this, but it does not work out for me. My Try: var config = map: '*': 'Magento_Checkout/web/js/view/form/element/email.js':'Vendor_Modul/web/js/view/checkout/form/element/email.js' ;

            – FuFu
            Mar 29 at 14:46











          • Do you need the whole code?

            – Rakesh Jakhar
            Mar 29 at 14:56











          • Please yes. It's hard to try it out, because after I run setup:something, magento 2 needs 20min to load the checkout :(

            – FuFu
            Mar 29 at 15:00











          • answer has been updated

            – Rakesh Jakhar
            Mar 29 at 15:24






          • 1





            It didn't worked out. Probably because of an other mistake done by myself. I edited my Answer. Probably the problem is that I extended the original class? I gonna try to not extend it on monday, but this is probably more problematic if the core-file changes....

            – FuFu
            Mar 29 at 17:05













          0












          0








          0







          Method 1.



          When a custom enter email the following file function are called to validate the email



          Magento_Checkout/web/js/view/form/element/email.js


          Look the function



          emailHasChanged: function () 
          var self = this;

          clearTimeout(this.emailCheckTimeout);

          if (self.validateEmail())
          quote.guestEmail = self.email();
          checkoutData.setValidatedEmailValue(self.email());

          this.emailCheckTimeout = setTimeout(function ()
          if (self.validateEmail())
          self.checkEmailAvailability();
          else
          self.isPasswordVisible(false);

          , self.checkDelay);

          checkoutData.setInputFieldEmailValue(self.email());
          ,


          Inside this function quote.guestEmail gives you the email, you can fire an ajax and save that in seesion and use.



          Another option saves the email in the browser cookie



          $.cookie("checkoutemail", self.email());


          and retrieve the cookie value.



          Method 2.



          Override the following file:-



          MagentoCustomerModelAccountManagement.php


          Replace the following function:-



          public function isEmailAvailable($customerEmail, $websiteId = null)

          $objectManager = MagentoFrameworkAppObjectManager::getInstance();
          $checkoutSession = $objectManager->get('MagentoCheckoutModelSession');
          $checkoutSession->setGuestCustomerEmail($customerEmail);
          try
          if ($websiteId === null)
          $websiteId = $this->storeManager->getStore()->getWebsiteId();


          $this->customerRepository->get($customerEmail, $websiteId);
          return false;
          catch (NoSuchEntityException $e)
          return true;




          Use the following to retrieve the email:-



          $objectManager = MagentoFrameworkAppObjectManager::getInstance();
          $checkoutSession = $objectManager->get('MagentoCheckoutModelSession');
          $guestEmail = $checkoutSession->getGuestCustomerEmail();


          Follow this to override model



          https://magenticians.com/override-model-magento-2/





          share|improve this answer















          Method 1.



          When a custom enter email the following file function are called to validate the email



          Magento_Checkout/web/js/view/form/element/email.js


          Look the function



          emailHasChanged: function () 
          var self = this;

          clearTimeout(this.emailCheckTimeout);

          if (self.validateEmail())
          quote.guestEmail = self.email();
          checkoutData.setValidatedEmailValue(self.email());

          this.emailCheckTimeout = setTimeout(function ()
          if (self.validateEmail())
          self.checkEmailAvailability();
          else
          self.isPasswordVisible(false);

          , self.checkDelay);

          checkoutData.setInputFieldEmailValue(self.email());
          ,


          Inside this function quote.guestEmail gives you the email, you can fire an ajax and save that in seesion and use.



          Another option saves the email in the browser cookie



          $.cookie("checkoutemail", self.email());


          and retrieve the cookie value.



          Method 2.



          Override the following file:-



          MagentoCustomerModelAccountManagement.php


          Replace the following function:-



          public function isEmailAvailable($customerEmail, $websiteId = null)

          $objectManager = MagentoFrameworkAppObjectManager::getInstance();
          $checkoutSession = $objectManager->get('MagentoCheckoutModelSession');
          $checkoutSession->setGuestCustomerEmail($customerEmail);
          try
          if ($websiteId === null)
          $websiteId = $this->storeManager->getStore()->getWebsiteId();


          $this->customerRepository->get($customerEmail, $websiteId);
          return false;
          catch (NoSuchEntityException $e)
          return true;




          Use the following to retrieve the email:-



          $objectManager = MagentoFrameworkAppObjectManager::getInstance();
          $checkoutSession = $objectManager->get('MagentoCheckoutModelSession');
          $guestEmail = $checkoutSession->getGuestCustomerEmail();


          Follow this to override model



          https://magenticians.com/override-model-magento-2/






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Mar 29 at 15:23

























          answered Mar 28 at 17:54









          Rakesh JakharRakesh Jakhar

          1765




          1765












          • Doc: devdocs.magento.com/guides/v2.0/javascript-dev-guide/javascript/… I tried this, but it does not work out for me. My Try: var config = map: '*': 'Magento_Checkout/web/js/view/form/element/email.js':'Vendor_Modul/web/js/view/checkout/form/element/email.js' ;

            – FuFu
            Mar 29 at 14:46











          • Do you need the whole code?

            – Rakesh Jakhar
            Mar 29 at 14:56











          • Please yes. It's hard to try it out, because after I run setup:something, magento 2 needs 20min to load the checkout :(

            – FuFu
            Mar 29 at 15:00











          • answer has been updated

            – Rakesh Jakhar
            Mar 29 at 15:24






          • 1





            It didn't worked out. Probably because of an other mistake done by myself. I edited my Answer. Probably the problem is that I extended the original class? I gonna try to not extend it on monday, but this is probably more problematic if the core-file changes....

            – FuFu
            Mar 29 at 17:05

















          • Doc: devdocs.magento.com/guides/v2.0/javascript-dev-guide/javascript/… I tried this, but it does not work out for me. My Try: var config = map: '*': 'Magento_Checkout/web/js/view/form/element/email.js':'Vendor_Modul/web/js/view/checkout/form/element/email.js' ;

            – FuFu
            Mar 29 at 14:46











          • Do you need the whole code?

            – Rakesh Jakhar
            Mar 29 at 14:56











          • Please yes. It's hard to try it out, because after I run setup:something, magento 2 needs 20min to load the checkout :(

            – FuFu
            Mar 29 at 15:00











          • answer has been updated

            – Rakesh Jakhar
            Mar 29 at 15:24






          • 1





            It didn't worked out. Probably because of an other mistake done by myself. I edited my Answer. Probably the problem is that I extended the original class? I gonna try to not extend it on monday, but this is probably more problematic if the core-file changes....

            – FuFu
            Mar 29 at 17:05
















          Doc: devdocs.magento.com/guides/v2.0/javascript-dev-guide/javascript/… I tried this, but it does not work out for me. My Try: var config = map: '*': 'Magento_Checkout/web/js/view/form/element/email.js':'Vendor_Modul/web/js/view/checkout/form/element/email.js' ;

          – FuFu
          Mar 29 at 14:46





          Doc: devdocs.magento.com/guides/v2.0/javascript-dev-guide/javascript/… I tried this, but it does not work out for me. My Try: var config = map: '*': 'Magento_Checkout/web/js/view/form/element/email.js':'Vendor_Modul/web/js/view/checkout/form/element/email.js' ;

          – FuFu
          Mar 29 at 14:46













          Do you need the whole code?

          – Rakesh Jakhar
          Mar 29 at 14:56





          Do you need the whole code?

          – Rakesh Jakhar
          Mar 29 at 14:56













          Please yes. It's hard to try it out, because after I run setup:something, magento 2 needs 20min to load the checkout :(

          – FuFu
          Mar 29 at 15:00





          Please yes. It's hard to try it out, because after I run setup:something, magento 2 needs 20min to load the checkout :(

          – FuFu
          Mar 29 at 15:00













          answer has been updated

          – Rakesh Jakhar
          Mar 29 at 15:24





          answer has been updated

          – Rakesh Jakhar
          Mar 29 at 15:24




          1




          1





          It didn't worked out. Probably because of an other mistake done by myself. I edited my Answer. Probably the problem is that I extended the original class? I gonna try to not extend it on monday, but this is probably more problematic if the core-file changes....

          – FuFu
          Mar 29 at 17:05





          It didn't worked out. Probably because of an other mistake done by myself. I edited my Answer. Probably the problem is that I extended the original class? I gonna try to not extend it on monday, but this is probably more problematic if the core-file changes....

          – FuFu
          Mar 29 at 17:05

















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Magento Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f267863%2fmagento2-how-to-get-guest-email-early-in-checkout%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Get product attribute by attribute group code in magento 2get product attribute by product attribute group in magento 2Magento 2 Log Bundle Product Data in List Page?How to get all product attribute of a attribute group of Default attribute set?Magento 2.1 Create a filter in the product grid by new attributeMagento 2 : Get Product Attribute values By GroupMagento 2 How to get all existing values for one attributeMagento 2 get custom attribute of a single product inside a pluginMagento 2.3 How to get all the Multi Source Inventory (MSI) locations collection in custom module?Magento2: how to develop rest API to get new productsGet product attribute by attribute group code ( [attribute_group_code] ) in magento 2

          Category:9 (number) SubcategoriesMedia in category "9 (number)"Navigation menuUpload mediaGND ID: 4485639-8Library of Congress authority ID: sh85091979ReasonatorScholiaStatistics

          Magento 2.3: How do i solve this, Not registered handle, on custom form?How can i rewrite TierPrice Block in Magento2magento 2 captcha not rendering if I override layout xmlmain.CRITICAL: Plugin class doesn't existMagento 2 : Problem while adding custom button order view page?Magento 2.2.5: Overriding Admin Controller sales/orderMagento 2.2.5: Add, Update and Delete existing products Custom OptionsMagento 2.3 : File Upload issue in UI Component FormMagento2 Not registered handleHow to configured Form Builder Js in my custom magento 2.3.0 module?Magento 2.3. How to create image upload field in an admin form