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: class Mage_Customer_Model_Convert_Adapter_Customer
 29:     extends Mage_Eav_Model_Convert_Adapter_Entity
 30: {
 31:     const MULTI_DELIMITER = ' , ';
 32: 
 33:     /**
 34:      * Customer model
 35:      *
 36:      * @var Mage_Customer_Model_Customer
 37:      */
 38:     protected $_customerModel;
 39:     protected $_stores;
 40:     protected $_attributes = array();
 41:     protected $_customerGroups;
 42: 
 43:     protected $_billingAddressModel;
 44:     protected $_shippingAddressModel;
 45: 
 46:     protected $_requiredFields = array();
 47: 
 48:     protected $_ignoreFields = array();
 49: 
 50:     protected $_billingFields = array();
 51: 
 52:     protected $_billingMappedFields = array();
 53: 
 54:     protected $_billingStreetFields = array();
 55: 
 56:     protected $_billingRequiredFields = array();
 57: 
 58:     protected $_shippingFields = array();
 59: 
 60:     protected $_shippingMappedFields = array();
 61: 
 62:     protected $_shippingStreetFields= array();
 63: 
 64:     protected $_shippingRequiredFields = array();
 65: 
 66:     protected $_addressFields = array();
 67: 
 68:     protected $_regions;
 69:     protected $_websites;
 70: 
 71:     protected $_customer = null;
 72:     protected $_address = null;
 73: 
 74:     protected $_customerId = '';
 75: 
 76:     /**
 77:      * Retrieve customer model cache
 78:      *
 79:      * @return Mage_Customer_Model_Customer
 80:      */
 81:     public function getCustomerModel()
 82:     {
 83:         if (is_null($this->_customerModel)) {
 84:             $object = Mage::getModel('customer/customer');
 85:             $this->_customerModel = Mage::objects()->save($object);
 86:         }
 87:         return Mage::objects()->load($this->_customerModel);
 88:     }
 89: 
 90:     /**
 91:      * Retrieve customer address model cache
 92:      *
 93:      * @return Mage_Customer_Model_Address
 94:      */
 95:     public function getBillingAddressModel()
 96:     {
 97:         if (is_null($this->_billingAddressModel)) {
 98:             $object = Mage::getModel('customer/address');
 99:             $this->_billingAddressModel = Mage::objects()->save($object);
100:         }
101:         return Mage::objects()->load($this->_billingAddressModel);
102:     }
103: 
104:     /**
105:      * Retrieve customer address model cache
106:      *
107:      * @return Mage_Customer_Model_Address
108:      */
109:     public function getShippingAddressModel()
110:     {
111:         if (is_null($this->_shippingAddressModel)) {
112:             $object = Mage::getModel('customer/address');
113:             $this->_shippingAddressModel = Mage::objects()->save($object);
114:         }
115:         return Mage::objects()->load($this->_shippingAddressModel);
116:     }
117: 
118:     /**
119:      * Retrieve store object by code
120:      *
121:      * @param string $store
122:      * @return Mage_Core_Model_Store
123:      */
124:     public function getStoreByCode($store)
125:     {
126:         if (is_null($this->_stores)) {
127:             $this->_stores = Mage::app()->getStores(true, true);
128:         }
129:         if (isset($this->_stores[$store])) {
130:             return $this->_stores[$store];
131:         }
132:         return false;
133:     }
134: 
135:     /**
136:      * Retrieve website model by code
137:      *
138:      * @param int $websiteId
139:      * @return Mage_Core_Model_Website
140:      */
141:     public function getWebsiteByCode($websiteCode)
142:     {
143:         if (is_null($this->_websites)) {
144:             $this->_websites = Mage::app()->getWebsites(true, true);
145:         }
146:         if (isset($this->_websites[$websiteCode])) {
147:             return $this->_websites[$websiteCode];
148:         }
149:         return false;
150:     }
151: 
152:     /**
153:      * Retrieve eav entity attribute model
154:      *
155:      * @param string $code
156:      * @return Mage_Eav_Model_Entity_Attribute
157:      */
158:     public function getAttribute($code)
159:     {
160:         if (!isset($this->_attributes[$code])) {
161:             $this->_attributes[$code] = $this->getCustomerModel()->getResource()->getAttribute($code);
162:         }
163:         return $this->_attributes[$code];
164:     }
165: 
166:     /**
167:      * Retrieve region id by country code and region name (if exists)
168:      *
169:      * @param string $country
170:      * @param string $region
171:      * @return int
172:      */
173:     public function getRegionId($country, $regionName)
174:     {
175:         if (is_null($this->_regions)) {
176:             $this->_regions = array();
177: 
178:             $collection = Mage::getModel('directory/region')
179:                 ->getCollection();
180:             foreach ($collection as $region) {
181:                 if (!isset($this->_regions[$region->getCountryId()])) {
182:                     $this->_regions[$region->getCountryId()] = array();
183:                 }
184: 
185:                 $this->_regions[$region->getCountryId()][$region->getDefaultName()] = $region->getId();
186:             }
187:         }
188: 
189:         if (isset($this->_regions[$country][$regionName])) {
190:             return $this->_regions[$country][$regionName];
191:         }
192: 
193:         return 0;
194:     }
195: 
196:     /**
197:      * Retrieve customer group collection array
198:      *
199:      * @return array
200:      */
201:     public function getCustomerGroups()
202:     {
203:         if (is_null($this->_customerGroups)) {
204:             $this->_customerGroups = array();
205:             $collection = Mage::getModel('customer/group')
206:                 ->getCollection()
207:                 ->addFieldToFilter('customer_group_id', array('gt'=> 0));
208:             foreach ($collection as $group) {
209:                 $this->_customerGroups[$group->getCustomerGroupCode()] = $group->getId();
210:             }
211:         }
212:         return $this->_customerGroups;
213:     }
214: 
215:     /**
216:      * Alias at getCustomerGroups()
217:      *
218:      * @return array
219:      */
220:     public function getCustomerGoups()
221:     {
222:         return $this->getCustomerGroups();
223:     }
224: 
225:     public function __construct()
226:     {
227:         $this->setVar('entity_type', 'customer/customer');
228: 
229:         if (!Mage::registry('Object_Cache_Customer')) {
230:             $this->setCustomer(Mage::getModel('customer/customer'));
231:         }
232:         //$this->setAddress(Mage::getModel('catalog/'))
233: 
234:         foreach (Mage::getConfig()->getFieldset('customer_dataflow', 'admin') as $code=>$node) {
235:             if ($node->is('ignore')) {
236:                 $this->_ignoreFields[] = $code;
237:             }
238:             if ($node->is('billing')) {
239:                 $this->_billingFields[] = 'billing_'.$code;
240:             }
241:             if ($node->is('shipping')) {
242:                 $this->_shippingFields[] = 'shipping_'.$code;
243:             }
244: 
245:             if ($node->is('billing') && $node->is('shipping')) {
246:                 $this->_addressFields[] = $code;
247:             }
248: 
249:             if ($node->is('mapped') || $node->is('billing_mapped')) {
250:                 $this->_billingMappedFields['billing_'.$code] = $code;
251:             }
252:             if ($node->is('mapped') || $node->is('shipping_mapped')) {
253:                 $this->_shippingMappedFields['shipping_'.$code] = $code;
254:             }
255:             if ($node->is('street')) {
256:                 $this->_billingStreetFields[] = 'billing_'.$code;
257:                 $this->_shippingStreetFields[] = 'shipping_'.$code;
258:             }
259:             if ($node->is('required')) {
260:                 $this->_requiredFields[] = $code;
261:             }
262:             if ($node->is('billing_required')) {
263:                 $this->_billingRequiredFields[] = 'billing_'.$code;
264:             }
265:             if ($node->is('shipping_required')) {
266:                 $this->_shippingRequiredFields[] = 'shipping_'.$code;
267:             }
268:         }
269:     }
270: 
271:     public function load()
272:     {
273:         $addressType = $this->getVar('filter/adressType'); //error in key filter addressType
274:         if ($addressType=='both') {
275:            $addressType = array('default_billing','default_shipping');
276:         }
277:         $attrFilterArray = array();
278:         $attrFilterArray ['firstname']                  = 'like';
279:         $attrFilterArray ['lastname']                   = 'like';
280:         $attrFilterArray ['email']                      = 'like';
281:         $attrFilterArray ['group']                      = 'eq';
282:         $attrFilterArray ['customer_address/telephone'] = array(
283:             'type'  => 'like',
284:             'bind'  => $addressType
285:         );
286:         $attrFilterArray ['customer_address/postcode']  = array(
287:             'type'  => 'like',
288:             'bind'  => $addressType
289:         );
290:         $attrFilterArray ['customer_address/country']   = array(
291:             'type'  => 'eq',
292:             'bind'  => $addressType
293:         );
294:         $attrFilterArray ['customer_address/region']    = array(
295:             'type'  => 'like',
296:             'bind'  => $addressType
297:         );
298:         $attrFilterArray ['created_at']                 = 'datetimeFromTo';
299: 
300:         /*
301:          * Fixing date filter from and to
302:          */
303:         if ($var = $this->getVar('filter/created_at/from')) {
304:             $this->setVar('filter/created_at/from', $var . ' 00:00:00');
305:         }
306: 
307:         if ($var = $this->getVar('filter/created_at/to')) {
308:             $this->setVar('filter/created_at/to', $var . ' 23:59:59');
309:         }
310: 
311:         $attrToDb = array(
312:             'group'                     => 'group_id',
313:             'customer_address/country'  => 'customer_address/country_id',
314:         );
315: 
316:         // Added store filter
317:         if ($storeId = $this->getStoreId()) {
318:             $websiteId = Mage::app()->getStore($storeId)->getWebsiteId();
319:             if ($websiteId) {
320:                 $this->_filter[] = array(
321:                     'attribute' => 'website_id',
322:                     'eq'        => $websiteId
323:                 );
324:             }
325:         }
326: 
327:         parent::setFilter($attrFilterArray, $attrToDb);
328:         return parent::load();
329:     }
330: 
331:     /**
332:      * Not use :(
333:      */
334:     public function parse()
335:     {
336:         $batchModel = Mage::getSingleton('dataflow/batch');
337:         /* @var $batchModel Mage_Dataflow_Model_Batch */
338: 
339:         $batchImportModel = $batchModel->getBatchImportModel();
340:         $importIds = $batchImportModel->getIdCollection();
341: 
342:         foreach ($importIds as $importId) {
343:             $batchImportModel->load($importId);
344:             $importData = $batchImportModel->getBatchData();
345: 
346:             $this->saveRow($importData);
347:         }
348:     }
349: 
350:     public function setCustomer(Mage_Customer_Model_Customer $customer)
351:     {
352:         $id = Mage::objects()->save($customer);
353:         Mage::register('Object_Cache_Customer', $id);
354:     }
355: 
356:     public function getCustomer()
357:     {
358:         return Mage::objects()->load(Mage::registry('Object_Cache_Customer'));
359:     }
360: 
361:     public function save()
362:     {
363:         $stores = array();
364:         foreach (Mage::getConfig()->getNode('stores')->children() as $storeNode) {
365:             $stores[(int)$storeNode->system->store->id] = $storeNode->getName();
366:         }
367: 
368:         $collections = $this->getData();
369:         if ($collections instanceof Mage_Customer_Model_Entity_Customer_Collection) {
370:             $collections = array($collections->getEntity()->getStoreId()=>$collections);
371:         } elseif (!is_array($collections)) {
372:             $this->addException(Mage::helper('customer')->__('No customer collections found'), Mage_Dataflow_Model_Convert_Exception::FATAL);
373:         }
374: 
375:         foreach ($collections as $storeId=>$collection) {
376:             $this->addException(Mage::helper('customer')->__('Records for %s store found.', $stores[$storeId]));
377: 
378:             if (!$collection instanceof Mage_Customer_Model_Entity_Customer_Collection) {
379:                 $this->addException(Mage::helper('customer')->__('Customer collection expected.'), Mage_Dataflow_Model_Convert_Exception::FATAL);
380:             }
381:             try {
382:                 $i = 0;
383:                 foreach ($collection->getIterator() as $model) {
384:                     $new = false;
385:                     // if customer is new, create default values first
386:                     if (!$model->getId()) {
387:                         $new = true;
388:                         $model->save();
389:                         #Mage::getResourceSingleton('catalog_entity/convert')->addProductToStore($model->getId(), 0);
390:                     }
391:                     if (!$new || 0!==$storeId) {
392: 
393: //                        if (0!==$storeId) {
394: //                            Mage::getResourceSingleton('catalog_entity/convert')->addProductToStore($model->getId(), $storeId);
395: //                        }
396: 
397:                         $model->save();
398:                     }
399:                     $i++;
400:                 }
401:                 $this->addException(Mage::helper('customer')->__("Saved %d record(s)", $i));
402:             } catch (Exception $e) {
403:                 if (!$e instanceof Mage_Dataflow_Model_Convert_Exception) {
404:                     $this->addException(Mage::helper('customer')->__('An error occurred while saving the collection, aborting. Error: %s', $e->getMessage()),
405:                         Mage_Dataflow_Model_Convert_Exception::FATAL);
406:                 }
407:             }
408:         }
409:         return $this;
410:     }
411: 
412:     /*
413:      * saveRow function for saving each customer data
414:      *
415:      * params args array
416:      * return array
417:      */
418:     public function saveRow($importData)
419:     {
420:         $customer = $this->getCustomerModel();
421:         $customer->setId(null);
422: 
423:         if (empty($importData['website'])) {
424:             $message = Mage::helper('customer')->__('Skipping import row, required field "%s" is not defined.', 'website');
425:             Mage::throwException($message);
426:         }
427: 
428:         $website = $this->getWebsiteByCode($importData['website']);
429: 
430:         if ($website === false) {
431:             $message = Mage::helper('customer')->__('Skipping import row, website "%s" field does not exist.', $importData['website']);
432:             Mage::throwException($message);
433:         }
434:         if (empty($importData['email'])) {
435:             $message = Mage::helper('customer')->__('Skipping import row, required field "%s" is not defined.', 'email');
436:             Mage::throwException($message);
437:         }
438: 
439:         $customer->setWebsiteId($website->getId())
440:             ->loadByEmail($importData['email']);
441:         if (!$customer->getId()) {
442:             $customerGroups = $this->getCustomerGroups();
443:             /**
444:              * Check customer group
445:              */
446:             if (empty($importData['group']) || !isset($customerGroups[$importData['group']])) {
447:                 $value = isset($importData['group']) ? $importData['group'] : '';
448:                 $message = Mage::helper('catalog')->__('Skipping import row, the value "%s" is not valid for the "%s" field.', $value, 'group');
449:                 Mage::throwException($message);
450:             }
451:             $customer->setGroupId($customerGroups[$importData['group']]);
452: 
453:             foreach ($this->_requiredFields as $field) {
454:                 if (!isset($importData[$field])) {
455:                     $message = Mage::helper('catalog')->__('Skip import row, required field "%s" for the new customer is not defined.', $field);
456:                     Mage::throwException($message);
457:                 }
458:             }
459: 
460:             $customer->setWebsiteId($website->getId());
461: 
462:             if (empty($importData['created_in']) || !$this->getStoreByCode($importData['created_in'])) {
463:                 $customer->setStoreId(0);
464:             }
465:             else {
466:                 $customer->setStoreId($this->getStoreByCode($importData['created_in'])->getId());
467:             }
468: 
469:             if (empty($importData['password_hash'])) {
470:                 $customer->setPasswordHash($customer->hashPassword($customer->generatePassword(8)));
471:             }
472:         }
473:         elseif (!empty($importData['group'])) {
474:             $customerGroups = $this->getCustomerGroups();
475:             /**
476:              * Check customer group
477:              */
478:             if (isset($customerGroups[$importData['group']])) {
479:                 $customer->setGroupId($customerGroups[$importData['group']]);
480:             }
481:         }
482: 
483:         foreach ($this->_ignoreFields as $field) {
484:             if (isset($importData[$field])) {
485:                 unset($importData[$field]);
486:             }
487:         }
488: 
489:         foreach ($importData as $field => $value) {
490:             if (in_array($field, $this->_billingFields)) {
491:                 continue;
492:             }
493:             if (in_array($field, $this->_shippingFields)) {
494:                 continue;
495:             }
496: 
497:             $attribute = $this->getAttribute($field);
498:             if (!$attribute) {
499:                 continue;
500:             }
501: 
502:             $isArray = false;
503:             $setValue = $value;
504: 
505:             if ($attribute->getFrontendInput() == 'multiselect') {
506:                 $value = explode(self::MULTI_DELIMITER, $value);
507:                 $isArray = true;
508:                 $setValue = array();
509:             }
510: 
511:             if ($attribute->usesSource()) {
512:                 $options = $attribute->getSource()->getAllOptions(false);
513: 
514:                 if ($isArray) {
515:                     foreach ($options as $item) {
516:                         if (in_array($item['label'], $value)) {
517:                             $setValue[] = $item['value'];
518:                         }
519:                     }
520:                 }
521:                 else {
522:                     $setValue = null;
523:                     foreach ($options as $item) {
524:                         if ($item['label'] == $value) {
525:                             $setValue = $item['value'];
526:                         }
527:                     }
528:                 }
529:             }
530: 
531:             $customer->setData($field, $setValue);
532:         }
533: 
534:         if (isset($importData['is_subscribed'])) {
535:             $customer->setData('is_subscribed', $importData['is_subscribed']);
536:         }
537: 
538:         $importBillingAddress = $importShippingAddress = true;
539:         $savedBillingAddress = $savedShippingAddress = false;
540: 
541:         /**
542:          * Check Billing address required fields
543:          */
544:         foreach ($this->_billingRequiredFields as $field) {
545:             if (empty($importData[$field])) {
546:                 $importBillingAddress = false;
547:             }
548:         }
549: 
550:         /**
551:          * Check Sipping address required fields
552:          */
553:         foreach ($this->_shippingRequiredFields as $field) {
554:             if (empty($importData[$field])) {
555:                 $importShippingAddress = false;
556:             }
557:         }
558: 
559:         $onlyAddress = false;
560: 
561:         /**
562:          * Check addresses
563:          */
564:         if ($importBillingAddress && $importShippingAddress) {
565:             $onlyAddress = true;
566:             foreach ($this->_addressFields as $field) {
567:                 if (!isset($importData['billing_'.$field]) && !isset($importData['shipping_'.$field])) {
568:                     continue;
569:                 }
570:                 if (!isset($importData['billing_'.$field]) || !isset($importData['shipping_'.$field])) {
571:                     $onlyAddress = false;
572:                     break;
573:                 }
574:                 if ($importData['billing_'.$field] != $importData['shipping_'.$field]) {
575:                     $onlyAddress = false;
576:                     break;
577:                 }
578:             }
579: 
580:             if ($onlyAddress) {
581:                 $importShippingAddress = false;
582:             }
583:         }
584: 
585:         /**
586:          * Import billing address
587:          */
588:         if ($importBillingAddress) {
589:             $billingAddress = $this->getBillingAddressModel();
590:             if ($customer->getDefaultBilling()) {
591:                 $billingAddress->load($customer->getDefaultBilling());
592:             }
593:             else {
594:                 $billingAddress->setData(array());
595:             }
596: 
597:             foreach ($this->_billingFields as $field) {
598:                 $cleanField = Mage::helper('core/string')->substr($field, 8);
599: 
600:                 if (isset($importData[$field])) {
601:                     $billingAddress->setDataUsingMethod($cleanField, $importData[$field]);
602:                 }
603:                 elseif (isset($this->_billingMappedFields[$field])
604:                     && isset($importData[$this->_billingMappedFields[$field]])) {
605:                     $billingAddress->setDataUsingMethod($cleanField, $importData[$this->_billingMappedFields[$field]]);
606:                 }
607:             }
608: 
609:             $street = array();
610:             foreach ($this->_billingStreetFields as $field) {
611:                 if (!empty($importData[$field])) {
612:                     $street[] = $importData[$field];
613:                 }
614:             }
615:             if ($street) {
616:                 $billingAddress->setDataUsingMethod('street', $street);
617:             }
618: 
619:             $billingAddress->setCountryId($importData['billing_country']);
620:             $regionName = isset($importData['billing_region']) ? $importData['billing_region'] : '';
621:             if ($regionName) {
622:                 $regionId = $this->getRegionId($importData['billing_country'], $regionName);
623:                 $billingAddress->setRegionId($regionId);
624:             }
625: 
626:             if ($customer->getId()) {
627:                 $billingAddress->setCustomerId($customer->getId());
628: 
629:                 $billingAddress->save();
630:                 $customer->setDefaultBilling($billingAddress->getId());
631: 
632:                 if ($onlyAddress) {
633:                     $customer->setDefaultShipping($billingAddress->getId());
634:                 }
635: 
636:                 $savedBillingAddress = true;
637:             }
638:         }
639: 
640:         /**
641:          * Import shipping address
642:          */
643:         if ($importShippingAddress) {
644:             $shippingAddress = $this->getShippingAddressModel();
645:             if ($customer->getDefaultShipping() && $customer->getDefaultBilling() != $customer->getDefaultShipping()) {
646:                 $shippingAddress->load($customer->getDefaultShipping());
647:             }
648:             else {
649:                 $shippingAddress->setData(array());
650:             }
651: 
652:             foreach ($this->_shippingFields as $field) {
653:                 $cleanField = Mage::helper('core/string')->substr($field, 9);
654: 
655:                 if (isset($importData[$field])) {
656:                     $shippingAddress->setDataUsingMethod($cleanField, $importData[$field]);
657:                 }
658:                 elseif (isset($this->_shippingMappedFields[$field])
659:                     && isset($importData[$this->_shippingMappedFields[$field]])) {
660:                     $shippingAddress->setDataUsingMethod($cleanField, $importData[$this->_shippingMappedFields[$field]]);
661:                 }
662:             }
663: 
664:             $street = array();
665:             foreach ($this->_shippingStreetFields as $field) {
666:                 if (!empty($importData[$field])) {
667:                     $street[] = $importData[$field];
668:                 }
669:             }
670:             if ($street) {
671:                 $shippingAddress->setDataUsingMethod('street', $street);
672:             }
673: 
674:             $shippingAddress->setCountryId($importData['shipping_country']);
675:             $regionName = isset($importData['shipping_region']) ? $importData['shipping_region'] : '';
676:             if ($regionName) {
677:                 $regionId = $this->getRegionId($importData['shipping_country'], $regionName);
678:                 $shippingAddress->setRegionId($regionId);
679:             }
680: 
681:             if ($customer->getId()) {
682:                 $shippingAddress->setCustomerId($customer->getId());
683:                 $shippingAddress->save();
684:                 $customer->setDefaultShipping($shippingAddress->getId());
685: 
686:                 $savedShippingAddress = true;
687:             }
688:         }
689: 
690:         $customer->setImportMode(true);
691:         $customer->save();
692:         $saveCustomer = false;
693: 
694:         if ($importBillingAddress && !$savedBillingAddress) {
695:             $saveCustomer = true;
696:             $billingAddress->setCustomerId($customer->getId());
697:             $billingAddress->save();
698:             $customer->setDefaultBilling($billingAddress->getId());
699:             if ($onlyAddress) {
700:                 $customer->setDefaultShipping($billingAddress->getId());
701:             }
702:         }
703:         if ($importShippingAddress && !$savedShippingAddress) {
704:             $saveCustomer = true;
705:             $shippingAddress->setCustomerId($customer->getId());
706:             $shippingAddress->save();
707:             $customer->setDefaultShipping($shippingAddress->getId());
708:         }
709:         if ($saveCustomer) {
710:             $customer->save();
711:         }
712: 
713:         return $this;
714:     }
715: 
716:     public function getCustomerId()
717:     {
718:         return $this->_customerId;
719:     }
720: 
721:     /* ########### THE CODE BELOW AT THIS METHOD IS NOT USED ############# */
722: 
723:     public function saveRow__OLD()
724:     {
725: 
726:         $mem = memory_get_usage(); $origMem = $mem; $memory = $mem;
727:         $customer = $this->getCustomer();
728:         @set_time_limit(240);
729:         $row = $args;
730:         $newMem = memory_get_usage(); $memory .= ', '.($newMem-$mem); $mem = $newMem;
731:         $customer->importFromTextArray($row);
732: 
733:         if (!$customer->getData()) {
734:             return;
735:         }
736: 
737:         $newMem = memory_get_usage(); $memory .= ', '.($newMem-$mem); $mem = $newMem;
738:         try {
739:             $customer->save();
740:             $this->_customerId = $customer->getId();
741:             $customer->unsetData();
742:             $customer->cleanAllAddresses();
743:             $customer->unsetSubscription();
744:             $newMem = memory_get_usage(); $memory .= ', '.($newMem-$mem); $mem = $newMem;
745: 
746:         } catch (Exception $e) {
747:         }
748:         unset($row);
749:         return array('memory'=>$memory);
750:     }
751: }
752: 
Magento 1.7.0.2 API documentation generated by ApiGen 2.8.0