在magento 2中,这段代码的等效性是什么?
Mage::getModel('customer/customer')->loadByEmail(); 发布于 2017-04-08 07:53:26
请使用以下代码:
<?php
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$customer = $objectManager->get('Magento\Customer\Model\Customer');
$customer->setWebsiteId('1');
$customer->loadByEmail('test@gmail.com');
?>发布于 2017-12-25 06:42:43
您也可以尝试这样做:
protected $customerCollection;
public function __construct(
...
\Magento\Customer\Model\Customer $customerCollection,
...
)
{
...
$this->customerCollection = $customerCollection;
...
}在您的功能中使用以下代码:-
$customerObj = $this->customerCollection;
$customerObj->setWebsiteId($websiteId);
$customerObj->loadByEmail('test@gmail.com');https://stackoverflow.com/questions/43250429
复制相似问题