/** * Check customer scope, email and confirmation key before saving * * @param Mage_Customer_Model_Customer $customer * @throws Mage_Customer_Exception * @return Mage_Customer_Model_Resource_Customer */ protected function _beforeSave(Varien_Object $customer) { parent::_beforeSave($customer); if (!$customer->getEmail()) { throw Mage::exception('Mage_Customer', Mage::helper('Mage_Customer_Helper_Data')->__('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('Mage_Customer_Helper_Data')->__('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; }
/** * Check customer scope, email and confirmation key before saving * * @param Varien_Object $customer * @return Mage_Customer_Model_Entity_Customer * @throws Mage_Core_Exception */ protected function _beforeSave(Varien_Object $customer) { parent::_beforeSave($customer); $select = $this->_getReadAdapter()->select()->from($this->getEntityTable(), array($this->getEntityIdField()))->where('email=?', $customer->getEmail()); if ($customer->getSharingConfig()->isWebsiteScope()) { $select->where('website_id=?', (int) $customer->getWebsiteId()); } if ($customer->getId()) { $select->where('entity_id !=?', $customer->getId()); } if ($this->_getWriteAdapter()->fetchOne($select)) { Mage::throwException(Mage::helper('customer')->__('Customer email already 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; }
/** * Also serialize additional information * * @param Varien_Object $payment */ protected function _beforeSave(Varien_Object $payment) { $additionalInformation = $payment->getData('additional_information'); if (empty($additionalInformation)) { $payment->setData('additional_information', null); } elseif (is_array($additionalInformation)) { $payment->setData('additional_information', serialize($additionalInformation)); } parent::_beforeSave($payment); }
protected function _beforeSave(Varien_Object $customer) { parent::_beforeSave($customer); $select = $this->_getReadAdapter()->select()->from($this->getEntityTable(), array($this->getEntityIdField()))->where('email=?', $customer->getEmail()); if ($customer->getSharingConfig()->isWebsiteScope()) { $select->where('website_id=?', (int) $customer->getWebsiteId()); } if ($customer->getId()) { $select->where('entity_id !=?', $customer->getId()); } if ($this->_getWriteAdapter()->fetchOne($select)) { Mage::throwException(Mage::helper('customer')->__('Customer email already exists')); } return $this; }
/** * @param Varien_Object $object * @return $this */ protected function _beforeSave(Varien_Object $object) { parent::_beforeSave($object); $this->_changeTime($object); return $this; }
/** * Check customer address before saving * * @param Varien_Object $address * @return Mage_Customer_Model_Resource_Address */ protected function _beforeSave(Varien_Object $address) { parent::_beforeSave($address); $this->_validate($address); return $this; }