Php 如何在“编辑和加载项”自定义模块上验证magento admin中的重复电子邮件
我需要在编辑和添加操作时验证magento中的重复电子邮件。基本上在编辑,如果我改变了电子邮件id,如果这是在数据库中,然后我需要得到的邮件重复电子邮件。。。。如果我添加,那么我还想验证magento中的重复电子邮件 我在管理中的保存功能Php 如何在“编辑和加载项”自定义模块上验证magento admin中的重复电子邮件,php,validation,email,magento,Php,Validation,Email,Magento,我需要在编辑和添加操作时验证magento中的重复电子邮件。基本上在编辑,如果我改变了电子邮件id,如果这是在数据库中,然后我需要得到的邮件重复电子邮件。。。。如果我添加,那么我还想验证magento中的重复电子邮件 我在管理中的保存功能 公共函数saveAction() { 如果($this->getRequest()->getPost()) { 试一试{ $postData=$this->getRequest()->getPost(); $currentTimestamp=time();
公共函数saveAction()
{
如果($this->getRequest()->getPost())
{
试一试{
$postData=$this->getRequest()->getPost();
$currentTimestamp=time();
$postData['updated_at']=$currentTimestamp;
$postData['seller\u other\u sale\u sites']=内爆(',',$postData['seller\u other\u sale\u sites']);
$sellerModel=Mage::getModel('seller/seller');
如果($this->getRequest()->getParam('id')setCreatedTime(
Mage::getSingleton('核心/日期')
->gmtDate()
);
$sellerModel
->addData($postData)
->设置日期时间(
Mage::getSingleton('核心/日期')
->gmtDate())
->setId($this->getRequest()->getParam('id'))
->save();
Mage::getSingleton('adminhtml/session')
->addSuccess(“已成功保存”);
Mage::getSingleton('adminhtml/session')
->settestData(假);
$this->_重定向('*/*/');
回来
}捕获(例外$e){
Mage::getSingleton('adminhtml/session')
->addError($e->getMessage());
Mage::getSingleton('adminhtml/session')
->settestData($this->getRequest()
->getPost()
);
$this->_重定向('*/*/edit',
数组('id'=>this->getRequest()
->getParam('id'));
回来
}
}
$this->_重定向('*/*/');
}
我需要验证save函数是否在helper类中创建一个以$email为参数的函数
public function customerExists($email, $websiteId = null)
{
$customer = Mage::getModel('customer/customer');
$customer->setWebsiteId($websiteId);
$customer->loadByEmail($email);
if ($customer->getId()) {
return $customer;
}
return false;
}
在执行保存操作之前,请以这种方式使用helper函数
Mage::helper('modulename')->customerExists($email,$websiteId);
如果客户已经存在,它将返回customer对象,如果没有,它将返回false。因此,您可以相应地写入剩余代码/抛出异常/设置错误消息。来自
Mage\u customer\u Model\u Resource\u customer
此代码在保存之前检查唯一的电子邮件\u(除非更新现有客户,在这种情况下,它只检查该客户上的重复项)
这在Mage系统中,但不使用任何模型
$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
);
}
我没有使用客户模型..我需要一个核心php中的函数,我需要通过helper进行验证
$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
);
}