PageRenderTime 42ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 1ms

/app/code/core/Mage/Customer/Model/Convert/Parser/Customer.php

https://bitbucket.org/andrewjleavitt/magestudy
PHP | 761 lines | 531 code | 102 blank | 128 comment | 104 complexity | edf75eb5b8ca0aaed124c29b02acb796 MD5 | raw file
Possible License(s): CC-BY-SA-3.0, LGPL-2.1, GPL-2.0, WTFPL
  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) 2010 Magento Inc. (http://www.magentocommerce.com)
  24. * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
  25. */
  26. class Mage_Customer_Model_Convert_Parser_Customer
  27. extends Mage_Eav_Model_Convert_Parser_Abstract
  28. {
  29. const MULTI_DELIMITER = ' , ';
  30. protected $_resource;
  31. /**
  32. * Product collections per store
  33. *
  34. * @var array
  35. */
  36. protected $_collections;
  37. protected $_customerModel;
  38. protected $_customerAddressModel;
  39. protected $_newsletterModel;
  40. protected $_store;
  41. protected $_storeId;
  42. protected $_stores;
  43. /**
  44. * Website collection array
  45. *
  46. * @var array
  47. */
  48. protected $_websites;
  49. protected $_attributes = array();
  50. protected $_fields;
  51. /**
  52. * Array to contain customer groups
  53. * @var null|array
  54. */
  55. protected $_customerGroups = null;
  56. public function getFields()
  57. {
  58. if (!$this->_fields) {
  59. $this->_fields = Mage::getConfig()->getFieldset('customer_dataflow', 'admin');
  60. }
  61. return $this->_fields;
  62. }
  63. /**
  64. * Retrieve customer model cache
  65. *
  66. * @return Mage_Customer_Model_Customer
  67. */
  68. public function getCustomerModel()
  69. {
  70. if (is_null($this->_customerModel)) {
  71. $object = Mage::getModel('customer/customer');
  72. $this->_customerModel = Mage::objects()->save($object);
  73. }
  74. return Mage::objects()->load($this->_customerModel);
  75. }
  76. /**
  77. * Retrieve customer address model cache
  78. *
  79. * @return Mage_Customer_Model_Address
  80. */
  81. public function getCustomerAddressModel()
  82. {
  83. if (is_null($this->_customerAddressModel)) {
  84. $object = Mage::getModel('customer/address');
  85. $this->_customerAddressModel = Mage::objects()->save($object);
  86. }
  87. return Mage::objects()->load($this->_customerAddressModel);
  88. }
  89. /**
  90. * Retrieve newsletter subscribers model cache
  91. *
  92. * @return Mage_Newsletter_Model_Subscriber
  93. */
  94. public function getNewsletterModel()
  95. {
  96. if (is_null($this->_newsletterModel)) {
  97. $object = Mage::getModel('newsletter/subscriber');
  98. $this->_newsletterModel = Mage::objects()->save($object);
  99. }
  100. return Mage::objects()->load($this->_newsletterModel);
  101. }
  102. /**
  103. * Retrieve current store model
  104. *
  105. * @return Mage_Core_Model_Store
  106. */
  107. public function getStore()
  108. {
  109. if (is_null($this->_store)) {
  110. try {
  111. $store = Mage::app()->getStore($this->getVar('store'));
  112. }
  113. catch (Exception $e) {
  114. $this->addException(Mage::helper('catalog')->__('An invalid store was specified.'), Varien_Convert_Exception::FATAL);
  115. throw $e;
  116. }
  117. $this->_store = $store;
  118. }
  119. return $this->_store;
  120. }
  121. /**
  122. * Retrieve store ID
  123. *
  124. * @return int
  125. */
  126. public function getStoreId()
  127. {
  128. if (is_null($this->_storeId)) {
  129. $this->_storeId = $this->getStore()->getId();
  130. }
  131. return $this->_storeId;
  132. }
  133. public function getStoreById($storeId)
  134. {
  135. if (is_null($this->_stores)) {
  136. $this->_stores = Mage::app()->getStores(true);
  137. }
  138. if (isset($this->_stores[$storeId])) {
  139. return $this->_stores[$storeId];
  140. }
  141. return false;
  142. }
  143. /**
  144. * Retrieve website model by id
  145. *
  146. * @param int $websiteId
  147. * @return Mage_Core_Model_Website
  148. */
  149. public function getWebsiteById($websiteId)
  150. {
  151. if (is_null($this->_websites)) {
  152. $this->_websites = Mage::app()->getWebsites(true);
  153. }
  154. if (isset($this->_websites[$websiteId])) {
  155. return $this->_websites[$websiteId];
  156. }
  157. return false;
  158. }
  159. /**
  160. * Retrieve eav entity attribute model
  161. *
  162. * @param string $code
  163. * @return Mage_Eav_Model_Entity_Attribute
  164. */
  165. public function getAttribute($code)
  166. {
  167. if (!isset($this->_attributes[$code])) {
  168. $this->_attributes[$code] = $this->getCustomerModel()->getResource()->getAttribute($code);
  169. }
  170. return $this->_attributes[$code];
  171. }
  172. /**
  173. * @return Mage_Catalog_Model_Mysql4_Convert
  174. */
  175. public function getResource()
  176. {
  177. if (!$this->_resource) {
  178. $this->_resource = Mage::getResourceSingleton('catalog_entity/convert');
  179. #->loadStores()
  180. #->loadProducts()
  181. #->loadAttributeSets()
  182. #->loadAttributeOptions();
  183. }
  184. return $this->_resource;
  185. }
  186. public function getCollection($storeId)
  187. {
  188. if (!isset($this->_collections[$storeId])) {
  189. $this->_collections[$storeId] = Mage::getResourceModel('customer/customer_collection');
  190. $this->_collections[$storeId]->getEntity()->setStore($storeId);
  191. }
  192. return $this->_collections[$storeId];
  193. }
  194. public function unparse()
  195. {
  196. $systemFields = array();
  197. foreach ($this->getFields() as $code=>$node) {
  198. if ($node->is('system')) {
  199. $systemFields[] = $code;
  200. }
  201. }
  202. $entityIds = $this->getData();
  203. foreach ($entityIds as $i => $entityId) {
  204. $customer = $this->getCustomerModel()
  205. ->setData(array())
  206. ->load($entityId);
  207. /* @var $customer Mage_Customer_Model_Customer */
  208. $position = Mage::helper('catalog')->__('Line %d, Email: %s', ($i+1), $customer->getEmail());
  209. $this->setPosition($position);
  210. $row = array();
  211. foreach ($customer->getData() as $field => $value) {
  212. if ($field == 'website_id') {
  213. $website = $this->getWebsiteById($value);
  214. if ($website === false) {
  215. $website = $this->getWebsiteById(0);
  216. }
  217. $row['website'] = $website->getCode();
  218. continue;
  219. }
  220. if (in_array($field, $systemFields) || is_object($value)) {
  221. continue;
  222. }
  223. $attribute = $this->getAttribute($field);
  224. if (!$attribute) {
  225. continue;
  226. }
  227. if ($attribute->usesSource()) {
  228. $option = $attribute->getSource()->getOptionText($value);
  229. if ($value && empty($option)) {
  230. $message = Mage::helper('catalog')->__("An invalid option ID is specified for %s (%s), skipping the record.", $field, $value);
  231. $this->addException($message, Mage_Dataflow_Model_Convert_Exception::ERROR);
  232. continue;
  233. }
  234. if (is_array($option)) {
  235. $value = join(self::MULTI_DELIMITER, $option);
  236. } else {
  237. $value = $option;
  238. }
  239. unset($option);
  240. }
  241. elseif (is_array($value)) {
  242. continue;
  243. }
  244. $row[$field] = $value;
  245. }
  246. $defaultBillingId = $customer->getDefaultBilling();
  247. $defaultShippingId = $customer->getDefaultShipping();
  248. $customerAddress = $this->getCustomerAddressModel();
  249. if (!$defaultBillingId) {
  250. foreach ($this->getFields() as $code=>$node) {
  251. if ($node->is('billing')) {
  252. $row['billing_'.$code] = null;
  253. }
  254. }
  255. }
  256. else {
  257. $customerAddress->load($defaultBillingId);
  258. foreach ($this->getFields() as $code=>$node) {
  259. if ($node->is('billing')) {
  260. $row['billing_'.$code] = $customerAddress->getDataUsingMethod($code);
  261. }
  262. }
  263. }
  264. if (!$defaultShippingId) {
  265. foreach ($this->getFields() as $code=>$node) {
  266. if ($node->is('shipping')) {
  267. $row['shipping_'.$code] = null;
  268. }
  269. }
  270. }
  271. else {
  272. if ($defaultShippingId != $defaultBillingId) {
  273. $customerAddress->load($defaultShippingId);
  274. }
  275. foreach ($this->getFields() as $code=>$node) {
  276. if ($node->is('shipping')) {
  277. $row['shipping_'.$code] = $customerAddress->getDataUsingMethod($code);
  278. }
  279. }
  280. }
  281. $store = $this->getStoreById($customer->getStoreId());
  282. if ($store === false) {
  283. $store = $this->getStoreById(0);
  284. }
  285. $row['created_in'] = $store->getCode();
  286. $newsletter = $this->getNewsletterModel()
  287. ->setData(array())
  288. ->loadByCustomer($customer);
  289. $row['is_subscribed'] = ($newsletter->getId()
  290. && $newsletter->getSubscriberStatus() == Mage_Newsletter_Model_Subscriber::STATUS_SUBSCRIBED)
  291. ? 1 : 0;
  292. if($customer->getGroupId()){
  293. $groupCode = $this->_getCustomerGroupCode($customer);
  294. if (is_null($groupCode)) {
  295. $this->addException(
  296. Mage::helper('catalog')->__("An invalid group ID is specified, skipping the record."),
  297. Mage_Dataflow_Model_Convert_Exception::ERROR
  298. );
  299. continue;
  300. } else {
  301. $row['group'] = $groupCode;
  302. }
  303. }
  304. $batchExport = $this->getBatchExportModel()
  305. ->setId(null)
  306. ->setBatchId($this->getBatchModel()->getId())
  307. ->setBatchData($row)
  308. ->setStatus(1)
  309. ->save();
  310. }
  311. return $this;
  312. }
  313. public function getExternalAttributes()
  314. {
  315. $internal = array(
  316. 'store_id',
  317. 'entity_id',
  318. 'website_id',
  319. 'group_id',
  320. 'created_in',
  321. 'default_billing',
  322. 'default_shipping',
  323. 'country_id'
  324. );
  325. $customerAttributes = Mage::getResourceModel('customer/attribute_collection')
  326. ->load()->getIterator();
  327. $addressAttributes = Mage::getResourceModel('customer/address_attribute_collection')
  328. ->load()->getIterator();
  329. $attributes = array(
  330. 'website' => 'website',
  331. 'email' => 'email',
  332. 'group' => 'group',
  333. 'create_in' => 'create_in',
  334. 'is_subscribed' => 'is_subscribed'
  335. );
  336. foreach ($customerAttributes as $attr) {
  337. $code = $attr->getAttributeCode();
  338. if (in_array($code, $internal) || $attr->getFrontendInput()=='hidden') {
  339. continue;
  340. }
  341. $attributes[$code] = $code;
  342. }
  343. $attributes['password_hash'] = 'password_hash';
  344. foreach ($addressAttributes as $attr) {
  345. $code = $attr->getAttributeCode();
  346. if (in_array($code, $internal) || $attr->getFrontendInput()=='hidden') {
  347. continue;
  348. }
  349. if ($code == 'street') {
  350. $attributes['billing_'.$code.'_full'] = 'billing_'.$code;
  351. } else {
  352. $attributes['billing_'.$code] = 'billing_'.$code;
  353. }
  354. }
  355. $attributes['billing_country'] = 'billing_country';
  356. foreach ($addressAttributes as $attr) {
  357. $code = $attr->getAttributeCode();
  358. if (in_array($code, $internal) || $attr->getFrontendInput()=='hidden') {
  359. continue;
  360. }
  361. if ($code == 'street') {
  362. $attributes['shipping_'.$code.'_full'] = 'shipping_'.$code;
  363. } else {
  364. $attributes['shipping_'.$code] = 'shipping_'.$code;
  365. }
  366. }
  367. $attributes['shipping_country'] = 'shipping_country';
  368. return $attributes;
  369. }
  370. /**
  371. * Gets group code by customer's groupId
  372. *
  373. * @param Mage_Customer_Model_Customer $customer
  374. * @return string|null
  375. */
  376. protected function _getCustomerGroupCode($customer)
  377. {
  378. if (is_null($this->_customerGroups)) {
  379. $groups = Mage::getResourceModel('customer/group_collection')
  380. ->load();
  381. foreach ($groups as $group) {
  382. $this->_customerGroups[$group->getId()] = $group->getData('customer_group_code');
  383. }
  384. }
  385. if (isset($this->_customerGroups[$customer->getGroupId()])) {
  386. return $this->_customerGroups[$customer->getGroupId()];
  387. } else {
  388. return null;
  389. }
  390. }
  391. /* ########### THE CODE BELOW IS NOT USED ############# */
  392. public function unparse__OLD()
  393. {
  394. $collections = $this->getData();
  395. // if ($collections instanceof Mage_Eav_Model_Entity_Collection_Abstract) {
  396. // $collections = array($collections->getEntity()->getStoreId()=>$collections);
  397. // } elseif (!is_array($collections)) {
  398. // $this->addException(Mage::helper('customer')->__("Array of Entity collections is expected."), Varien_Convert_Exception::FATAL);
  399. // }
  400. // foreach ($collections as $storeId=>$collection) {
  401. // if (!$collection instanceof Mage_Eav_Model_Entity_Collection_Abstract) {
  402. // $this->addException(Mage::helper('customer')->__("Entity collection is expected."), Varien_Convert_Exception::FATAL);
  403. // }
  404. $data = array();
  405. foreach ($collections->getIterator() as $i=>$model) {
  406. $this->setPosition('Line: '.($i+1).', Email: '.$model->getEmail());
  407. // Will be removed after confirmation from Dima or Moshe
  408. $row = array(
  409. 'store_view'=>$this->getStoreCode($this->getVar('store') ? $this->getVar('store') : $storeId),
  410. ); // End
  411. foreach ($model->getData() as $field=>$value) {
  412. // set website_id
  413. if ($field == 'website_id') {
  414. $row['website_code'] = Mage::getModel('core/website')->load($value)->getCode();
  415. continue;
  416. } // end
  417. if (in_array($field, $systemFields)) {
  418. continue;
  419. }
  420. $attribute = $model->getResource()->getAttribute($field);
  421. if (!$attribute) {
  422. continue;
  423. }
  424. if ($attribute->usesSource()) {
  425. $option = $attribute->getSource()->getOptionText($value);
  426. if (false===$option) {
  427. $this->addException(Mage::helper('customer')->__("An invalid option ID is specified for %s (%s), skipping the record.", $field, $value), Mage_Dataflow_Model_Convert_Exception::ERROR);
  428. continue;
  429. }
  430. if (is_array($option)) {
  431. $value = $option['label'];
  432. } else {
  433. $value = $option;
  434. }
  435. }
  436. $row[$field] = $value;
  437. $billingAddress = $model->getDefaultBillingAddress();
  438. if($billingAddress instanceof Mage_Customer_Model_Address){
  439. $billingAddress->explodeStreetAddress();
  440. $row['billing_street1'] = $billingAddress->getStreet1();
  441. $row['billing_street2'] = $billingAddress->getStreet2();
  442. $row['billing_city'] = $billingAddress->getCity();
  443. $row['billing_region'] = $billingAddress->getRegion();
  444. $row['billing_country'] = $billingAddress->getCountry();
  445. $row['billing_postcode'] = $billingAddress->getPostcode();
  446. $row['billing_telephone'] = $billingAddress->getTelephone();
  447. }
  448. $shippingAddress = $model->getDefaultShippingAddress();
  449. if($shippingAddress instanceof Mage_Customer_Model_Address){
  450. $shippingAddress->explodeStreetAddress();
  451. $row['shipping_street1'] = $shippingAddress->getStreet1();
  452. $row['shipping_street2'] = $shippingAddress->getStreet2();
  453. $row['shipping_city'] = $shippingAddress->getCity();
  454. $row['shipping_region'] = $shippingAddress->getRegion();
  455. $row['shipping_country'] = $shippingAddress->getCountry();
  456. $row['shipping_postcode'] = $shippingAddress->getPostcode();
  457. $row['shipping_telephone'] = $shippingAddress->getTelephone();
  458. }
  459. if($model->getGroupId()){
  460. $group = Mage::getResourceModel('customer/group_collection')
  461. ->addFilter('customer_group_id',$model->getGroupId())
  462. ->load();
  463. $row['group']=$group->getFirstItem()->getData('customer_group_code');
  464. }
  465. }
  466. $subscriber = Mage::getModel('newsletter/subscriber')->loadByCustomer($model);
  467. if ($subscriber->getId()) {
  468. if ($subscriber->getSubscriberStatus() == Mage_Newsletter_Model_Subscriber::STATUS_SUBSCRIBED) {
  469. $row['is_subscribed'] = Mage_Customer_Model_Customer::SUBSCRIBED_YES;
  470. } else {
  471. $row['is_subscribed'] = Mage_Customer_Model_Customer::SUBSCRIBED_NO;
  472. }
  473. }
  474. if(!isset($row['created_in'])){
  475. $row['created_in'] = 'Admin';
  476. }
  477. $data[] = $row;
  478. }
  479. // }
  480. $this->setData($data);
  481. return $this;
  482. }
  483. /**
  484. * @deprecated not used anymore
  485. */
  486. public function parse()
  487. {
  488. $data = $this->getData();
  489. $entityTypeId = Mage::getSingleton('eav/config')->getEntityType('customer')->getId();
  490. $result = array();
  491. foreach ($data as $i=>$row) {
  492. $this->setPosition('Line: '.($i+1));
  493. try {
  494. // validate SKU
  495. if (empty($row['email'])) {
  496. $this->addException(Mage::helper('customer')->__('Missing email, skipping the record.'), Varien_Convert_Exception::ERROR);
  497. continue;
  498. }
  499. $this->setPosition('Line: '.($i+1).', email: '.$row['email']);
  500. // try to get entity_id by sku if not set
  501. /*
  502. if (empty($row['entity_id'])) {
  503. $row['entity_id'] = $this->getResource()->getProductIdBySku($row['email']);
  504. }
  505. */
  506. // if attribute_set not set use default
  507. if (empty($row['attribute_set'])) {
  508. $row['attribute_set'] = 'Default';
  509. }
  510. // get attribute_set_id, if not throw error
  511. $row['attribute_set_id'] = $this->getAttributeSetId($entityTypeId, $row['attribute_set']);
  512. if (!$row['attribute_set_id']) {
  513. $this->addException(Mage::helper('customer')->__("Invalid attribute set specified, skipping the record."), Varien_Convert_Exception::ERROR);
  514. continue;
  515. }
  516. if (empty($row['group'])) {
  517. $row['group'] = 'General';
  518. }
  519. if (empty($row['firstname'])) {
  520. $this->addException(Mage::helper('customer')->__('Missing firstname, skipping the record.'), Varien_Convert_Exception::ERROR);
  521. continue;
  522. }
  523. //$this->setPosition('Line: '.($i+1).', Firstname: '.$row['firstname']);
  524. if (empty($row['lastname'])) {
  525. $this->addException(Mage::helper('customer')->__('Missing lastname, skipping the record.'), Varien_Convert_Exception::ERROR);
  526. continue;
  527. }
  528. //$this->setPosition('Line: '.($i+1).', Lastname: '.$row['lastname']);
  529. /*
  530. // get product type_id, if not throw error
  531. $row['type_id'] = $this->getProductTypeId($row['type']);
  532. if (!$row['type_id']) {
  533. $this->addException(Mage::helper('catalog')->__("Invalid product type specified, skipping the record."), Varien_Convert_Exception::ERROR);
  534. continue;
  535. }
  536. */
  537. // get store ids
  538. $storeIds = $this->getStoreIds(isset($row['store']) ? $row['store'] : $this->getVar('store'));
  539. if (!$storeIds) {
  540. $this->addException(Mage::helper('customer')->__("Invalid store specified, skipping the record."), Varien_Convert_Exception::ERROR);
  541. continue;
  542. }
  543. // import data
  544. $rowError = false;
  545. foreach ($storeIds as $storeId) {
  546. $collection = $this->getCollection($storeId);
  547. //print_r($collection);
  548. $entity = $collection->getEntity();
  549. $model = Mage::getModel('customer/customer');
  550. $model->setStoreId($storeId);
  551. if (!empty($row['entity_id'])) {
  552. $model->load($row['entity_id']);
  553. }
  554. foreach ($row as $field=>$value) {
  555. $attribute = $entity->getAttribute($field);
  556. if (!$attribute) {
  557. continue;
  558. #$this->addException(Mage::helper('catalog')->__("Unknown attribute: %s.", $field), Varien_Convert_Exception::ERROR);
  559. }
  560. if ($attribute->usesSource()) {
  561. $source = $attribute->getSource();
  562. $optionId = $this->getSourceOptionId($source, $value);
  563. if (is_null($optionId)) {
  564. $rowError = true;
  565. $this->addException(Mage::helper('customer')->__("Invalid attribute option specified for attribute %s (%s), skipping the record.", $field, $value), Varien_Convert_Exception::ERROR);
  566. continue;
  567. }
  568. $value = $optionId;
  569. }
  570. $model->setData($field, $value);
  571. }//foreach ($row as $field=>$value)
  572. $billingAddress = $model->getPrimaryBillingAddress();
  573. $customer = Mage::getModel('customer/customer')->load($model->getId());
  574. if (!$billingAddress instanceof Mage_Customer_Model_Address) {
  575. $billingAddress = Mage::getModel('customer/address');
  576. if ($customer->getId() && $customer->getDefaultBilling()) {
  577. $billingAddress->setId($customer->getDefaultBilling());
  578. }
  579. }
  580. $regions = Mage::getResourceModel('directory/region_collection')
  581. ->addRegionNameFilter($row['billing_region'])
  582. ->load();
  583. if ($regions) foreach($regions as $region) {
  584. $regionId = $region->getId();
  585. }
  586. $billingAddress->setFirstname($row['firstname']);
  587. $billingAddress->setLastname($row['lastname']);
  588. $billingAddress->setCity($row['billing_city']);
  589. $billingAddress->setRegion($row['billing_region']);
  590. $billingAddress->setRegionId($regionId);
  591. $billingAddress->setCountryId($row['billing_country']);
  592. $billingAddress->setPostcode($row['billing_postcode']);
  593. $billingAddress->setStreet(array($row['billing_street1'],$row['billing_street2']));
  594. if (!empty($row['billing_telephone'])) {
  595. $billingAddress->setTelephone($row['billing_telephone']);
  596. }
  597. if (!$model->getDefaultBilling()) {
  598. $billingAddress->setCustomerId($model->getId());
  599. $billingAddress->setIsDefaultBilling(true);
  600. $billingAddress->save();
  601. $model->setDefaultBilling($billingAddress->getId());
  602. $model->addAddress($billingAddress);
  603. if ($customer->getDefaultBilling()) {
  604. $model->setDefaultBilling($customer->getDefaultBilling());
  605. } else {
  606. $shippingAddress->save();
  607. $model->setDefaultShipping($billingAddress->getId());
  608. $model->addAddress($billingAddress);
  609. }
  610. }
  611. $shippingAddress = $model->getPrimaryShippingAddress();
  612. if (!$shippingAddress instanceof Mage_Customer_Model_Address) {
  613. $shippingAddress = Mage::getModel('customer/address');
  614. if ($customer->getId() && $customer->getDefaultShipping()) {
  615. $shippingAddress->setId($customer->getDefaultShipping());
  616. }
  617. }
  618. $regions = Mage::getResourceModel('directory/region_collection')
  619. ->addRegionNameFilter($row['shipping_region'])
  620. ->load();
  621. if ($regions) foreach($regions as $region) {
  622. $regionId = $region->getId();
  623. }
  624. $shippingAddress->setFirstname($row['firstname']);
  625. $shippingAddress->setLastname($row['lastname']);
  626. $shippingAddress->setCity($row['shipping_city']);
  627. $shippingAddress->setRegion($row['shipping_region']);
  628. $shippingAddress->setRegionId($regionId);
  629. $shippingAddress->setCountryId($row['shipping_country']);
  630. $shippingAddress->setPostcode($row['shipping_postcode']);
  631. $shippingAddress->setStreet(array($row['shipping_street1'], $row['shipping_street2']));
  632. $shippingAddress->setCustomerId($model->getId());
  633. if (!empty($row['shipping_telephone'])) {
  634. $shippingAddress->setTelephone($row['shipping_telephone']);
  635. }
  636. if (!$model->getDefaultShipping()) {
  637. if ($customer->getDefaultShipping()) {
  638. $model->setDefaultShipping($customer->getDefaultShipping());
  639. } else {
  640. $shippingAddress->save();
  641. $model->setDefaultShipping($shippingAddress->getId());
  642. $model->addAddress($shippingAddress);
  643. }
  644. $shippingAddress->setIsDefaultShipping(true);
  645. }
  646. if (!$rowError) {
  647. $collection->addItem($model);
  648. }
  649. } //foreach ($storeIds as $storeId)
  650. } catch (Exception $e) {
  651. if (!$e instanceof Mage_Dataflow_Model_Convert_Exception) {
  652. $this->addException(Mage::helper('customer')->__('An error occurred while retrieving the option value: %s.', $e->getMessage()), Mage_Dataflow_Model_Convert_Exception::FATAL);
  653. }
  654. }
  655. }
  656. $this->setData($this->_collections);
  657. return $this;
  658. }
  659. }