public function setIsDefaultShipping($value)
 {
     if (false === $this->_isShippingFixed()) {
         parent::setIsDefaultShipping($value);
     }
     return $this;
 }
示例#2
0
 /**
  * Importing customer data from text array
  *
  * @param array $row
  * @return uMage_Customer_Model_Customer
  */
 public function importFromTextArray(array $row)
 {
     $this->resetErrors();
     $hlp = Mage::helper('customer');
     $line = $row['i'];
     $row = $row['row'];
     $regions = Mage::getResourceModel('directory/region_collection');
     //        $config = Mage::getSingleton('eav/config')->getEntityType('customer');
     $website = Mage::getModel('core/website')->load($row['website_code'], 'code');
     if (!$website->getId()) {
         $this->addError($hlp->__('Invalid website, skipping the record, line: %s.', $line));
     } else {
         $row['website_id'] = $website->getWebsiteId();
         $this->setWebsiteId($row['website_id']);
     }
     // Validate Email
     if (empty($row['email'])) {
         $this->addError($hlp->__('Missing email, skipping the record, line: %s.', $line));
     } else {
         $this->loadByEmail($row['email']);
     }
     if (empty($row['entity_id'])) {
         if ($this->getData('entity_id')) {
             $this->addError($hlp->__('The customer email (%s) already exists, skipping the record, line: %s.', $row['email'], $line));
         }
     } else {
         if ($row['entity_id'] != $this->getData('entity_id')) {
             $this->addError($hlp->__('The customer ID and email did not match, skipping the record, line: %s.', $line));
         } else {
             $this->unsetData();
             $this->load($row['entity_id']);
             if (isset($row['store_view'])) {
                 $storeId = Mage::app()->getStore($row['store_view'])->getId();
                 if ($storeId) {
                     $this->setStoreId($storeId);
                 }
             }
         }
     }
     if (empty($row['website_code'])) {
         $this->addError($hlp->__('Missing website, skipping the record, line: %s.', $line));
     }
     if (empty($row['group'])) {
         $row['group'] = 'General';
     }
     if (empty($row['firstname'])) {
         $this->addError($hlp->__('Missing first name, skipping the record, line: %s.', $line));
     }
     if (empty($row['lastname'])) {
         $this->addError($hlp->__('Missing last name, skipping the record, line: %s.', $line));
     }
     if (!empty($row['password_new'])) {
         $this->setPassword($row['password_new']);
         unset($row['password_new']);
         if (!empty($row['password_hash'])) {
             unset($row['password_hash']);
         }
     }
     if ($errors = $this->getErrors()) {
         $this->unsetData();
         $this->printError(join("<br />", $errors));
         return;
     }
     //        $entity = $this->getResource();
     foreach ($row as $field => $value) {
         //            $attribute = $entity->getAttribute($field);
         //            if (!$attribute) {
         //                echo $field;
         //                continue;
         //            }
         //            if ($attribute->usesSource()) {
         //                $source = $attribute->getSource();
         //                $optionId = $config->getSourceOptionId($source, $value);
         //                if (is_null($optionId)) {
         //                    $this->printError($hlp->__("Invalid attribute option specified for attribute attribute %s (%s).", $field, $value), $line);
         //                }
         //                $value = $optionId;
         //            }
         $this->setData($field, $value);
     }
     if (!$this->validateAddress($row, 'billing')) {
         $this->printError($hlp->__('Invalid billing address for (%s).', $row['email']), $line);
     } else {
         // Handling billing address
         $billingAddress = $this->getPrimaryBillingAddress();
         if (!$billingAddress instanceof Mage_Customer_Model_Address) {
             $billingAddress = new Mage_Customer_Model_Address();
         }
         $regions->addRegionNameFilter($row['billing_region'])->load();
         if ($regions) {
             foreach ($regions as $region) {
                 $regionId = $region->getId();
             }
         }
         $billingAddress->setFirstname($row['firstname']);
         $billingAddress->setLastname($row['lastname']);
         $billingAddress->setCity($row['billing_city']);
         $billingAddress->setRegion($row['billing_region']);
         if (isset($regionId)) {
             $billingAddress->setRegionId($regionId);
         }
         $billingAddress->setCountryId($row['billing_country']);
         $billingAddress->setPostcode($row['billing_postcode']);
         if (isset($row['billing_street2'])) {
             $billingAddress->setStreet(array($row['billing_street1'], $row['billing_street2']));
         } else {
             $billingAddress->setStreet(array($row['billing_street1']));
         }
         if (isset($row['billing_telephone'])) {
             $billingAddress->setTelephone($row['billing_telephone']);
         }
         if (!$billingAddress->getId()) {
             $billingAddress->setIsDefaultBilling(true);
             if ($this->getDefaultBilling()) {
                 $this->setData('default_billing', '');
             }
             $this->addAddress($billingAddress);
         }
         // End handling billing address
     }
     if (!$this->validateAddress($row, 'shipping')) {
         $this->printError($hlp->__('Invalid shipping address for (%s).', $row['email']), $line);
     } else {
         // Handling shipping address
         $shippingAddress = $this->getPrimaryShippingAddress();
         if (!$shippingAddress instanceof Mage_Customer_Model_Address) {
             $shippingAddress = new Mage_Customer_Model_Address();
         }
         $regions->addRegionNameFilter($row['shipping_region'])->load();
         if ($regions) {
             foreach ($regions as $region) {
                 $regionId = $region->getId();
             }
         }
         $shippingAddress->setFirstname($row['firstname']);
         $shippingAddress->setLastname($row['lastname']);
         $shippingAddress->setCity($row['shipping_city']);
         $shippingAddress->setRegion($row['shipping_region']);
         if (isset($regionId)) {
             $shippingAddress->setRegionId($regionId);
         }
         $shippingAddress->setCountryId($row['shipping_country']);
         $shippingAddress->setPostcode($row['shipping_postcode']);
         if (isset($row['shipping_street2'])) {
             $shippingAddress->setStreet(array($row['shipping_street1'], $row['shipping_street2']));
         } else {
             $shippingAddress->setStreet(array($row['shipping_street1']));
         }
         if (!empty($row['shipping_telephone'])) {
             $shippingAddress->setTelephone($row['shipping_telephone']);
         }
         if (!$shippingAddress->getId()) {
             $shippingAddress->setIsDefaultShipping(true);
             $this->addAddress($shippingAddress);
         }
         // End handling shipping address
     }
     if (!empty($row['is_subscribed'])) {
         $this->setIsSubscribed(strtolower($row['is_subscribed']) == self::SUBSCRIBED_YES ? 1 : 0);
     }
     unset($row);
     return $this;
 }