Esempio n. 1
0
 /**
  * @param Mage_Customer_Model_Customer $customer
  */
 protected function _anonymizeCustomer($customer)
 {
     $randomData = $this->_getRandomData();
     foreach ($this->_getCustomerMapping() as $customerKey => $randomDataKey) {
         if (!$customer->getData($customerKey)) {
             continue;
         }
         if (strlen($randomDataKey)) {
             $customer->setData($customerKey, $randomData[$randomDataKey]);
         } else {
             $customer->setData($customerKey, '');
         }
     }
     $customer->getResource()->save($customer);
     $this->_anonymizedCustomerIds[] = $customer->getId();
     /* @var $subscriber Mage_Newsletter_Model_Subscriber */
     $subscriber = Mage::getModel('newsletter/subscriber');
     $subscriber->loadByEmail($customer->getOrigData('email'));
     if ($subscriber->getId()) {
         $this->_anonymizeNewsletterSubscriber($subscriber, $randomData);
     }
     $this->_anonymizeQuotes($customer, $randomData);
     $this->_anonymizeOrders($customer, $randomData);
     $this->_anonymizeCustomerAddresses($customer, $randomData);
 }
Esempio n. 2
0
 /**
  * Provides functionality for getters and setters of the customer
  * @see Varien_Object::__call()
  */
 public function __call($method, $args)
 {
     if ($this->_customer instanceof Mage_Customer_Model_Customer) {
         $key = $this->_underscore(substr($method, 3));
         switch (substr($method, 0, 3)) {
             case 'get':
                 return $this->_customer->getData($key, isset($args[0]) ? $args[0] : null);
             case 'set':
                 return $this->_customer->setData($key, isset($args[0]) ? $args[0] : null);
             case 'uns':
                 return $this->_customer->unsetData($key);
             case 'has':
                 $data = $this->_customer->getData();
                 return isset($data[$key]);
         }
         try {
             $_reflectionObject = new ReflectionObject($this->_customer);
             if ($_reflectionObject->hasMethod($method)) {
                 $_reflectionMethod = new ReflectionMethod(get_class($this->_customer), $method);
                 return $_reflectionMethod->invokeArgs($this->_customer, $args);
             }
         } catch (Exception $e) {
             return parent::__call($method, $args);
         }
     }
     return parent::__call($method, $args);
 }
Esempio n. 3
0
 public function connectByEmail(Mage_Customer_Model_Customer $customer, $Id, $token, $type)
 {
     $tokenName = "amajaxlogin_" . $type . "_token";
     $idName = "amajaxlogin_" . $type . "_id";
     $customer->setData($idName, $Id)->setData($tokenName, $token)->save();
     Mage::getSingleton('customer/session')->setCustomerAsLoggedIn($customer);
 }
Esempio n. 4
0
 /**
  * Prepare data before attribute save
  *
  * @param Mage_Customer_Model_Customer $customer
  * @return Mage_Customer_Model_Attribute_Backend_Data_Boolean
  */
 public function beforeSave($customer)
 {
     $attributeName = $this->getAttribute()->getName();
     $inputValue = $customer->getData($attributeName);
     $sanitizedValue = !empty($inputValue) ? '1' : '0';
     $customer->setData($attributeName, $sanitizedValue);
     return $this;
 }
 protected function _customerAddress(Mage_Customer_Model_Customer &$customer)
 {
     $_address = $customer->getDefaultBillingAddress();
     //use default billing address as address synced in Marketo
     if (!$_address) {
         return false;
     }
     //PREPARE ADDITIONAL DATA
     $_address->setData($this->_addressKey, true);
     $this->_prepareData($_address);
     foreach ($_address->getData() as $field => $value) {
         if (!$customer->hasData($field)) {
             //replace only when customer
             $customer->setData($field, $value);
         }
     }
     return true;
 }
Esempio n. 6
0
 public function _saveAddresses(Mage_Customer_Model_Customer $customer)
 {
     $defaultBillingId = $customer->getData('default_billing');
     $defaultShippingId = $customer->getData('default_shipping');
     $defaultPickupId = $customer->getData('default_pickup');
     foreach ($customer->getAddresses() as $address) {
         if ($address->getData('_deleted')) {
             if ($address->getId() == $defaultBillingId) {
                 $customer->setData('default_billing', null);
             }
             if ($address->getId() == $defaultShippingId) {
                 $customer->setData('default_shipping', null);
             }
             if ($address->getId() == $defaultPickupId) {
                 $customer->setData('default_pickup', null);
             }
             $address->delete();
         } else {
             $address->setParentId($customer->getId())->setStoreId($customer->getStoreId())->setIsCustomerSaveTransaction(true)->save();
             if (($address->getIsPrimaryBilling() || $address->getIsDefaultBilling()) && $address->getId() != $defaultBillingId) {
                 $customer->setData('default_billing', $address->getId());
             }
             if (($address->getIsPrimaryShipping() || $address->getIsDefaultShipping()) && $address->getId() != $defaultShippingId) {
                 $customer->setData('default_shipping', $address->getId());
             }
             if (($address->getIsPrimaryPickup() || $address->getIsDefaultPickup()) && $address->getId() != $defaultPickupId) {
                 $customer->setData('default_pickup', $address->getId());
             }
         }
     }
     if ($customer->dataHasChangedFor('default_billing')) {
         $this->saveAttribute($customer, 'default_billing');
     }
     if ($customer->dataHasChangedFor('default_shipping')) {
         $this->saveAttribute($customer, 'default_shipping');
     }
     if ($customer->dataHasChangedFor('default_pickup')) {
         $this->saveAttribute($customer, 'default_pickup');
     }
     return $this;
 }
Esempio n. 7
0
 /**
  * Save/delete customer address
  *
  * @param Mage_Customer_Model_Customer $customer
  * @return Mage_Customer_Model_Entity_Customer
  */
 protected function _saveAddresses(Mage_Customer_Model_Customer $customer)
 {
     foreach ($customer->getAddresses() as $address) {
         if ($address->getData('_deleted')) {
             if ($address->getId() == $customer->getData('default_billing')) {
                 $customer->setData('default_billing', null);
             }
             if ($address->getId() == $customer->getData('default_shipping')) {
                 $customer->setData('default_shipping', null);
             }
             $address->delete();
         } else {
             $address->setParentId($customer->getId())->setStoreId($customer->getStoreId())->save();
             if ($address->getIsPrimaryBilling() && $address->getId() != $customer->getData('default_billing')) {
                 $customer->setData('default_billing', $address->getId());
             }
             if ($address->getIsPrimaryShipping() && $address->getId() != $customer->getData('default_shipping')) {
                 $customer->setData('default_shipping', $address->getId());
             }
         }
         if ($customer->dataHasChangedFor('default_billing')) {
             $this->saveAttribute($customer, 'default_billing');
         }
         if ($customer->dataHasChangedFor('default_shipping')) {
             $this->saveAttribute($customer, 'default_shipping');
         }
     }
     return $this;
 }
Esempio n. 8
0
 /**
  * Edit/View Existing Customer form fields
  *
  * @param Varien_Data_Form $form
  * @param Varien_Data_Form_Element_Fieldset $fieldset
  * @param Mage_Customer_Model_Customer $customer
  */
 protected function _addEditCustomerFormFields($form, $fieldset, $customer)
 {
     $form->getElement('created_in')->setDisabled('disabled');
     if (!Mage::app()->isSingleStoreMode()) {
         $form->getElement('website_id')->setDisabled('disabled');
         $renderer = $this->getLayout()->createBlock('Mage_Adminhtml_Block_Store_Switcher_Form_Renderer_Fieldset_Element');
         $form->getElement('website_id')->setRenderer($renderer);
     } else {
         $fieldset->removeField('website_id');
     }
     if ($customer->isReadonly()) {
         return;
     }
     $this->_addPasswordManagementFieldset($form, 'New Password', true);
     // Prepare customer confirmation control (only for existing customers)
     $confirmationKey = $customer->getConfirmation();
     if ($confirmationKey || $customer->isConfirmationRequired()) {
         $confirmationAttr = $customer->getAttribute('confirmation');
         if (!$confirmationKey) {
             $confirmationKey = $customer->getRandomConfirmationKey();
         }
         $element = $fieldset->addField('confirmation', 'select', array('name' => 'confirmation', 'label' => Mage::helper('Mage_Customer_Helper_Data')->__($confirmationAttr->getFrontendLabel())));
         $element->setEntityAttribute($confirmationAttr);
         $element->setValues(array('' => 'Confirmed', $confirmationKey => 'Not confirmed'));
         // Prepare send welcome email checkbox if customer is not confirmed
         // no need to add it, if website ID is empty
         if ($customer->getConfirmation() && $customer->getWebsiteId()) {
             $fieldset->addField('sendemail', 'checkbox', array('name' => 'sendemail', 'label' => Mage::helper('Mage_Customer_Helper_Data')->__('Send Welcome Email after Confirmation')));
             $customer->setData('sendemail', '1');
         }
     }
 }
Esempio n. 9
0
 /**
  * Prepare customer data for update
  *
  * @param array $rowData
  * @return array
  */
 protected function _prepareDataForUpdate(array $rowData)
 {
     /** @var $passwordAttribute Mage_Customer_Model_Attribute */
     $passwordAttribute = $this->_customerModel->getAttribute('password_hash');
     $passwordAttributeId = $passwordAttribute->getId();
     $passwordStorageTable = $passwordAttribute->getBackend()->getTable();
     $entitiesToCreate = array();
     $entitiesToUpdate = array();
     $attributesToSave = array();
     // entity table data
     $now = new DateTime('@' . time());
     if (empty($rowData['created_at'])) {
         $createdAt = $now;
     } else {
         $createdAt = new DateTime('@' . strtotime($rowData['created_at']));
     }
     $entityRow = array('group_id' => empty($rowData['group_id']) ? self::DEFAULT_GROUP_ID : $rowData['group_id'], 'store_id' => empty($rowData[self::COLUMN_STORE]) ? 0 : $this->_storeCodeToId[$rowData[self::COLUMN_STORE]], 'created_at' => $createdAt->format(Varien_Date::DATETIME_PHP_FORMAT), 'updated_at' => $now->format(Varien_Date::DATETIME_PHP_FORMAT));
     $emailInLowercase = strtolower($rowData[self::COLUMN_EMAIL]);
     if ($entityId = $this->_getCustomerId($emailInLowercase, $rowData[self::COLUMN_WEBSITE])) {
         // edit
         $entityRow['entity_id'] = $entityId;
         $entitiesToUpdate[] = $entityRow;
     } else {
         // create
         $entityId = $this->_getNextEntityId();
         $entityRow['entity_id'] = $entityId;
         $entityRow['entity_type_id'] = $this->getEntityTypeId();
         $entityRow['attribute_set_id'] = 0;
         $entityRow['website_id'] = $this->_websiteCodeToId[$rowData[self::COLUMN_WEBSITE]];
         $entityRow['email'] = $emailInLowercase;
         $entityRow['is_active'] = 1;
         $entitiesToCreate[] = $entityRow;
         $this->_newCustomers[$emailInLowercase][$rowData[self::COLUMN_WEBSITE]] = $entityId;
     }
     // attribute values
     foreach (array_intersect_key($rowData, $this->_attributes) as $attributeCode => $value) {
         if (!$this->_attributes[$attributeCode]['is_static'] && strlen($value)) {
             /** @var $attribute Mage_Customer_Model_Attribute */
             $attribute = $this->_customerModel->getAttribute($attributeCode);
             $backendModel = $attribute->getBackendModel();
             $attributeParameters = $this->_attributes[$attributeCode];
             if ('select' == $attributeParameters['type']) {
                 $value = $attributeParameters['options'][strtolower($value)];
             } elseif ('datetime' == $attributeParameters['type']) {
                 $value = new DateTime('@' . strtotime($value));
                 $value = $value->format(Varien_Date::DATETIME_PHP_FORMAT);
             } elseif ($backendModel) {
                 $attribute->getBackend()->beforeSave($this->_customerModel->setData($attributeCode, $value));
                 $value = $this->_customerModel->getData($attributeCode);
             }
             $attributesToSave[$attribute->getBackend()->getTable()][$entityId][$attributeParameters['id']] = $value;
             // restore 'backend_model' to avoid default setting
             $attribute->setBackendModel($backendModel);
         }
     }
     // password change/set
     if (isset($rowData['password']) && strlen($rowData['password'])) {
         $attributesToSave[$passwordStorageTable][$entityId][$passwordAttributeId] = $this->_customerModel->hashPassword($rowData['password']);
     }
     return array(self::ENTITIES_TO_CREATE_KEY => $entitiesToCreate, self::ENTITIES_TO_UPDATE_KEY => $entitiesToUpdate, self::ATTRIBUTES_TO_SAVE_KEY => $attributesToSave);
 }
Esempio n. 10
0
 /**
  * Save/delete customer address
  *
  * @param Mage_Customer_Model_Customer $customer
  * @return Mage_Customer_Model_Resource_Customer
  */
 protected function _saveAddresses(Mage_Customer_Model_Customer $customer)
 {
     $defaultBillingId = $customer->getData('default_billing');
     $defaultShippingId = $customer->getData('default_shipping');
     /** @var Mage_Customer_Model_Address $address */
     foreach ($customer->getAddresses() as $address) {
         if ($address->getData('_deleted')) {
             if ($address->getId() == $defaultBillingId) {
                 $customer->setData('default_billing', null);
             }
             if ($address->getId() == $defaultShippingId) {
                 $customer->setData('default_shipping', null);
             }
             $removedAddressId = $address->getId();
             $address->delete();
             // Remove deleted address from customer address collection
             $customer->getAddressesCollection()->removeItemByKey($removedAddressId);
         } else {
             $address->setParentId($customer->getId())->setStoreId($customer->getStoreId())->setIsCustomerSaveTransaction(true)->save();
             if (($address->getIsPrimaryBilling() || $address->getIsDefaultBilling()) && $address->getId() != $defaultBillingId) {
                 $customer->setData('default_billing', $address->getId());
             }
             if (($address->getIsPrimaryShipping() || $address->getIsDefaultShipping()) && $address->getId() != $defaultShippingId) {
                 $customer->setData('default_shipping', $address->getId());
             }
         }
     }
     if ($customer->dataHasChangedFor('default_billing')) {
         $this->saveAttribute($customer, 'default_billing');
     }
     if ($customer->dataHasChangedFor('default_shipping')) {
         $this->saveAttribute($customer, 'default_shipping');
     }
     return $this;
 }