How to get email address in sales_quote_address_collect_totals_before events guest user email address.
<?php namespace xxxxxx\xxxx\Observer;
use Magento\Framework\Event\ObserverInterface;
class Observer implements ObserverInterface {
/**
* @var \Magento\Customer\Helper\Address
*/
protected $customerAddressHelper;
/**
* Initialize dependencies.
*
* @param \Magento\Customer\Helper\Address $customerAddressHelper
*/
public function __construct(
\Magento\Customer\Helper\Address $customerAddressHelper
) {
$this->customerAddressHelper = $customerAddressHelper;
}
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();
$order= $observer->getEvent()->getOrder();
$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());
$logger->info($quote->getCustomerEmail());
}
print in a log file is :
2019-08-07T07:04:44+00:00 INFO (6): 7827495597
2019-08-07T07:04:44+00:00 INFO (6): testasd
2019-08-07T07:04:44+00:00 INFO (6): test1
2019-08-07T07:04:44+00:00 INFO (6):
2019-08-07T07:04:44+00:00 INFO (6):
Email address is empty. I want to get guest user email address in custom observer file .