Overview

Packages

  • currencysymbol
  • MAbout
  • Mage
    • Admin
    • Adminhtml
    • AdminNotification
    • Api
    • Api2
    • Authorizenet
    • Backup
    • Bundle
    • Captcha
    • Catalog
    • CatalogIndex
    • CatalogInventory
    • CatalogRule
    • CatalogSearch
    • Centinel
    • Checkout
    • Cms
    • Compiler
    • Connect
    • Contacts
    • Core
    • Cron
    • CurrencySymbol
    • Customer
    • Dataflow
    • Directory
    • DirtectPost
    • Downloadable
    • Eav
    • GiftMessage
    • GoogleAnalytics
    • GoogleBase
    • GoogleCheckout
    • ImportExport
    • Index
    • Install
    • Log
    • Media
    • Newsletter
    • Oauth
    • Page
    • PageCache
    • Paygate
    • Payment
    • Paypal
    • PaypalUk
    • Persistent
    • Poll
    • ProductAlert
    • Rating
    • Reports
    • Review
    • Rss
    • Rule
    • Sales
    • SalesRule
    • Sedfriend
    • Sendfriend
    • Shipping
    • Sitemap
    • Tag
    • Tax
    • Usa
    • Weee
    • Widget
    • Wishlist
    • XmlConnect
  • None
  • Phoenix
    • Moneybookers
  • PHP
  • Zend
    • Date
    • Mime
    • XmlRpc

Classes

  • Mage_Customer_AccountController
  • Mage_Customer_AddressController
  • Mage_Customer_Block_Account
  • Mage_Customer_Block_Account_Dashboard
  • Mage_Customer_Block_Account_Dashboard_Address
  • Mage_Customer_Block_Account_Dashboard_Block
  • Mage_Customer_Block_Account_Dashboard_Hello
  • Mage_Customer_Block_Account_Dashboard_Info
  • Mage_Customer_Block_Account_Dashboard_Newsletter
  • Mage_Customer_Block_Account_Dashboard_Sidebar
  • Mage_Customer_Block_Account_Forgotpassword
  • Mage_Customer_Block_Account_Navigation
  • Mage_Customer_Block_Account_Resetpassword
  • Mage_Customer_Block_Address_Book
  • Mage_Customer_Block_Address_Edit
  • Mage_Customer_Block_Address_Renderer_Default
  • Mage_Customer_Block_Form_Edit
  • Mage_Customer_Block_Form_Login
  • Mage_Customer_Block_Form_Register
  • Mage_Customer_Block_Newsletter
  • Mage_Customer_Block_Widget_Abstract
  • Mage_Customer_Block_Widget_Dob
  • Mage_Customer_Block_Widget_Gender
  • Mage_Customer_Block_Widget_Name
  • Mage_Customer_Block_Widget_Taxvat
  • Mage_Customer_Helper_Address
  • Mage_Customer_Helper_Data
  • Mage_Customer_Model_Address
  • Mage_Customer_Model_Address_Abstract
  • Mage_Customer_Model_Address_Api
  • Mage_Customer_Model_Address_Api_V2
  • Mage_Customer_Model_Address_Config
  • Mage_Customer_Model_Api2_Customer
  • Mage_Customer_Model_Api2_Customer_Address
  • Mage_Customer_Model_Api2_Customer_Address_Rest
  • Mage_Customer_Model_Api2_Customer_Address_Rest_Admin_V1
  • Mage_Customer_Model_Api2_Customer_Address_Rest_Customer_V1
  • Mage_Customer_Model_Api2_Customer_Address_Validator
  • Mage_Customer_Model_Api2_Customer_Rest
  • Mage_Customer_Model_Api2_Customer_Rest_Admin_V1
  • Mage_Customer_Model_Api2_Customer_Rest_Customer_V1
  • Mage_Customer_Model_Api_Resource
  • Mage_Customer_Model_Attribute
  • Mage_Customer_Model_Attribute_Backend_Data_Boolean
  • Mage_Customer_Model_Attribute_Data
  • Mage_Customer_Model_Attribute_Data_Abstract
  • Mage_Customer_Model_Attribute_Data_Boolean
  • Mage_Customer_Model_Attribute_Data_Date
  • Mage_Customer_Model_Attribute_Data_File
  • Mage_Customer_Model_Attribute_Data_Hidden
  • Mage_Customer_Model_Attribute_Data_Image
  • Mage_Customer_Model_Attribute_Data_Multiline
  • Mage_Customer_Model_Attribute_Data_Multiselect
  • Mage_Customer_Model_Attribute_Data_Postcode
  • Mage_Customer_Model_Attribute_Data_Select
  • Mage_Customer_Model_Attribute_Data_Text
  • Mage_Customer_Model_Attribute_Data_Textarea
  • Mage_Customer_Model_Config_Share
  • Mage_Customer_Model_Convert_Adapter_Customer
  • Mage_Customer_Model_Convert_Parser_Customer
  • Mage_Customer_Model_Customer
  • Mage_Customer_Model_Customer_Api
  • Mage_Customer_Model_Customer_Api_V2
  • Mage_Customer_Model_Customer_Attribute_Backend_Billing
  • Mage_Customer_Model_Customer_Attribute_Backend_Password
  • Mage_Customer_Model_Customer_Attribute_Backend_Shipping
  • Mage_Customer_Model_Customer_Attribute_Backend_Store
  • Mage_Customer_Model_Customer_Attribute_Backend_Website
  • Mage_Customer_Model_Customer_Attribute_Source_Group
  • Mage_Customer_Model_Customer_Attribute_Source_Store
  • Mage_Customer_Model_Customer_Attribute_Source_Website
  • Mage_Customer_Model_Entity_Address
  • Mage_Customer_Model_Entity_Address_Attribute_Backend_Region
  • Mage_Customer_Model_Entity_Address_Attribute_Backend_Street
  • Mage_Customer_Model_Entity_Address_Attribute_Collection
  • Mage_Customer_Model_Entity_Address_Attribute_Source_Country
  • Mage_Customer_Model_Entity_Address_Attribute_Source_Region
  • Mage_Customer_Model_Entity_Address_Collection
  • Mage_Customer_Model_Entity_Attribute
  • Mage_Customer_Model_Entity_Attribute_Collection
  • Mage_Customer_Model_Entity_Customer
  • Mage_Customer_Model_Entity_Customer_Collection
  • Mage_Customer_Model_Entity_Form_Attribute
  • Mage_Customer_Model_Entity_Form_Attribute_Collection
  • Mage_Customer_Model_Entity_Group
  • Mage_Customer_Model_Entity_Group_Collection
  • Mage_Customer_Model_Entity_Setup
  • Mage_Customer_Model_Entity_Wishlist_Collection
  • Mage_Customer_Model_Form
  • Mage_Customer_Model_Group
  • Mage_Customer_Model_Group_Api
  • Mage_Customer_Model_Group_Api_V2
  • Mage_Customer_Model_Observer
  • Mage_Customer_Model_Resource_Address
  • Mage_Customer_Model_Resource_Address_Attribute_Backend_Region
  • Mage_Customer_Model_Resource_Address_Attribute_Backend_Street
  • Mage_Customer_Model_Resource_Address_Attribute_Collection
  • Mage_Customer_Model_Resource_Address_Attribute_Source_Country
  • Mage_Customer_Model_Resource_Address_Attribute_Source_Region
  • Mage_Customer_Model_Resource_Address_Collection
  • Mage_Customer_Model_Resource_Attribute
  • Mage_Customer_Model_Resource_Attribute_Collection
  • Mage_Customer_Model_Resource_Customer
  • Mage_Customer_Model_Resource_Customer_Collection
  • Mage_Customer_Model_Resource_Form_Attribute
  • Mage_Customer_Model_Resource_Form_Attribute_Collection
  • Mage_Customer_Model_Resource_Group
  • Mage_Customer_Model_Resource_Group_Collection
  • Mage_Customer_Model_Resource_Setup
  • Mage_Customer_Model_Resource_Wishlist_Collection
  • Mage_Customer_Model_Session
  • Mage_Customer_ReviewController

Interfaces

  • Mage_Customer_Block_Address_Renderer_Interface

Exceptions

  • Mage_Customer_Exception
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: /**
  3:  * Magento
  4:  *
  5:  * NOTICE OF LICENSE
  6:  *
  7:  * This source file is subject to the Open Software License (OSL 3.0)
  8:  * that is bundled with this package in the file LICENSE.txt.
  9:  * It is also available through the world-wide-web at this URL:
 10:  * http://opensource.org/licenses/osl-3.0.php
 11:  * If you did not receive a copy of the license and are unable to
 12:  * obtain it through the world-wide-web, please send an email
 13:  * to license@magentocommerce.com so we can send you a copy immediately.
 14:  *
 15:  * DISCLAIMER
 16:  *
 17:  * Do not edit or add to this file if you wish to upgrade Magento to newer
 18:  * versions in the future. If you wish to customize Magento for your
 19:  * needs please refer to http://www.magentocommerce.com for more information.
 20:  *
 21:  * @category    Mage
 22:  * @package     Mage_Customer
 23:  * @copyright   Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
 24:  * @license     http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 25:  */
 26: 
 27: 
 28: /**
 29:  * Customer entity resource model
 30:  *
 31:  * @category    Mage
 32:  * @package     Mage_Customer
 33:  * @author      Magento Core Team <core@magentocommerce.com>
 34:  */
 35: class Mage_Customer_Model_Resource_Customer extends Mage_Eav_Model_Entity_Abstract
 36: {
 37:     /**
 38:      * Resource initialization
 39:      */
 40:     public function __construct()
 41:     {
 42:         $this->setType('customer');
 43:         $this->setConnection('customer_read', 'customer_write');
 44:     }
 45: 
 46:     /**
 47:      * Retrieve customer entity default attributes
 48:      *
 49:      * @return array
 50:      */
 51:     protected function _getDefaultAttributes()
 52:     {
 53:         return array(
 54:             'entity_type_id',
 55:             'attribute_set_id',
 56:             'created_at',
 57:             'updated_at',
 58:             'increment_id',
 59:             'store_id',
 60:             'website_id'
 61:         );
 62:     }
 63: 
 64:     /**
 65:      * Check customer scope, email and confirmation key before saving
 66:      *
 67:      * @param Mage_Customer_Model_Customer $customer
 68:      * @throws Mage_Customer_Exception
 69:      * @return Mage_Customer_Model_Resource_Customer
 70:      */
 71:     protected function _beforeSave(Varien_Object $customer)
 72:     {
 73:         parent::_beforeSave($customer);
 74: 
 75:         if (!$customer->getEmail()) {
 76:             throw Mage::exception('Mage_Customer', Mage::helper('customer')->__('Customer email is required'));
 77:         }
 78: 
 79:         $adapter = $this->_getWriteAdapter();
 80:         $bind    = array('email' => $customer->getEmail());
 81: 
 82:         $select = $adapter->select()
 83:             ->from($this->getEntityTable(), array($this->getEntityIdField()))
 84:             ->where('email = :email');
 85:         if ($customer->getSharingConfig()->isWebsiteScope()) {
 86:             $bind['website_id'] = (int)$customer->getWebsiteId();
 87:             $select->where('website_id = :website_id');
 88:         }
 89:         if ($customer->getId()) {
 90:             $bind['entity_id'] = (int)$customer->getId();
 91:             $select->where('entity_id != :entity_id');
 92:         }
 93: 
 94:         $result = $adapter->fetchOne($select, $bind);
 95:         if ($result) {
 96:             throw Mage::exception(
 97:                 'Mage_Customer', Mage::helper('customer')->__('This customer email already exists'),
 98:                 Mage_Customer_Model_Customer::EXCEPTION_EMAIL_EXISTS
 99:             );
100:         }
101: 
102:         // set confirmation key logic
103:         if ($customer->getForceConfirmed()) {
104:             $customer->setConfirmation(null);
105:         } elseif (!$customer->getId() && $customer->isConfirmationRequired()) {
106:             $customer->setConfirmation($customer->getRandomConfirmationKey());
107:         }
108:         // remove customer confirmation key from database, if empty
109:         if (!$customer->getConfirmation()) {
110:             $customer->setConfirmation(null);
111:         }
112: 
113:         return $this;
114:     }
115: 
116:     /**
117:      * Save customer addresses and set default addresses in attributes backend
118:      *
119:      * @param Varien_Object $customer
120:      * @return Mage_Eav_Model_Entity_Abstract
121:      */
122:     protected function _afterSave(Varien_Object $customer)
123:     {
124:         $this->_saveAddresses($customer);
125:         return parent::_afterSave($customer);
126:     }
127: 
128:     /**
129:      * Save/delete customer address
130:      *
131:      * @param Mage_Customer_Model_Customer $customer
132:      * @return Mage_Customer_Model_Resource_Customer
133:      */
134:     protected function _saveAddresses(Mage_Customer_Model_Customer $customer)
135:     {
136:         $defaultBillingId   = $customer->getData('default_billing');
137:         $defaultShippingId  = $customer->getData('default_shipping');
138:         foreach ($customer->getAddresses() as $address) {
139:             if ($address->getData('_deleted')) {
140:                 if ($address->getId() == $defaultBillingId) {
141:                     $customer->setData('default_billing', null);
142:                 }
143:                 if ($address->getId() == $defaultShippingId) {
144:                     $customer->setData('default_shipping', null);
145:                 }
146:                 $address->delete();
147:             } else {
148:                 $address->setParentId($customer->getId())
149:                     ->setStoreId($customer->getStoreId())
150:                     ->setIsCustomerSaveTransaction(true)
151:                     ->save();
152:                 if (($address->getIsPrimaryBilling() || $address->getIsDefaultBilling())
153:                     && $address->getId() != $defaultBillingId
154:                 ) {
155:                     $customer->setData('default_billing', $address->getId());
156:                 }
157:                 if (($address->getIsPrimaryShipping() || $address->getIsDefaultShipping())
158:                     && $address->getId() != $defaultShippingId
159:                 ) {
160:                     $customer->setData('default_shipping', $address->getId());
161:                 }
162:             }
163:         }
164:         if ($customer->dataHasChangedFor('default_billing')) {
165:             $this->saveAttribute($customer, 'default_billing');
166:         }
167:         if ($customer->dataHasChangedFor('default_shipping')) {
168:             $this->saveAttribute($customer, 'default_shipping');
169:         }
170: 
171:         return $this;
172:     }
173: 
174:     /**
175:      * Retrieve select object for loading base entity row
176:      *
177:      * @param Varien_Object $object
178:      * @param mixed $rowId
179:      * @return Varien_Db_Select
180:      */
181:     protected function _getLoadRowSelect($object, $rowId)
182:     {
183:         $select = parent::_getLoadRowSelect($object, $rowId);
184:         if ($object->getWebsiteId() && $object->getSharingConfig()->isWebsiteScope()) {
185:             $select->where('website_id =?', (int)$object->getWebsiteId());
186:         }
187: 
188:         return $select;
189:     }
190: 
191:     /**
192:      * Load customer by email
193:      *
194:      * @throws Mage_Core_Exception
195:      *
196:      * @param Mage_Customer_Model_Customer $customer
197:      * @param string $email
198:      * @param bool $testOnly
199:      * @return Mage_Customer_Model_Resource_Customer
200:      */
201:     public function loadByEmail(Mage_Customer_Model_Customer $customer, $email, $testOnly = false)
202:     {
203:         $adapter = $this->_getReadAdapter();
204:         $bind    = array('customer_email' => $email);
205:         $select  = $adapter->select()
206:             ->from($this->getEntityTable(), array($this->getEntityIdField()))
207:             ->where('email = :customer_email');
208: 
209:         if ($customer->getSharingConfig()->isWebsiteScope()) {
210:             if (!$customer->hasData('website_id')) {
211:                 Mage::throwException(
212:                     Mage::helper('customer')->__('Customer website ID must be specified when using the website scope')
213:                 );
214:             }
215:             $bind['website_id'] = (int)$customer->getWebsiteId();
216:             $select->where('website_id = :website_id');
217:         }
218: 
219:         $customerId = $adapter->fetchOne($select, $bind);
220:         if ($customerId) {
221:             $this->load($customer, $customerId);
222:         } else {
223:             $customer->setData(array());
224:         }
225: 
226:         return $this;
227:     }
228: 
229:     /**
230:      * Change customer password
231:      *
232:      * @param Mage_Customer_Model_Customer $customer
233:      * @param string $newPassword
234:      * @return Mage_Customer_Model_Resource_Customer
235:      */
236:     public function changePassword(Mage_Customer_Model_Customer $customer, $newPassword)
237:     {
238:         $customer->setPassword($newPassword);
239:         $this->saveAttribute($customer, 'password_hash');
240:         return $this;
241:     }
242: 
243:     /**
244:      * Check whether there are email duplicates of customers in global scope
245:      *
246:      * @return bool
247:      */
248:     public function findEmailDuplicates()
249:     {
250:         $adapter = $this->_getReadAdapter();
251:         $select  = $adapter->select()
252:             ->from($this->getTable('customer/entity'), array('email', 'cnt' => 'COUNT(*)'))
253:             ->group('email')
254:             ->order('cnt DESC')
255:             ->limit(1);
256:         $lookup = $adapter->fetchRow($select);
257:         if (empty($lookup)) {
258:             return false;
259:         }
260:         return $lookup['cnt'] > 1;
261:     }
262: 
263:     /**
264:      * Check customer by id
265:      *
266:      * @param int $customerId
267:      * @return bool
268:      */
269:     public function checkCustomerId($customerId)
270:     {
271:         $adapter = $this->_getReadAdapter();
272:         $bind    = array('entity_id' => (int)$customerId);
273:         $select  = $adapter->select()
274:             ->from($this->getTable('customer/entity'), 'entity_id')
275:             ->where('entity_id = :entity_id')
276:             ->limit(1);
277: 
278:         $result = $adapter->fetchOne($select, $bind);
279:         if ($result) {
280:             return true;
281:         }
282:         return false;
283:     }
284: 
285:     /**
286:      * Get customer website id
287:      *
288:      * @param int $customerId
289:      * @return int
290:      */
291:     public function getWebsiteId($customerId)
292:     {
293:         $adapter = $this->_getReadAdapter();
294:         $bind    = array('entity_id' => (int)$customerId);
295:         $select  = $adapter->select()
296:             ->from($this->getTable('customer/entity'), 'website_id')
297:             ->where('entity_id = :entity_id');
298: 
299:         return $adapter->fetchOne($select, $bind);
300:     }
301: 
302:     /**
303:      * Custom setter of increment ID if its needed
304:      *
305:      * @param Varien_Object $object
306:      * @return Mage_Customer_Model_Resource_Customer
307:      */
308:     public function setNewIncrementId(Varien_Object $object)
309:     {
310:         if (Mage::getStoreConfig(Mage_Customer_Model_Customer::XML_PATH_GENERATE_HUMAN_FRIENDLY_ID)) {
311:             parent::setNewIncrementId($object);
312:         }
313:         return $this;
314:     }
315: 
316:     /**
317:      * Change reset password link token
318:      *
319:      * Stores new reset password link token and its creation time
320:      *
321:      * @param Mage_Customer_Model_Customer $newResetPasswordLinkToken
322:      * @param string $newResetPasswordLinkToken
323:      * @return Mage_Customer_Model_Resource_Customer
324:      */
325:     public function changeResetPasswordLinkToken(Mage_Customer_Model_Customer $customer, $newResetPasswordLinkToken) {
326:         if (is_string($newResetPasswordLinkToken) && !empty($newResetPasswordLinkToken)) {
327:             $customer->setRpToken($newResetPasswordLinkToken);
328:             $currentDate = Varien_Date::now();
329:             $customer->setRpTokenCreatedAt($currentDate);
330:             $this->saveAttribute($customer, 'rp_token');
331:             $this->saveAttribute($customer, 'rp_token_created_at');
332:         }
333:         return $this;
334:     }
335: }
336: 
Magento 1.7.0.2 API documentation generated by ApiGen 2.8.0