0

how to get a guest email address in CollectTotalsObserver page in Magento 2.

public function execute(\Magento\Framework\Event\Observer $observer)
{
    /** @var \Magento\Quote\Api\Data\ShippingAssignmentInterface $shippingAssignment */
    $shippingAssignment = $observer->getShippingAssignment();
    /** @var \Magento\Quote\Model\Quote $quote */
    $quote = $observer->getQuote();
    /** @var \Magento\Quote\Model\Quote\Address $address */
    $address = $shippingAssignment->getShipping()->getAddress();

    $customer = $quote->getCustomer();
    $storeId = $customer->getStoreId();

    $writer = new \Zend\Log\Writer\Stream(BP. '/var/log/nitesh.log');
    $logger = new \Zend\Log\Logger();
    $logger->addWriter($writer);


    $logger->info($address->getTelephone()); 
    $logger->info($address->getFirstname()); 
    $logger->info($address->getLastname()); 
    $logger->info($address->getEmail());

print in log file
2019-08-03T13:00:09+00:00 INFO (6): 782700000
2019-08-03T13:00:09+00:00 INFO (6): nitesh
2019-08-03T13:00:09+00:00 INFO (6): singh
2019-08-03T13:00:09+00:00 INFO (6):

I want to get email address here.

  • 1
    $quote->getCustomerEmail(); – Sohel Rana Aug 3 at 13:36
  • Hi Sohel Rana, Thanks .but using namespace Magento\Quote\Observer\Frontend\Quote\Address; $quote->getCustomerEmail(); is given None . – Nitesh Kumar Singh Aug 5 at 8:58
  • user is login then $quote->getCustomerEmail(); but i want to guest user email address – Nitesh Kumar Singh Aug 5 at 10:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.