Mage_Customer_Model_Entity_Customer Class Reference

Inheritance diagram for Mage_Customer_Model_Entity_Customer:

Mage_Eav_Model_Entity_Abstract Mage_Core_Model_Resource_Abstract Mage_Eav_Model_Entity_Interface

List of all members.

Public Member Functions

 __construct ()
 loadByEmail (Mage_Customer_Model_Customer $customer, $email, $testOnly=false)
 changePassword (Mage_Customer_Model_Customer $customer, $newPassword)
 findEmailDuplicates ()
 checkCustomerId ($customerId)

Protected Member Functions

 _getDefaultAttributes ()
 _beforeSave (Varien_Object $customer)
 _afterSave (Varien_Object $customer)
 _saveAddresses (Mage_Customer_Model_Customer $customer)
 _getLoadRowSelect ($object, $rowId)


Detailed Description

Definition at line 34 of file Customer.php.


Constructor & Destructor Documentation

__construct (  ) 

Initiate resources

Reimplemented from Mage_Core_Model_Resource_Abstract.

Definition at line 40 of file Customer.php.

00041     {
00042         $resource = Mage::getSingleton('core/resource');
00043         $this->setType('customer');
00044         $this->setConnection(
00045             $resource->getConnection('customer_read'),
00046             $resource->getConnection('customer_write')
00047         );
00048     }


Member Function Documentation

_afterSave ( Varien_Object customer  )  [protected]

Save customer addresses and set default addresses in attributes backend

Parameters:
Varien_Object $customer
Returns:
Mage_Eav_Model_Entity_Abstract

Reimplemented from Mage_Eav_Model_Entity_Abstract.

Definition at line 113 of file Customer.php.

00114     {
00115         $this->_saveAddresses($customer);
00116         return parent::_afterSave($customer);
00117     }

_beforeSave ( Varien_Object customer  )  [protected]

Check customer scope, email and confirmation key before saving

Parameters:
Varien_Object $customer
Returns:
Mage_Customer_Model_Entity_Customer
Exceptions:
Mage_Core_Exception 

Reimplemented from Mage_Eav_Model_Entity_Abstract.

Definition at line 75 of file Customer.php.

00076     {
00077         parent::_beforeSave($customer);
00078         $select = $this->_getReadAdapter()->select()
00079             ->from($this->getEntityTable(), array($this->getEntityIdField()))
00080             ->where('email=?', $customer->getEmail());
00081         if ($customer->getSharingConfig()->isWebsiteScope()) {
00082             $select->where('website_id=?', (int) $customer->getWebsiteId());
00083         }
00084         if ($customer->getId()) {
00085             $select->where('entity_id !=?', $customer->getId());
00086         }
00087 
00088         if ($this->_getWriteAdapter()->fetchOne($select)) {
00089             Mage::throwException(Mage::helper('customer')->__('Customer email already exists'));
00090         }
00091 
00092         // set confirmation key logic
00093         if ($customer->getForceConfirmed()) {
00094             $customer->setConfirmation(null);
00095         }
00096         elseif ((!$customer->getId()) && ($customer->isConfirmationRequired())) {
00097             $customer->setConfirmation($customer->getRandomConfirmationKey());
00098         }
00099         // remove customer confirmation key from database, if empty
00100         if (!$customer->getConfirmation()) {
00101             $customer->setConfirmation(null);
00102         }
00103 
00104         return $this;
00105     }

_getDefaultAttributes (  )  [protected]

Retrieve customer entity default attributes

Returns:
array

Reimplemented from Mage_Eav_Model_Entity_Abstract.

Definition at line 55 of file Customer.php.

00056     {
00057         return array(
00058             'entity_type_id',
00059             'attribute_set_id',
00060             'created_at',
00061             'updated_at',
00062             'increment_id',
00063             'store_id',
00064             'website_id'
00065         );
00066     }

_getLoadRowSelect ( object,
rowId 
) [protected]

Retrieve select object for loading base entity row

Parameters:
Varien_Object $object
mixed $rowId
Returns:
Zend_Db_Select

Reimplemented from Mage_Eav_Model_Entity_Abstract.

Definition at line 147 of file Customer.php.

00148     {
00149         $select = parent::_getLoadRowSelect($object, $rowId);
00150         if ($object->getWebsiteId() && $object->getSharingConfig()->isWebsiteScope()) {
00151             $select->where('website_id=?', (int) $object->getWebsiteId());
00152         }
00153         return $select;
00154     }

_saveAddresses ( Mage_Customer_Model_Customer customer  )  [protected]

Save/delete customer address

Parameters:
Mage_Customer_Model_Customer $customer
Returns:
Mage_Customer_Model_Entity_Customer

Definition at line 125 of file Customer.php.

00126     {
00127         foreach ($customer->getAddresses() as $address) {
00128             if ($address->getData('_deleted')) {
00129                 $address->delete();
00130             }
00131             else {
00132                 $address->setParentId($customer->getId())
00133                     ->setStoreId($customer->getStoreId())
00134                     ->save();
00135             }
00136         }
00137         return $this;
00138     }

changePassword ( Mage_Customer_Model_Customer customer,
newPassword 
)

Change customer password

Parameters:
Mage_Customer_Model_Customer 
string $newPassword
Returns:
this

Definition at line 194 of file Customer.php.

00195     {
00196         $customer->setPassword($newPassword);
00197         $this->saveAttribute($customer, 'password_hash');
00198         return $this;
00199     }

checkCustomerId ( customerId  ) 

Check customer by id

Parameters:
int $customerId
Returns:
bool

Definition at line 224 of file Customer.php.

00225     {
00226         $select = $this->_getReadAdapter()->select()
00227             ->from($this->getTable('customer/entity'), 'entity_id')
00228             ->where('entity_id=?', $customerId)
00229             ->limit(1);
00230         if ($this->_getReadAdapter()->fetchOne($select)) {
00231             return true;
00232         }
00233         return false;
00234     }

findEmailDuplicates (  ) 

Check whether there are email duplicates of customers in global scope

Returns:
bool

Definition at line 206 of file Customer.php.

00207     {
00208         $lookup = $this->_getReadAdapter()->fetchRow("SELECT email, COUNT(*) AS `qty`
00209             FROM `{$this->getTable('customer/entity')}`
00210             GROUP BY 1 ORDER BY 2 DESC LIMIT 1
00211         ");
00212         if (empty($lookup)) {
00213             return false;
00214         }
00215         return $lookup['qty'] > 1;
00216     }

loadByEmail ( Mage_Customer_Model_Customer customer,
email,
testOnly = false 
)

Load customer by email

Parameters:
Mage_Customer_Model_Customer $customer
string $email
bool $testOnly
Returns:
Mage_Customer_Model_Entity_Customer
Exceptions:
Mage_Core_Exception 

Definition at line 165 of file Customer.php.

00166     {
00167         $select = $this->_getReadAdapter()->select()
00168             ->from($this->getEntityTable(), array($this->getEntityIdField()))
00169             //->where('email=?', $email);
00170             ->where('email=:customer_email');
00171         if ($customer->getSharingConfig()->isWebsiteScope()) {
00172             if (!$customer->hasData('website_id')) {
00173                 Mage::throwException(Mage::helper('customer')->__('Customer website id must be specified, when using website scope.'));
00174             }
00175             $select->where('website_id=?', (int)$customer->getWebsiteId());
00176         }
00177 
00178         if ($id = $this->_getReadAdapter()->fetchOne($select, array('customer_email' => $email))) {
00179             $this->load($customer, $id);
00180         }
00181         else {
00182             $customer->setData(array());
00183         }
00184         return $this;
00185     }


The documentation for this class was generated from the following file:

Generated on Sat Jul 4 17:24:04 2009 for Magento by  doxygen 1.5.8