Please use two plugin. Following code worked for me
<type name="Magento\Checkout\Model\ShippingInformationManagement">
<plugin disabled="false" name="BA_Vertex_ShippingInformationManagement" type="BA\Vertex\Plugin\Frontend\Magento\Checkout\Model\ShippingInformationManagement"/>
</type>
<type name="Magento\Customer\Api\AccountManagementInterface">
<plugin name="BA_IsCustomerAvailable" type="BA\Vertex\Plugin\Magento\Customer\Api\AccountManagementPlugin"/>
</type>
AccountManagementInterface
<?php
namespace BA\Vertex\Plugin\Magento\Customer\Api;
use Magento\Framework\App\RequestInterface;
use Magento\Framework\App\Response\RedirectInterface;
class AccountManagementPlugin
{
/**
* @var \Magento\Framework\App\RequestInterface
*/
protected $request;
/**
* @var \Magento\Checkout\Helper\Cart
*/
protected $cartHelper;
/**
* @var \Magento\Framework\App\Response\RedirectInterface
*/
protected $redirect;
public function __construct(
\Magento\Checkout\Helper\Cart $cartHelper,
RequestInterface $request,
RedirectInterface $redirect
) {
$this->request = $request;
$this->cartHelper = $cartHelper;
$this->redirect = $redirect;
}
public function beforeIsEmailAvailable(
\Magento\Customer\Api\AccountManagementInterface $subject,
$result,
$customerEmail,
$websiteId = null
) {
$referrer = $this->redirect->getRefererUrl();
if (preg_match('/checkout/i', $referrer)) {
$this->cartHelper->getQuote()->setCustomerEmail($result);
$this->cartHelper->getQuote()->save();
}
return $result;
}
}
ShippingInformationManagement
<?php
namespace BA\Vertex\Plugin\Frontend\Magento\Checkout\Model;
class ShippingInformationManagement
{
protected $_logger;
/**
* @var \Magento\Checkout\Helper\Cart
*/
protected $cartHelper;
public function __construct(
\Magento\Checkout\Helper\Cart $cartHelper
) {
$this->cartHelper = $cartHelper;
}
public function beforeSaveAddressInformation(
\Magento\Checkout\Model\ShippingInformationManagement $subject,
$result,
\Magento\Checkout\Api\Data\ShippingInformationInterface $addressInformation
) {
$emailAddress = $this->cartHelper->getQuote()->getCustomerEmail();
$firstName = $addressInformation->getShippingAddress()->getFirstname();
$lastName = $addressInformation->getShippingAddress()->getLastname();
return $result;
}
}