magento 2与Mage::getModel(';customer/customer';)的等价物是什么;loadByEmail();是

magento 2与Mage::getModel(';customer/customer';)的等价物是什么;loadByEmail();是,model,magento2,customer,Model,Magento2,Customer,magento 2中此代码的等效代码是什么 Mage::getModel('customer/customer')->loadByEmail() ?请使用此代码: <?php $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $customer = $objectManager->get('Magento\Customer\Model\Customer'); $customer->se

magento 2中此代码的等效代码是什么

Mage::getModel('customer/customer')->loadByEmail()

请使用此代码:

<?php 
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$customer =  $objectManager->get('Magento\Customer\Model\Customer');
$customer->setWebsiteId('1');
$customer->loadByEmail('test@gmail.com'); 
?>

请使用此代码:

<?php 
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$customer =  $objectManager->get('Magento\Customer\Model\Customer');
$customer->setWebsiteId('1');
$customer->loadByEmail('test@gmail.com'); 
?>

您也可以尝试以下方法:

protected $customerCollection;

public function __construct(
    ...
    \Magento\Customer\Model\Customer $customerCollection,
    ...     
)
{
    ...
    $this->customerCollection = $customerCollection;
    ...
}
在函数中使用以下代码:-

$customerObj = $this->customerCollection;
$customerObj->setWebsiteId($websiteId);
$customerObj->loadByEmail('test@gmail.com');
您也可以尝试以下方法:

protected $customerCollection;

public function __construct(
    ...
    \Magento\Customer\Model\Customer $customerCollection,
    ...     
)
{
    ...
    $this->customerCollection = $customerCollection;
    ...
}
在函数中使用以下代码:-

$customerObj = $this->customerCollection;
$customerObj->setWebsiteId($websiteId);
$customerObj->loadByEmail('test@gmail.com');