magento报错:Customer website ID must be specified when using the website scope

根据邮件用户名获取顾客对象时,可以用Customer模块自带的loadByEmail方法

public function loadByEmail($customerEmail)
    {
        $this->_getResource()->loadByEmail($this, $customerEmail);
        return $this;
    }

但是直接使用下面的方法

$customer = Mage::getModel('customer/customer')
                ->loadByEmail($email);

会报错,错误信息如下:

Customer website ID must be specified when using the website

事实上,创建customer对象时需要指定websitId

正确的使用方法如下:

$customer = Mage::getModel('customer/customer')
                ->setWebsiteId(Mage::app()->getStore()->getWebsiteId())
                ->loadByEmail($email);

你可能感兴趣的:(magento报错:Customer website ID must be specified when using the website scope)