php 客户模型中 Magento 中的 loadByEmail 和加载方法问题
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24759015/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
loadByEmail and load method issue in Magento in Customer Model
提问by Patel Dixit
i getting error while i am try to use get Entity Id (getEntityId()) Method in customer/customer model object.
当我尝试在客户/客户模型对象中使用 get Entity Id (getEntityId()) 方法时出现错误。
Please check my bellow's code.
请检查我的波纹管代码。
I want to use bellow's code. But its showing error.
我想使用波纹管的代码。但它的显示错误。
$customer = Mage::getModel("customer/customer");
$customer->setWebsiteId(Mage::app()->getWebsite()->getId());
$customer->loadByEmail('[email protected]'); //load customer by email id
While bellow's code is working fine. with getEntityId()
虽然波纹管的代码工作正常。使用 getEntityId()
$id=3;
$customer = Mage::getModel('customer/customer')->load($id);
So Please give solution for loadByEmail() method.
所以请给出 loadByEmail() 方法的解决方案。
回答by Amit Bera
The store website code is wrong,
it should be Mage::app()->getStore()->getWebsiteId()
商店网站代码错误,应该是 Mage::app()->getStore()->getWebsiteId()
Here modified code is
这里修改的代码是
$customer = Mage::getModel("customer/customer");
$customer->setWebsiteId(Mage::app()->getStore()->getWebsiteId());
$customer->loadByEmail('[email protected]')
回答by Patel Dixit
Finally i founds solution for my problem.
最后我找到了解决我的问题的方法。
$customer = Mage::getModel("customer/customer");
$customer->setWebsiteId(Mage::app()->getWebsite('admin')->getId());
$customer->loadByEmail($email);
回答by Moose
This is a duplicate of
这是一个副本
Get information about customer by email id in magento
通过 magento 中的电子邮件 ID 获取有关客户的信息
Your code is correct but the Mage::app()->getWebsite()->getId()
is returning a 0 which does not correspond.
您的代码是正确的,但Mage::app()->getWebsite()->getId()
返回的是不对应的 0。
If you, for instance, use the following:
例如,如果您使用以下内容:
$customer->setWebsiteId(1);
You'll most likely notice that the customer now loads. The reasoning is because customer accounts are shared by website. You can read the aforementioned post for further info.
您很可能会注意到客户现在正在加载。原因是客户帐户是由网站共享的。您可以阅读上述帖子以获取更多信息。
回答by jruzafa
Other posible solution is a collection:
其他可能的解决方案是一个集合:
$customerExist = Mage::getModel('customer/customer')
->getCollection()
->addAttributeToSelect('*')
->addAttributeToFilter('email', $email )
->getFirstItem();