Example #1
0
 /**
  * @param Mage_Customer_Model_Address $address
  * @return bool
  */
 public function addressIsValid($address)
 {
     $isValid = true;
     foreach ($this->_requiredFields as $field => $validator) {
         if (!Zend_Validate::is($address->getData($field), $validator)) {
             $isValid = false;
         }
     }
     return $isValid;
 }
Example #2
0
 /**
  * Check whether specified address should be processed in after_save event handler
  *
  * @param Mage_Customer_Model_Address $address
  * @return bool
  */
 protected function _canProcessAddress($address)
 {
     if ($address->getForceProcess()) {
         return true;
     }
     if (Mage::registry(self::VIV_CURRENTLY_SAVED_ADDRESS) != $address->getId()) {
         return false;
     }
     $configAddressType = Mage::helper('customer/address')->getTaxCalculationAddressType();
     if ($configAddressType == Mage_Customer_Model_Address_Abstract::TYPE_SHIPPING) {
         return $this->_isDefaultShipping($address);
     }
     return $this->_isDefaultBilling($address);
 }
 public function setIsDefaultBilling($value)
 {
     if (false === $this->_isFixed()) {
         parent::setIsDefaultBilling($value);
     }
     return $this;
 }
Example #4
0
 /**
  * Collect address data to xml node
  * Remove objects from data array and escape data values
  *
  * @param Mage_Customer_Model_Address $address
  * @param Mage_XmlConnect_Model_Simplexml_Element $item
  * @return array
  */
 public function prepareAddressData(Mage_Customer_Model_Address $address, Mage_XmlConnect_Model_Simplexml_Element $item)
 {
     if (!$address) {
         return array();
     }
     $attributes = Mage::helper('Mage_Customer_Helper_Address')->getAttributes();
     $data = array('entity_id' => $address->getId());
     foreach ($attributes as $attribute) {
         /* @var $attribute Mage_Customer_Model_Attribute */
         if (!$attribute->getIsVisible()) {
             continue;
         }
         if ($attribute->getAttributeCode() == 'country_id') {
             $data['country'] = $address->getCountryModel()->getName();
             $data['country_id'] = $address->getCountryId();
         } else {
             if ($attribute->getAttributeCode() == 'region') {
                 $data['region'] = $address->getRegion();
             } else {
                 $dataModel = Mage_Customer_Model_Attribute_Data::factory($attribute, $address);
                 $value = $dataModel->outputValue(Mage_Customer_Model_Attribute_Data::OUTPUT_FORMAT_ONELINE);
                 if ($attribute->getFrontendInput() == 'multiline') {
                     $values = $dataModel->outputValue(Mage_Customer_Model_Attribute_Data::OUTPUT_FORMAT_ARRAY);
                     // explode lines
                     foreach ($values as $k => $v) {
                         $key = sprintf('%s%d', $attribute->getAttributeCode(), $k + 1);
                         $data[$key] = $v;
                     }
                 }
                 $data[$attribute->getAttributeCode()] = $value;
             }
         }
     }
     foreach ($data as $key => $value) {
         if (empty($value)) {
             continue;
         }
         $item->addChild($key, $item->escapeXml($value));
     }
 }
 /**
  * Validate data for change association with the country
  *
  * @param Mage_Customer_Model_Address $address
  * @param array $data
  * @return bool
  */
 public function isValidDataForChangeAssociationWithCountry(Mage_Customer_Model_Address $address, array $data)
 {
     if (!isset($data['country_id']) && !isset($data['region'])) {
         return true;
     }
     // If country is in data - it has been already validated. If no - load current country.
     if (isset($data['country_id'])) {
         $country = Mage::getModel('directory/country')->loadByCode($data['country_id']);
     } else {
         $country = $address->getCountryModel();
     }
     return $this->_checkRegion($data, $country);
 }
 /**
  * Takes a magento address object and generates an array 
  * containing data for gateway request
  *
  * @param Mage_Customer_Model_Address $address
  *
  * @return array
  */
 public function convertAddress($address)
 {
     if ($this->getConfig()->isConsumerCheck()) {
         switch ($address->getCountryId()) {
             case 'AT':
                 $staat = '040';
                 break;
             case 'CH':
                 $staat = '756';
                 break;
             case 'DE':
                 $staat = '280';
                 break;
             default:
                 $staat = '276';
                 break;
         }
     } else {
         $staat = 'DE' == $address->getCountryId() ? '280' : '276';
     }
     $addressData = array($this->_getFirstNameFieldName() => utf8_decode($this->_getFirstNameValue($address)), $this->_getLastNameFieldName() => utf8_decode($this->_getLastNameValue($address)), 'STRASSE' => utf8_decode($this->getStreet(implode(' ', $address->getStreet()))), 'HAUS_NR' => utf8_decode($this->getStreetNumber(implode(' ', $address->getStreet()))), 'ORT' => utf8_decode($address->getCity()), 'PLZ' => utf8_decode($address->getPostcode()), 'STAAT' => $staat);
     return $addressData;
 }
 /**
  * Return customer address formated as one-line string
  *
  * @param Mage_Customer_Model_Address $address
  * @return string
  */
 public function getAddressAsString($address)
 {
     return $this->htmlEscape($address->format('oneline'));
 }
Example #8
0
 /**
  * @param Mage_Customer_Model_Address $address
  * @return array|null
  */
 protected function _createPhoneNumber(Mage_Customer_Model_Address $address)
 {
     $primaryPhone = $address->getTelephone();
     $data = array('number' => $primaryPhone, 'type' => 'UNKNOWN');
     return $data;
 }
Example #9
0
 /**
  * Perform basic validation
  *
  * @return void
  */
 protected function _basicCheck()
 {
     parent::_basicCheck();
     Mage::helper('pagarme')->_validateCustomerAddress($this);
 }
Example #10
0
 /**
  * Get region filter
  *
  * @param Mage_Customer_Model_Address $address
  * @param int                         $storeId
  * @return string|bool
  */
 protected function _getFilterRegion($address, $storeId)
 {
     $filter = false;
     $regionFilters = explode(',', Mage::getStoreConfig('tax/avatax/region_filter_list', $storeId));
     $entityId = $address->getRegionId() ?: $address->getCountryId();
     if (!in_array($entityId, $regionFilters)) {
         $filter = 'region';
     }
     return $filter;
 }
 /**
  * Convert magento address to array for braintree
  * 
  * @param Mage_Customer_Model_Address $address
  * @return array
  */
 protected function _toBraintreeAddress($address)
 {
     if ($address) {
         return array('firstName' => $address->getFirstname(), 'lastName' => $address->getLastname(), 'company' => $address->getCompany(), 'streetAddress' => $address->getStreet(1), 'extendedAddress' => $address->getStreet(2), 'locality' => $address->getCity(), 'region' => $address->getRegion(), 'postalCode' => $address->getPostcode(), 'countryCodeAlpha2' => $address->getCountry());
     } else {
         return array();
     }
 }
Example #12
0
 /**
  * @param Mage_Customer_Model_Address $customerAddress
  * @param array $randomData
  */
 protected function _anonymizeOrderAddresses($customerAddress, $randomData)
 {
     $orderAddresses = Mage::getModel('sales/order_address')->getCollection()->addFieldToFilter('customer_address_id', $customerAddress->getId());
     foreach ($orderAddresses as $orderAddress) {
         $this->_anonymizeOrderAddress($orderAddress, $randomData);
     }
 }
 /**
  * Build a Magento address model into a Braintree array
  *
  * @param Mage_Sales_Model_Order_Address|Mage_Sales_Model_Quote_Address|Mage_Customer_Model_Address $address
  *
  * @return array
  */
 private function buildAddress($address)
 {
     // Build up the initial array
     $return = array('firstName' => $address->getFirstname(), 'lastName' => $address->getLastname(), 'streetAddress' => $address->getStreet1(), 'locality' => $address->getCity(), 'postalCode' => $address->getPostcode(), 'countryCodeAlpha2' => $address->getCountry());
     // Any extended address?
     if ($address->getStreet2()) {
         $return['extendedAddress'] = $address->getStreet2();
     }
     // Region
     if ($address->getRegion()) {
         $return['region'] = $address->getRegionCode();
     }
     // Check to see if we have a company
     if ($address->getCompany()) {
         $return['company'] = $address->getCompany();
     }
     return $return;
 }
Example #14
0
 /**
  * Sets up address data to the GiftRegistry entity  object
  *
  * @param Mage_Customer_Model_Address $address
  * @return $this
  */
 public function importAddress(Mage_Customer_Model_Address $address)
 {
     $skip = array('increment_id', 'entity_type_id', 'parent_id', 'entity_id', 'attribute_set_id');
     $data = array();
     $attributes = $address->getAttributes();
     foreach ($attributes as $attribute) {
         if (!in_array($attribute->getAttributeCode(), $skip)) {
             $data[$attribute->getAttributeCode()] = $address->getData($attribute->getAttributeCode());
         }
     }
     $this->setData('shipping_address', serialize($data));
     return $this;
 }
Example #15
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;
 }
Example #16
0
 /**
  * _cleanPhone
  *
  * strip non-digit characters from phone/fax numbers
  *
  * @param  Mage_Customer_Model_Address $address
  * @param  string                      $type    # (i.e., 'fax' or 'telephone')
  * @param  string                      $pattern # regex pattern to use
  * @return string
  */
 protected function _cleanPhone(Mage_Customer_Model_Address $address, $type = 'telephone', $pattern = "/[^\\d]/")
 {
     $number = $address->getData($type);
     $cleanNum = preg_replace($pattern, "", $number);
     return $cleanNum;
 }
Example #17
0
 /**
  * @param \Mage_Customer_Model_Address $address
  * @return $this
  */
 public function withAddress($address)
 {
     $this->model->getBillingAddress()->addData($address->getData());
     $this->model->getShippingAddress()->addData($address->getData())->setCollectShippingRates(true)->collectShippingRates()->setShippingMethod($this->attributes['shipping_method'])->setPaymentMethod($this->attributes['payment_method']);
     return $this;
 }
 protected function _basicCheck()
 {
     parent::_basicCheck();
     $this->_errors = Mage::helper('Twinsen_NoTelephoneRequired')->processErrors($this->_errors);
 }
Example #19
0
 * to license@magentocommerce.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Magento to newer
 * versions in the future. If you wish to customize Magento for your
 * needs please refer to http://www.magentocommerce.com for more information.
 *
 * @category    Magento
 * @package     Mage_ImportExport
 * @subpackage  integration_tests
 * @copyright   Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
 * @license     http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 */
//Create customer
$customer = new Mage_Customer_Model_Customer();
$customer->setWebsiteId(1)->setEntityId(1)->setEntityTypeId(1)->setAttributeSetId(0)->setEmail('*****@*****.**')->setPassword('password')->setGroupId(1)->setStoreId(1)->setIsActive(1)->setFirstname('Charles')->setLastname('Alston')->setGender(2);
$customer->isObjectNew(true);
// Create address
$address = new Mage_Customer_Model_Address();
//  default_billing and default_shipping information would not be saved, it is needed only for simple check
$address->addData(array('firstname' => 'Charles', 'lastname' => 'Alston', 'street' => '3781 Neuport Lane', 'city' => 'Panola', 'country_id' => 'US', 'region_id' => '51', 'postcode' => '30058', 'telephone' => '770-322-3514', 'default_billing' => 1, 'default_shipping' => 1));
// Assign customer and address
$customer->addAddress($address);
$customer->save();
// Mark last address as default billing and default shipping for current customer
$customer->setDefaultBilling($address->getId());
$customer->setDefaultShipping($address->getId());
$customer->save();
Mage::unregister('_fixture/Mage_ImportExport_Customer');
Mage::register('_fixture/Mage_ImportExport_Customer', $customer);
Example #20
0
 /**
  * Do validation of customer and its address using validate methods in models
  *
  * @param Mage_Customer_Model_Customer $customer
  * @param Mage_Customer_Model_Address|null $address
  * @throws Magento_Validator_Exception
  */
 protected function _validateCustomer($customer, $address = null)
 {
     $errors = array();
     if ($address) {
         $addressErrors = $address->validate();
         if (is_array($addressErrors)) {
             $errors = array_merge($errors, $addressErrors);
         }
     }
     $customerErrors = $customer->validate();
     if (is_array($customerErrors)) {
         $errors = array_merge($errors, $customerErrors);
     }
     if (count($errors) > 0) {
         throw new Magento_Validator_Exception(array($errors));
     }
 }
Example #21
0
 /**
  * Return customer id
  * @deprecated
  *
  * @param Mage_Customer_Model_Address $object
  * @return int
  */
 public function getCustomerId($object)
 {
     return $object->getData('customer_id') ? $object->getData('customer_id') : $object->getParentId();
 }
$customer->setDefaultBilling($address->getId());
$customer->setDefaultShipping($address->getId());
$customer->save();
$customers[] = $customer;
$customer = new Mage_Customer_Model_Customer();
$customer->setWebsiteId(1)->setEntityId(2)->setEntityTypeId(1)->setAttributeSetId(0)->setEmail('*****@*****.**')->setPassword('password')->setGroupId(1)->setStoreId(1)->setIsActive(1)->setFirstname('Anthony')->setLastname('Nealy')->setGender(1);
$customer->isObjectNew(true);
$address = new Mage_Customer_Model_Address();
$address->addData(array('firstname' => 'Anthony', 'lastname' => 'Nealy', 'street' => '3176 Cambridge Court', 'city' => 'Fayetteville', 'country_id' => 'US', 'region_id' => '5', 'postcode' => '72701', 'telephone' => '479-899-9849', 'default_billing' => 0, 'default_shipping' => 0));
$customer->addAddress($address);
$address = new Mage_Customer_Model_Address();
$address->addData(array('firstname' => 'Anthony', 'lastname' => 'Nealy', 'street' => '4709 Pleasant Hill Road', 'city' => 'Irvine', 'country_id' => 'US', 'region_id' => '12', 'postcode' => '92664', 'telephone' => '562-208-2310', 'default_billing' => 1, 'default_shipping' => 1));
$customer->addAddress($address);
$customer->save();
$customer->setDefaultBilling($address->getId());
$customer->setDefaultShipping($address->getId());
$customer->save();
$customers[] = $customer;
$customer = new Mage_Customer_Model_Customer();
$customer->setWebsiteId(1)->setEntityId(3)->setEntityTypeId(1)->setAttributeSetId(0)->setEmail('*****@*****.**')->setPassword('password')->setGroupId(1)->setStoreId(1)->setIsActive(1)->setFirstname('Lori')->setLastname('Banks')->setGender(2);
$customer->isObjectNew(true);
$address = new Mage_Customer_Model_Address();
$address->addData(array('firstname' => 'Lori', 'lastname' => 'Banks', 'street' => '2573 Goodwin Avenue', 'city' => 'Wenatchee', 'country_id' => 'US', 'region_id' => '62', 'postcode' => '98801', 'telephone' => '509-421-4364', 'default_billing' => 1, 'default_shipping' => 1));
$customer->addAddress($address);
$customer->save();
$customer->setDefaultBilling($address->getId());
$customer->setDefaultShipping($address->getId());
$customer->save();
$customers[] = $customer;
Mage::unregister('_fixture/Mage_ImportExport_Customers_Array');
Mage::register('_fixture/Mage_ImportExport_Customers_Array', $customers);
Example #23
0
 /**
  * get gender according to shopgate needs
  *
  * @param Mage_Customer_Model_Customer|Mage_Customer_Model_Address $data
  * @return string
  */
 public function getShopgateCustomerGender($data)
 {
     $options = Mage::getResourceModel('customer/customer')->getAttribute('gender')->getSource()->getAllOptions(false);
     $gender = null;
     foreach ($options as $option) {
         if ($option['value'] == $data->getGender()) {
             $gender = $option['label'];
         }
     }
     switch ($gender) {
         case 'Male':
             return ShopgateCustomer::MALE;
             break;
         case 'Female':
             return ShopgateCustomer::FEMALE;
             break;
         default:
             return '';
     }
 }
Example #24
0
 /**
  * Import quote address data from customer address object
  *
  * @param   Mage_Customer_Model_Address $address
  * @return  Mage_Sales_Model_Quote_Address
  */
 public function importCustomerAddress(Mage_Customer_Model_Address $address)
 {
     $this->setCustomerAddressId($address->getId())->setCustomerId($address->getParentId())->setEmail($address->hasEmail() ? $address->getEmail() : $address->getCustomer()->getEmail())->setFirstname($address->getFirstname())->setLastname($address->getLastname())->setCompany($address->getCompany())->setStreet($address->getStreet())->setCity($address->getCity())->setRegion($address->getRegion())->setRegionId($address->getRegionId())->setPostcode($address->getPostcode())->setCountryId($address->getCountryId())->setTelephone($address->getTelephone())->setFax($address->getFax());
     return $this;
 }
 /**
  * @deprecated not used anymore
  */
 public function parse()
 {
     $data = $this->getData();
     $entityTypeId = Mage::getSingleton('eav/config')->getEntityType('customer')->getId();
     $result = array();
     foreach ($data as $i => $row) {
         $this->setPosition('Line: ' . ($i + 1));
         try {
             // validate SKU
             if (empty($row['email'])) {
                 $this->addException(Mage::helper('customer')->__('Missing email, skipping the record'), Varien_Convert_Exception::ERROR);
                 continue;
             }
             $this->setPosition('Line: ' . ($i + 1) . ', email: ' . $row['email']);
             // try to get entity_id by sku if not set
             /*
             if (empty($row['entity_id'])) {
                 $row['entity_id'] = $this->getResource()->getProductIdBySku($row['email']);
             }
             */
             // if attribute_set not set use default
             if (empty($row['attribute_set'])) {
                 $row['attribute_set'] = 'Default';
             }
             // get attribute_set_id, if not throw error
             $row['attribute_set_id'] = $this->getAttributeSetId($entityTypeId, $row['attribute_set']);
             if (!$row['attribute_set_id']) {
                 $this->addException(Mage::helper('customer')->__("Invalid attribute set specified, skipping the record"), Varien_Convert_Exception::ERROR);
                 continue;
             }
             if (empty($row['group'])) {
                 $row['group'] = 'General';
             }
             if (empty($row['firstname'])) {
                 $this->addException(Mage::helper('customer')->__('Missing firstname, skipping the record'), Varien_Convert_Exception::ERROR);
                 continue;
             }
             //$this->setPosition('Line: '.($i+1).', Firstname: '.$row['firstname']);
             if (empty($row['lastname'])) {
                 $this->addException(Mage::helper('customer')->__('Missing lastname, skipping the record'), Varien_Convert_Exception::ERROR);
                 continue;
             }
             //$this->setPosition('Line: '.($i+1).', Lastname: '.$row['lastname']);
             /*
             // get product type_id, if not throw error
             $row['type_id'] = $this->getProductTypeId($row['type']);
             if (!$row['type_id']) {
                 $this->addException(Mage::helper('catalog')->__("Invalid product type specified, skipping the record"), Varien_Convert_Exception::ERROR);
                 continue;
             }
             */
             // get store ids
             $storeIds = $this->getStoreIds(isset($row['store']) ? $row['store'] : $this->getVar('store'));
             if (!$storeIds) {
                 $this->addException(Mage::helper('customer')->__("Invalid store specified, skipping the record"), Varien_Convert_Exception::ERROR);
                 continue;
             }
             // import data
             $rowError = false;
             foreach ($storeIds as $storeId) {
                 $collection = $this->getCollection($storeId);
                 //print_r($collection);
                 $entity = $collection->getEntity();
                 $model = Mage::getModel('customer/customer');
                 $model->setStoreId($storeId);
                 if (!empty($row['entity_id'])) {
                     $model->load($row['entity_id']);
                 }
                 foreach ($row as $field => $value) {
                     $attribute = $entity->getAttribute($field);
                     if (!$attribute) {
                         continue;
                         #$this->addException(Mage::helper('catalog')->__("Unknown attribute: %s", $field), Varien_Convert_Exception::ERROR);
                     }
                     if ($attribute->usesSource()) {
                         $source = $attribute->getSource();
                         $optionId = $this->getSourceOptionId($source, $value);
                         if (is_null($optionId)) {
                             $rowError = true;
                             $this->addException(Mage::helper('customer')->__("Invalid attribute option specified for attribute %s (%s), skipping the record", $field, $value), Varien_Convert_Exception::ERROR);
                             continue;
                         }
                         $value = $optionId;
                     }
                     $model->setData($field, $value);
                 }
                 //foreach ($row as $field=>$value)
                 $billingAddress = $model->getPrimaryBillingAddress();
                 $customer = Mage::getModel('customer/customer')->load($model->getId());
                 if (!$billingAddress instanceof Mage_Customer_Model_Address) {
                     $billingAddress = new Mage_Customer_Model_Address();
                     if ($customer->getId() && $customer->getDefaultBilling()) {
                         $billingAddress->setId($customer->getDefaultBilling());
                     }
                 }
                 $regions = Mage::getResourceModel('directory/region_collection')->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']);
                 $billingAddress->setRegionId($regionId);
                 $billingAddress->setCountryId($row['billing_country']);
                 $billingAddress->setPostcode($row['billing_postcode']);
                 $billingAddress->setStreet(array($row['billing_street1'], $row['billing_street2']));
                 if (!empty($row['billing_telephone'])) {
                     $billingAddress->setTelephone($row['billing_telephone']);
                 }
                 if (!$model->getDefaultBilling()) {
                     $billingAddress->setCustomerId($model->getId());
                     $billingAddress->setIsDefaultBilling(true);
                     $billingAddress->save();
                     $model->setDefaultBilling($billingAddress->getId());
                     $model->addAddress($billingAddress);
                     if ($customer->getDefaultBilling()) {
                         $model->setDefaultBilling($customer->getDefaultBilling());
                     } else {
                         $shippingAddress->save();
                         $model->setDefaultShipping($billingAddress->getId());
                         $model->addAddress($billingAddress);
                     }
                 }
                 $shippingAddress = $model->getPrimaryShippingAddress();
                 if (!$shippingAddress instanceof Mage_Customer_Model_Address) {
                     $shippingAddress = new Mage_Customer_Model_Address();
                     if ($customer->getId() && $customer->getDefaultShipping()) {
                         $shippingAddress->setId($customer->getDefaultShipping());
                     }
                 }
                 $regions = Mage::getResourceModel('directory/region_collection')->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']);
                 $shippingAddress->setRegionId($regionId);
                 $shippingAddress->setCountryId($row['shipping_country']);
                 $shippingAddress->setPostcode($row['shipping_postcode']);
                 $shippingAddress->setStreet(array($row['shipping_street1'], $row['shipping_street2']));
                 $shippingAddress->setCustomerId($model->getId());
                 if (!empty($row['shipping_telephone'])) {
                     $shippingAddress->setTelephone($row['shipping_telephone']);
                 }
                 if (!$model->getDefaultShipping()) {
                     if ($customer->getDefaultShipping()) {
                         $model->setDefaultShipping($customer->getDefaultShipping());
                     } else {
                         $shippingAddress->save();
                         $model->setDefaultShipping($shippingAddress->getId());
                         $model->addAddress($shippingAddress);
                     }
                     $shippingAddress->setIsDefaultShipping(true);
                 }
                 if (!$rowError) {
                     $collection->addItem($model);
                 }
             }
             //foreach ($storeIds as $storeId)
         } catch (Exception $e) {
             if (!$e instanceof Mage_Dataflow_Model_Convert_Exception) {
                 $this->addException(Mage::helper('customer')->__("Error during retrieval of option value: %s", $e->getMessage()), Mage_Dataflow_Model_Convert_Exception::FATAL);
             }
         }
     }
     $this->setData($this->_collections);
     return $this;
 }
 /**
  * Is specified address a default shipping address?
  *
  * @param Mage_Customer_Model_Address $address
  * @return bool
  */
 protected function _isDefaultShippingAddress(Mage_Customer_Model_Address $address)
 {
     return $address->getCustomer()->getDefaultShipping() == $address->getId();
 }
Example #27
0
 /**
  * Check if address is primary
  *
  * @param Mage_Customer_Model_Address $address
  * @return boolean
  */
 public function isAddressPrimary(Mage_Customer_Model_Address $address)
 {
     if (!$address->getId()) {
         return false;
     }
     return $address->getId() == $this->getDefaultBilling() || $address->getId() == $this->getDefaultShipping();
 }
Example #28
0
 /**
  * Set customer id
  *
  * @deprecated
  * @param Mage_Customer_Model_Address $object
  * @param integer $id
  * @return Mage_Customer_Model_Address
  */
 public function setCustomerId($object, $id)
 {
     $object->setParentId($id);
     $object->setData('customer_id', $id);
     return $object;
 }
Example #29
0
 /**
  * Get validation message that will be displayed to user by VAT validation result object
  *
  * @param Mage_Customer_Model_Address $customerAddress
  * @param bool $customerGroupAutoAssignDisabled
  * @param Varien_Object $validationResult
  * @return Varien_Object
  */
 public function getVatValidationUserMessage($customerAddress, $customerGroupAutoAssignDisabled, $validationResult)
 {
     $message = '';
     $isError = true;
     $customerVatClass = $this->getCustomerVatClass($customerAddress->getCountryId(), $validationResult);
     $groupAutoAssignDisabled = Mage::getStoreConfigFlag(self::XML_PATH_CUSTOMER_VIV_GROUP_AUTO_ASSIGN);
     $willChargeTaxMessage = $this->__('You will be charged tax.');
     $willNotChargeTaxMessage = $this->__('You will not be charged tax.');
     if ($validationResult->getIsValid()) {
         $message = $this->__('Your VAT ID was successfully validated.');
         $isError = false;
         if (!$groupAutoAssignDisabled && !$customerGroupAutoAssignDisabled) {
             $message .= ' ' . ($customerVatClass == self::VAT_CLASS_DOMESTIC ? $willChargeTaxMessage : $willNotChargeTaxMessage);
         }
     } else {
         if ($validationResult->getRequestSuccess()) {
             $message = sprintf($this->__('The VAT ID entered (%s) is not a valid VAT ID.') . ' ', $this->escapeHtml($customerAddress->getVatId()));
             if (!$groupAutoAssignDisabled && !$customerGroupAutoAssignDisabled) {
                 $message .= $willChargeTaxMessage;
             }
         } else {
             $contactUsMessage = sprintf($this->__('If you believe this is an error, please contact us at %s'), Mage::getStoreConfig(self::XML_PATH_SUPPORT_EMAIL));
             $message = $this->__('Your Tax ID cannot be validated.') . ' ' . (!$groupAutoAssignDisabled && !$customerGroupAutoAssignDisabled ? $willChargeTaxMessage . ' ' : '') . $contactUsMessage;
         }
     }
     $validationMessageEnvelope = new Varien_Object();
     $validationMessageEnvelope->setMessage($message);
     $validationMessageEnvelope->setIsError($isError);
     return $validationMessageEnvelope;
 }
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Magento to newer
 * versions in the future. If you wish to customize Magento for your
 * needs please refer to http://www.magentocommerce.com for more information.
 *
 * @category    Magento
 * @package     Mage_ImportExport
 * @subpackage  integration_tests
 * @copyright   Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
 * @license     http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 */
//Create customer
$customer = new Mage_Customer_Model_Customer();
$customer->setWebsiteId(0)->setEntityId(1)->setEntityTypeId(1)->setAttributeSetId(0)->setEmail('*****@*****.**')->setPassword('password')->setGroupId(0)->setStoreId(0)->setIsActive(1)->setFirstname('Betsy')->setLastname('Parker')->setGender(2);
$customer->isObjectNew(true);
$customer->save();
// Create and set addresses
$addressFirst = new Mage_Customer_Model_Address();
$addressFirst->addData(array('entity_id' => 1, 'firstname' => 'Betsy', 'lastname' => 'Parker', 'street' => '1079 Rocky Road', 'city' => 'Philadelphia', 'country_id' => 'US', 'region_id' => '51', 'postcode' => '19107', 'telephone' => '215-629-9720'));
$addressFirst->isObjectNew(true);
$customer->addAddress($addressFirst);
$customer->setDefaultBilling($addressFirst->getId());
$addressSecond = new Mage_Customer_Model_Address();
$addressSecond->addData(array('entity_id' => 2, 'firstname' => 'Anthony', 'lastname' => 'Nealy', 'street' => '3176 Cambridge Court', 'city' => 'Fayetteville', 'country_id' => 'US', 'region_id' => '5', 'postcode' => '72701', 'telephone' => '479-899-9849'));
$addressSecond->isObjectNew(true);
$customer->addAddress($addressSecond);
$customer->setDefaultShipping($addressSecond->getId());
$customer->isObjectNew(true);
$customer->save();