magento 2相当于Mage :: getModel(' customer / customer') - > loadByEmail();是?

时间:2017-04-06 08:58:38

标签: model magento2 customer

magento 2中此代码的等价物是什么?

法师:: getModel('顾客/顾客') - > loadByEmail();

2 个答案:

答案 0 :(得分:2)

请使用此代码:

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

答案 1 :(得分:2)

你也可以试试这个:

protected $customerCollection;

public function __construct(
    ...
    \Magento\Customer\Model\Customer $customerCollection,
    ...     
)
{
    ...
    $this->customerCollection = $customerCollection;
    ...
}

在您的函数中使用以下代码: -

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