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_ImportExport_Adminhtml_ExportController
  • Mage_ImportExport_Adminhtml_ImportController
  • Mage_ImportExport_Block_Adminhtml_Export_Edit
  • Mage_ImportExport_Block_Adminhtml_Export_Edit_Form
  • Mage_ImportExport_Block_Adminhtml_Export_Filter
  • Mage_ImportExport_Block_Adminhtml_Import_Edit
  • Mage_ImportExport_Block_Adminhtml_Import_Edit_Form
  • Mage_ImportExport_Block_Adminhtml_Import_Frame_Result
  • Mage_ImportExport_Helper_Data
  • Mage_ImportExport_Model_Abstract
  • Mage_ImportExport_Model_Config
  • Mage_ImportExport_Model_Export
  • Mage_ImportExport_Model_Export_Adapter_Abstract
  • Mage_ImportExport_Model_Export_Adapter_Csv
  • Mage_ImportExport_Model_Export_Entity_Abstract
  • Mage_ImportExport_Model_Export_Entity_Customer
  • Mage_ImportExport_Model_Export_Entity_Product
  • Mage_ImportExport_Model_Export_Entity_Product_Type_Abstract
  • Mage_ImportExport_Model_Export_Entity_Product_Type_Configurable
  • Mage_ImportExport_Model_Export_Entity_Product_Type_Grouped
  • Mage_ImportExport_Model_Export_Entity_Product_Type_Simple
  • Mage_ImportExport_Model_Import
  • Mage_ImportExport_Model_Import_Adapter
  • Mage_ImportExport_Model_Import_Adapter_Abstract
  • Mage_ImportExport_Model_Import_Adapter_Csv
  • Mage_ImportExport_Model_Import_Entity_Abstract
  • Mage_ImportExport_Model_Import_Entity_Customer
  • Mage_ImportExport_Model_Import_Entity_Customer_Address
  • Mage_ImportExport_Model_Import_Entity_Product
  • Mage_ImportExport_Model_Import_Entity_Product_Type_Abstract
  • Mage_ImportExport_Model_Import_Entity_Product_Type_Configurable
  • Mage_ImportExport_Model_Import_Entity_Product_Type_Grouped
  • Mage_ImportExport_Model_Import_Entity_Product_Type_Simple
  • Mage_ImportExport_Model_Import_Proxy_Product
  • Mage_ImportExport_Model_Import_Proxy_Product_Resource
  • Mage_ImportExport_Model_Import_Uploader
  • Mage_ImportExport_Model_Mysql4_Import_Data
  • Mage_ImportExport_Model_Mysql4_Setup
  • Mage_ImportExport_Model_Resource_Import_Data
  • Mage_ImportExport_Model_Resource_Setup
  • Mage_ImportExport_Model_Source_Export_Entity
  • Mage_ImportExport_Model_Source_Export_Format
  • Mage_ImportExport_Model_Source_Import_Behavior
  • Mage_ImportExport_Model_Source_Import_Entity
  • 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_ImportExport
 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:  * Import entity customer model
 29:  *
 30:  * @category    Mage
 31:  * @package     Mage_ImportExport
 32:  * @author      Magento Core Team <core@magentocommerce.com>
 33:  */
 34: class Mage_ImportExport_Model_Import_Entity_Customer extends Mage_ImportExport_Model_Import_Entity_Abstract
 35: {
 36:     /**
 37:      * Size of bunch - part of entities to save in one step.
 38:      */
 39:     const BUNCH_SIZE = 20;
 40: 
 41:     /**
 42:      * Data row scopes.
 43:      */
 44:     const SCOPE_DEFAULT = 1;
 45:     const SCOPE_ADDRESS = -1;
 46: 
 47:     /**
 48:      * Permanent column names.
 49:      *
 50:      * Names that begins with underscore is not an attribute. This name convention is for
 51:      * to avoid interference with same attribute name.
 52:      */
 53:     const COL_EMAIL   = 'email';
 54:     const COL_WEBSITE = '_website';
 55:     const COL_STORE   = '_store';
 56: 
 57:     /**
 58:      * Error codes.
 59:      */
 60:     const ERROR_INVALID_WEBSITE      = 'invalidWebsite';
 61:     const ERROR_INVALID_EMAIL        = 'invalidEmail';
 62:     const ERROR_DUPLICATE_EMAIL_SITE = 'duplicateEmailSite';
 63:     const ERROR_EMAIL_IS_EMPTY       = 'emailIsEmpty';
 64:     const ERROR_ROW_IS_ORPHAN        = 'rowIsOrphan';
 65:     const ERROR_VALUE_IS_REQUIRED    = 'valueIsRequired';
 66:     const ERROR_INVALID_STORE        = 'invalidStore';
 67:     const ERROR_EMAIL_SITE_NOT_FOUND = 'emailSiteNotFound';
 68:     const ERROR_PASSWORD_LENGTH      = 'passwordLength';
 69: 
 70:     /**
 71:      * Customer constants
 72:      *
 73:      */
 74:     const DEFAULT_GROUP_ID = 1;
 75:     const MAX_PASSWD_LENGTH = 6;
 76: 
 77:     /**
 78:      * Customer address import entity model.
 79:      *
 80:      * @var Mage_ImportExport_Model_Import_Entity_Customer_Address
 81:      */
 82:     protected $_addressEntity;
 83: 
 84:     /**
 85:      * Customer attributes parameters.
 86:      *
 87:      *  [attr_code_1] => array(
 88:      *      'options' => array(),
 89:      *      'type' => 'text', 'price', 'textarea', 'select', etc.
 90:      *      'id' => ..
 91:      *  ),
 92:      *  ...
 93:      *
 94:      * @var array
 95:      */
 96:     protected $_attributes = array();
 97: 
 98:     /**
 99:      * Customer account sharing. TRUE - is global, FALSE - is per website.
100:      *
101:      * @var boolean
102:      */
103:     protected $_customerGlobal;
104: 
105:     /**
106:      * Customer groups ID-to-name.
107:      *
108:      * @var array
109:      */
110:     protected $_customerGroups = array();
111: 
112:     /**
113:      * Customer entity DB table name.
114:      *
115:      * @var string
116:      */
117:     protected $_entityTable;
118: 
119:     /**
120:      * Array of attribute codes which will be ignored in validation and import procedures.
121:      * For example, when entity attribute has own validation and import procedures
122:      * or just to deny this attribute processing.
123:      *
124:      * @var array
125:      */
126:     protected $_ignoredAttributes = array('website_id', 'store_id', 'default_billing', 'default_shipping');
127: 
128:     /**
129:      * Attributes with index (not label) value.
130:      *
131:      * @var array
132:      */
133:     protected $_indexValueAttributes = array('group_id');
134: 
135:     /**
136:      * Validation failure message template definitions
137:      *
138:      * @var array
139:      */
140:     protected $_messageTemplates = array(
141:         self::ERROR_INVALID_WEBSITE      => 'Invalid value in Website column (website does not exists?)',
142:         self::ERROR_INVALID_EMAIL        => 'E-mail is invalid',
143:         self::ERROR_DUPLICATE_EMAIL_SITE => 'E-mail is duplicated in import file',
144:         self::ERROR_EMAIL_IS_EMPTY       => 'E-mail is not specified',
145:         self::ERROR_ROW_IS_ORPHAN        => 'Orphan rows that will be skipped due default row errors',
146:         self::ERROR_VALUE_IS_REQUIRED    => "Required attribute '%s' has an empty value",
147:         self::ERROR_INVALID_STORE        => 'Invalid value in Store column (store does not exists?)',
148:         self::ERROR_EMAIL_SITE_NOT_FOUND => 'E-mail and website combination is not found',
149:         self::ERROR_PASSWORD_LENGTH      => 'Invalid password length'
150:     );
151: 
152:     /**
153:      * Dry-runned customers information from import file.
154:      *
155:      * @var array
156:      */
157:     protected $_newCustomers = array();
158: 
159:     /**
160:      * Existing customers information. In form of:
161:      *
162:      * [customer e-mail] => array(
163:      *    [website code 1] => customer_id 1,
164:      *    [website code 2] => customer_id 2,
165:      *           ...       =>     ...      ,
166:      *    [website code n] => customer_id n,
167:      * )
168:      *
169:      * @var array
170:      */
171:     protected $_oldCustomers = array();
172: 
173:     /**
174:      * Column names that holds values with particular meaning.
175:      *
176:      * @var array
177:      */
178:     protected $_particularAttributes = array(self::COL_WEBSITE, self::COL_STORE);
179: 
180:     /**
181:      * Permanent entity columns.
182:      *
183:      * @var array
184:      */
185:     protected $_permanentAttributes = array(self::COL_EMAIL, self::COL_WEBSITE);
186: 
187:     /**
188:      * All stores code-ID pairs.
189:      *
190:      * @var array
191:      */
192:     protected $_storeCodeToId = array();
193: 
194:     /**
195:      * Website code-to-ID
196:      *
197:      * @var array
198:      */
199:     protected $_websiteCodeToId = array();
200: 
201:     /**
202:      * Website ID-to-code
203:      *
204:      * @var array
205:      */
206:     protected $_websiteIdToCode = array();
207: 
208:     /**
209:      * Constructor.
210:      *
211:      * @return void
212:      */
213:     public function __construct()
214:     {
215:         parent::__construct();
216: 
217:         $this->_initWebsites()
218:             ->_initStores()
219:             ->_initCustomerGroups()
220:             ->_initAttributes()
221:             ->_initCustomers();
222: 
223:         $this->_entityTable   = Mage::getModel('customer/customer')->getResource()->getEntityTable();
224:         $this->_addressEntity = Mage::getModel('importexport/import_entity_customer_address', $this);
225:     }
226: 
227:     /**
228:      * Delete customers.
229:      *
230:      * @return Mage_ImportExport_Model_Import_Entity_Customer
231:      */
232:     protected function _deleteCustomers()
233:     {
234:         while ($bunch = $this->_dataSourceModel->getNextBunch()) {
235:             $idToDelete = array();
236: 
237:             foreach ($bunch as $rowNum => $rowData) {
238:                 if (self::SCOPE_DEFAULT == $this->getRowScope($rowData) && $this->validateRow($rowData, $rowNum)) {
239:                     $idToDelete[] = $this->_oldCustomers[$rowData[self::COL_EMAIL]][$rowData[self::COL_WEBSITE]];
240:                 }
241:             }
242:             if ($idToDelete) {
243:                 $this->_connection->query(
244:                     $this->_connection->quoteInto(
245:                         "DELETE FROM `{$this->_entityTable}` WHERE `entity_id` IN (?)", $idToDelete
246:                     )
247:                 );
248:             }
249:         }
250:         return $this;
251:     }
252: 
253:     /**
254:      * Save customer data to DB.
255:      *
256:      * @throws Exception
257:      * @return bool Result of operation.
258:      */
259:     protected function _importData()
260:     {
261:         if (Mage_ImportExport_Model_Import::BEHAVIOR_DELETE == $this->getBehavior()) {
262:             $this->_deleteCustomers();
263:         } else {
264:             $this->_saveCustomers();
265:             $this->_addressEntity->importData();
266:         }
267:         return true;
268:     }
269: 
270:     /**
271:      * Initialize customer attributes.
272:      *
273:      * @return Mage_ImportExport_Model_Import_Entity_Customer
274:      */
275:     protected function _initAttributes()
276:     {
277:         $collection = Mage::getResourceModel('customer/attribute_collection')->addSystemHiddenFilterWithPasswordHash();
278:         foreach ($collection as $attribute) {
279:             $this->_attributes[$attribute->getAttributeCode()] = array(
280:                 'id'          => $attribute->getId(),
281:                 'is_required' => $attribute->getIsRequired(),
282:                 'is_static'   => $attribute->isStatic(),
283:                 'rules'       => $attribute->getValidateRules() ? unserialize($attribute->getValidateRules()) : null,
284:                 'type'        => Mage_ImportExport_Model_Import::getAttributeType($attribute),
285:                 'options'     => $this->getAttributeOptions($attribute)
286:             );
287:         }
288:         return $this;
289:     }
290: 
291:     /**
292:      * Initialize customer groups.
293:      *
294:      * @return Mage_ImportExport_Model_Import_Entity_Customer
295:      */
296:     protected function _initCustomerGroups()
297:     {
298:         foreach (Mage::getResourceModel('customer/group_collection') as $customerGroup) {
299:             $this->_customerGroups[$customerGroup->getId()] = true;
300:         }
301:         return $this;
302:     }
303: 
304:     /**
305:      * Initialize existent customers data.
306:      *
307:      * @return Mage_ImportExport_Model_Import_Entity_Customer
308:      */
309:     protected function _initCustomers()
310:     {
311:         foreach (Mage::getResourceModel('customer/customer_collection') as $customer) {
312:             $email = $customer->getEmail();
313: 
314:             if (!isset($this->_oldCustomers[$email])) {
315:                 $this->_oldCustomers[$email] = array();
316:             }
317:             $this->_oldCustomers[$email][$this->_websiteIdToCode[$customer->getWebsiteId()]] = $customer->getId();
318:         }
319:         $this->_customerGlobal = Mage::getModel('customer/customer')->getSharingConfig()->isGlobalScope();
320: 
321:         return $this;
322:     }
323: 
324:     /**
325:      * Initialize stores hash.
326:      *
327:      * @return Mage_ImportExport_Model_Import_Entity_Customer
328:      */
329:     protected function _initStores()
330:     {
331:         foreach (Mage::app()->getStores(true) as $store) {
332:             $this->_storeCodeToId[$store->getCode()] = $store->getId();
333:         }
334:         return $this;
335:     }
336: 
337:     /**
338:      * Initialize website values.
339:      *
340:      * @return Mage_ImportExport_Model_Import_Entity_Customer
341:      */
342:     protected function _initWebsites()
343:     {
344:         /** @var $website Mage_Core_Model_Website */
345:         foreach (Mage::app()->getWebsites(true) as $website) {
346:             $this->_websiteCodeToId[$website->getCode()] = $website->getId();
347:             $this->_websiteIdToCode[$website->getId()]   = $website->getCode();
348:         }
349:         return $this;
350:     }
351: 
352:     /**
353:      * Gather and save information about customer entities.
354:      *
355:      * @return Mage_ImportExport_Model_Import_Entity_Customer
356:      */
357:     protected function _saveCustomers()
358:     {
359:         /** @var $resource Mage_Customer_Model_Customer */
360:         $resource       = Mage::getModel('customer/customer');
361:         $strftimeFormat = Varien_Date::convertZendToStrftime(Varien_Date::DATETIME_INTERNAL_FORMAT, true, true);
362:         $table = $resource->getResource()->getEntityTable();
363:         $nextEntityId   = Mage::getResourceHelper('importexport')->getNextAutoincrement($table);
364:         $passId         = $resource->getAttribute('password_hash')->getId();
365:         $passTable      = $resource->getAttribute('password_hash')->getBackend()->getTable();
366: 
367:         while ($bunch = $this->_dataSourceModel->getNextBunch()) {
368:             $entityRowsIn = array();
369:             $entityRowsUp = array();
370:             $attributes   = array();
371: 
372:             foreach ($bunch as $rowNum => $rowData) {
373:                 if (!$this->validateRow($rowData, $rowNum)) {
374:                     continue;
375:                 }
376:                 if (self::SCOPE_DEFAULT == $this->getRowScope($rowData)) {
377:                     // entity table data
378:                     $entityRow = array(
379:                         'group_id'   => empty($rowData['group_id']) ? self::DEFAULT_GROUP_ID : $rowData['group_id'],
380:                         'store_id'   => empty($rowData[self::COL_STORE])
381:                                         ? 0 : $this->_storeCodeToId[$rowData[self::COL_STORE]],
382:                         'created_at' => empty($rowData['created_at'])
383:                                         ? now() : gmstrftime($strftimeFormat, strtotime($rowData['created_at'])),
384:                         'updated_at' => now()
385:                     );
386:                     if (isset($this->_oldCustomers[$rowData[self::COL_EMAIL]][$rowData[self::COL_WEBSITE]])) { // edit
387:                         $entityId = $this->_oldCustomers[$rowData[self::COL_EMAIL]][$rowData[self::COL_WEBSITE]];
388:                         $entityRow['entity_id'] = $entityId;
389:                         $entityRowsUp[] = $entityRow;
390:                     } else { // create
391:                         $entityId                      = $nextEntityId++;
392:                         $entityRow['entity_id']        = $entityId;
393:                         $entityRow['entity_type_id']   = $this->_entityTypeId;
394:                         $entityRow['attribute_set_id'] = 0;
395:                         $entityRow['website_id']       = $this->_websiteCodeToId[$rowData[self::COL_WEBSITE]];
396:                         $entityRow['email']            = $rowData[self::COL_EMAIL];
397:                         $entityRow['is_active']        = 1;
398:                         $entityRowsIn[]                = $entityRow;
399: 
400:                         $this->_newCustomers[$rowData[self::COL_EMAIL]][$rowData[self::COL_WEBSITE]] = $entityId;
401:                     }
402:                     // attribute values
403:                     foreach (array_intersect_key($rowData, $this->_attributes) as $attrCode => $value) {
404:                         if (!$this->_attributes[$attrCode]['is_static'] && strlen($value)) {
405:                             /** @var $attribute Mage_Customer_Model_Attribute */
406:                             $attribute  = $resource->getAttribute($attrCode);
407:                             $backModel  = $attribute->getBackendModel();
408:                             $attrParams = $this->_attributes[$attrCode];
409: 
410:                             if ('select' == $attrParams['type']) {
411:                                 $value = $attrParams['options'][strtolower($value)];
412:                             } elseif ('datetime' == $attrParams['type']) {
413:                                 $value = gmstrftime($strftimeFormat, strtotime($value));
414:                             } elseif ($backModel) {
415:                                 $attribute->getBackend()->beforeSave($resource->setData($attrCode, $value));
416:                                 $value = $resource->getData($attrCode);
417:                             }
418:                             $attributes[$attribute->getBackend()->getTable()][$entityId][$attrParams['id']] = $value;
419: 
420:                             // restore 'backend_model' to avoid default setting
421:                             $attribute->setBackendModel($backModel);
422:                         }
423:                     }
424:                     // password change/set
425:                     if (isset($rowData['password']) && strlen($rowData['password'])) {
426:                         $attributes[$passTable][$entityId][$passId] = $resource->hashPassword($rowData['password']);
427:                     }
428:                 }
429:             }
430:             $this->_saveCustomerEntity($entityRowsIn, $entityRowsUp)->_saveCustomerAttributes($attributes);
431:         }
432:         return $this;
433:     }
434: 
435:     /**
436:      * Save customer attributes.
437:      *
438:      * @param array $attributesData
439:      * @return Mage_ImportExport_Model_Import_Entity_Customer
440:      */
441:     protected function _saveCustomerAttributes(array $attributesData)
442:     {
443:         foreach ($attributesData as $tableName => $data) {
444:             $tableData = array();
445: 
446:             foreach ($data as $customerId => $attrData) {
447:                 foreach ($attrData as $attributeId => $value) {
448:                     $tableData[] = array(
449:                         'entity_id'      => $customerId,
450:                         'entity_type_id' => $this->_entityTypeId,
451:                         'attribute_id'   => $attributeId,
452:                         'value'          => $value
453:                     );
454:                 }
455:             }
456:             $this->_connection->insertOnDuplicate($tableName, $tableData, array('value'));
457:         }
458:         return $this;
459:     }
460: 
461:     /**
462:      * Update and insert data in entity table.
463:      *
464:      * @param array $entityRowsIn Row for insert
465:      * @param array $entityRowsUp Row for update
466:      * @return Mage_ImportExport_Model_Import_Entity_Customer
467:      */
468:     protected function _saveCustomerEntity(array $entityRowsIn, array $entityRowsUp)
469:     {
470:         if ($entityRowsIn) {
471:             $this->_connection->insertMultiple($this->_entityTable, $entityRowsIn);
472:         }
473:         if ($entityRowsUp) {
474:             $this->_connection->insertOnDuplicate(
475:                 $this->_entityTable,
476:                 $entityRowsUp,
477:                 array('group_id', 'store_id', 'updated_at', 'created_at')
478:             );
479:         }
480:         return $this;
481:     }
482: 
483:     /**
484:      * Get customer ID. Method tries to find ID from old and new customers. If it fails - it returns NULL.
485:      *
486:      * @param string $email
487:      * @param string $websiteCode
488:      * @return string|null
489:      */
490:     public function getCustomerId($email, $websiteCode)
491:     {
492:         if (isset($this->_oldCustomers[$email][$websiteCode])) {
493:             return $this->_oldCustomers[$email][$websiteCode];
494:         } elseif (isset($this->_newCustomers[$email][$websiteCode])) {
495:             return $this->_newCustomers[$email][$websiteCode];
496:         } else {
497:             return null;
498:         }
499:     }
500: 
501:     /**
502:      * EAV entity type code getter.
503:      *
504:      * @abstract
505:      * @return string
506:      */
507:     public function getEntityTypeCode()
508:     {
509:         return 'customer';
510:     }
511: 
512:     /**
513:      * Obtain scope of the row from row data.
514:      *
515:      * @param array $rowData
516:      * @return int
517:      */
518:     public function getRowScope(array $rowData)
519:     {
520:         return strlen(trim($rowData[self::COL_EMAIL])) ? self::SCOPE_DEFAULT : self::SCOPE_ADDRESS;
521:     }
522: 
523:     /**
524:      * Is attribute contains particular data (not plain entity attribute).
525:      *
526:      * @param string $attrCode
527:      * @return bool
528:      */
529:     public function isAttributeParticular($attrCode)
530:     {
531:         return parent::isAttributeParticular($attrCode) || $this->_addressEntity->isAttributeParticular($attrCode);
532:     }
533: 
534:     /**
535:      * Validate data row.
536:      *
537:      * @param array $rowData
538:      * @param int $rowNum
539:      * @return boolean
540:      */
541:     public function validateRow(array $rowData, $rowNum)
542:     {
543:         static $email   = null; // e-mail is remembered through all customer rows
544:         static $website = null; // website is remembered through all customer rows
545: 
546:         if (isset($this->_validatedRows[$rowNum])) { // check that row is already validated
547:             return !isset($this->_invalidRows[$rowNum]);
548:         }
549:         $this->_validatedRows[$rowNum] = true;
550: 
551:         $rowScope = $this->getRowScope($rowData);
552: 
553:         if (self::SCOPE_DEFAULT == $rowScope) {
554:             $this->_processedEntitiesCount ++;
555:         }
556:         // BEHAVIOR_DELETE use specific validation logic
557:         if (Mage_ImportExport_Model_Import::BEHAVIOR_DELETE == $this->getBehavior()) {
558:             if (self::SCOPE_DEFAULT == $rowScope
559:                     && !isset($this->_oldCustomers[$rowData[self::COL_EMAIL]][$rowData[self::COL_WEBSITE]])) {
560:                 $this->addRowError(self::ERROR_EMAIL_SITE_NOT_FOUND, $rowNum);
561:             }
562:         } elseif (self::SCOPE_DEFAULT == $rowScope) { // row is SCOPE_DEFAULT = new customer block begins
563:             $email   = $rowData[self::COL_EMAIL];
564:             $website = $rowData[self::COL_WEBSITE];
565: 
566:             if (!Zend_Validate::is($email, 'EmailAddress')) {
567:                 $this->addRowError(self::ERROR_INVALID_EMAIL, $rowNum);
568:             } elseif (!isset($this->_websiteCodeToId[$website])) {
569:                 $this->addRowError(self::ERROR_INVALID_WEBSITE, $rowNum);
570:             } else {
571:                 if (isset($this->_newCustomers[$email][$website])) {
572:                     $this->addRowError(self::ERROR_DUPLICATE_EMAIL_SITE, $rowNum);
573:                 }
574:                 $this->_newCustomers[$email][$website] = false;
575: 
576:                 if (!empty($rowData[self::COL_STORE]) && !isset($this->_storeCodeToId[$rowData[self::COL_STORE]])) {
577:                     $this->addRowError(self::ERROR_INVALID_STORE, $rowNum);
578:                 }
579:                 // check password
580:                 if (isset($rowData['password']) && strlen($rowData['password'])
581:                     && Mage::helper('core/string')->strlen($rowData['password']) < self::MAX_PASSWD_LENGTH
582:                 ) {
583:                     $this->addRowError(self::ERROR_PASSWORD_LENGTH, $rowNum);
584:                 }
585:                 // check simple attributes
586:                 foreach ($this->_attributes as $attrCode => $attrParams) {
587:                     if (in_array($attrCode, $this->_ignoredAttributes)) {
588:                         continue;
589:                     }
590:                     if (isset($rowData[$attrCode]) && strlen($rowData[$attrCode])) {
591:                         $this->isAttributeValid($attrCode, $attrParams, $rowData, $rowNum);
592:                     } elseif ($attrParams['is_required'] && !isset($this->_oldCustomers[$email][$website])) {
593:                         $this->addRowError(self::ERROR_VALUE_IS_REQUIRED, $rowNum, $attrCode);
594:                     }
595:                 }
596:             }
597:             if (isset($this->_invalidRows[$rowNum])) {
598:                 $email = false; // mark row as invalid for next address rows
599:             }
600:         } else {
601:             if (null === $email) { // first row is not SCOPE_DEFAULT
602:                 $this->addRowError(self::ERROR_EMAIL_IS_EMPTY, $rowNum);
603:             } elseif (false === $email) { // SCOPE_DEFAULT row is invalid
604:                 $this->addRowError(self::ERROR_ROW_IS_ORPHAN, $rowNum);
605:             }
606:         }
607:         // validate row data by address entity
608:         $this->_addressEntity->validateRow($rowData, $rowNum);
609: 
610:         return !isset($this->_invalidRows[$rowNum]);
611:     }
612: }
613: 
Magento 1.7.0.2 API documentation generated by ApiGen 2.8.0