0

我的要求是,当客户注册电子邮件存在验证是 magento 的默认功能,但我们应该允许重复的电子邮件。

我正在使用自定义模块使用用户名(而不是电子邮件)登录到 magento 商店。

因此,您的自定义应支持在前端注册/更新、后端(管理面板)注册/更新、从客户 CSV 文件导入以及从 V2_API 创建用户时使用重复电子邮件进行注册。

如果可能,请详细回复我一些好的解决方案。任何帮助是极大的赞赏。提前致谢。

4

1 回答 1

2

Magento 在 Mage_Customer_Model_Resource_Customer 类中检查了重复的客户电子邮件。看看它。你会发现这个功能。

protected function _beforeSave(Varien_Object $customer)
{
    parent::_beforeSave($customer);

    if (!$customer->getEmail()) {
        throw Mage::exception('Mage_Customer', Mage::helper('customer')->__('Customer email is required'));
    }

    $adapter = $this->_getWriteAdapter();
    $bind    = array('email' => $customer->getEmail());

    $select = $adapter->select()
        ->from($this->getEntityTable(), array($this->getEntityIdField()))
        ->where('email = :email');
    if ($customer->getSharingConfig()->isWebsiteScope()) {
        $bind['website_id'] = (int)$customer->getWebsiteId();
        $select->where('website_id = :website_id');
    }
    if ($customer->getId()) {
        $bind['entity_id'] = (int)$customer->getId();
        $select->where('entity_id != :entity_id');
    }

    $result = $adapter->fetchOne($select, $bind);
    if ($result) {
        throw Mage::exception(
            'Mage_Customer', Mage::helper('customer')->__('This customer email already exists'),
            Mage_Customer_Model_Customer::EXCEPTION_EMAIL_EXISTS
        );
    }

    // set confirmation key logic
    if ($customer->getForceConfirmed()) {
        $customer->setConfirmation(null);
    } elseif (!$customer->getId() && $customer->isConfirmationRequired()) {
        $customer->setConfirmation($customer->getRandomConfirmationKey());
    }
    // remove customer confirmation key from database, if empty
    if (!$customer->getConfirmation()) {
        $customer->setConfirmation(null);
    }

    return $this;
}

如果您要允许重复的客户电子邮件,您可以注释掉此代码。

    $adapter = $this->_getWriteAdapter();
    $bind    = array('email' => $customer->getEmail());

    $select = $adapter->select()
        ->from($this->getEntityTable(), array($this->getEntityIdField()))
        ->where('email = :email');
    if ($customer->getSharingConfig()->isWebsiteScope()) {
        $bind['website_id'] = (int)$customer->getWebsiteId();
        $select->where('website_id = :website_id');
    }
    if ($customer->getId()) {
        $bind['entity_id'] = (int)$customer->getId();
        $select->where('entity_id != :entity_id');
    }

    $result = $adapter->fetchOne($select, $bind);
    if ($result) {
        throw Mage::exception(
            'Mage_Customer', Mage::helper('customer')->__('This customer email already exists'),
            Mage_Customer_Model_Customer::EXCEPTION_EMAIL_EXISTS
        );
    }

或者你最好重写客户资源。我自己建议你重写它。希望这可以帮助。

于 2012-08-01T08:49:30.163 回答