/** * 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); }
/** * @param Mage_Customer_Model_Customer $customer * @return bool * @throws Exception */ public function isCustomerFacebookUser(Mage_Customer_Model_Customer $customer) { $customerEmail = $customer->getData('email'); $facebookUser = $this->getFacebookUser()->setData('store_id', $customer->getStoreId()); $facebookUser->loadByEmail($customerEmail); return (bool) $facebookUser->getId() && $customer->getStoreId() == $facebookUser->getData('store_id'); }
/** * @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); }
public function getData($key = '', $index = null) { switch ($key) { case 'value-ar-total': return $this->getDueTotals(); break; case 'value-ar-current': return $this->getDueTotals(0, 29); break; case 'value-ar-30days': return $this->getDueTotals(30, 59); break; case 'value-ar-60days': return $this->getDueTotals(60, 89); break; case 'value-ar-90days': return $this->getDueTotals(90, 119); break; case 'value-ar-120days': return $this->getDueTotals(120, 179); break; case 'value-ar-180days': return $this->getDueTotals(180, 239); break; case 'value-ar-240days': return $this->getDueTotals(240); break; default: return parent::getData($key, $index); } return parent::getData($key, $index); }
/** * 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; }
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; }
/** * Get Customer Info * * @param Mage_Customer_Model_Customer $customer got customer * @return void */ public function registerCustomerInfo($customer) { /** * @var $customer Mage_Customer_Model_Customer */ if ($customer) { $telephone = $customer->getData('oc_telephone'); $name = $customer->getName(); Mage::register('customer_name', $name); Mage::register('customer_phone', $telephone); } }
public function getCustomerData(Mage_Customer_Model_Customer $customer) { if (!$customer->getId()) { return array('customer_is_guest' => 1); } $data = $customer->getData(); if (isset($data['dob'])) { $data['customer_dob'] = $this->getFormatedDate($data['dob']); } if (isset($data['gender'])) { $data['gender'] = $this->getOptionById($data['gender'])->getValue(); } $data = new Varien_Object($data); Mage::dispatchEvent('ves_pdfpro_data_prepare_after', array('source' => $data, 'model' => $customer, 'type' => 'customer')); return $data->getData(); }
protected function _isCustomerJustConfirmed(Mage_Customer_Model_Customer $customer) { return is_null($customer->getData('confirmation')) && !is_null($customer->getOrigData('confirmation')); }
/** * 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; }
protected function getCustomerIsConfirmedStatus(Mage_Customer_Model_Customer $customer) { // TODO: Verify this if (!$customer->getData('confirmation')) { return true; } if ($customer->isConfirmationRequired()) { return false; } return null; }
/** * 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); }
/** * 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; }
public function getDefaultPickupAddress(Mage_Customer_Model_Customer $customer) { return $customer->getPrimaryAddress($customer->getData('default_pickup')); }
/** * Check customer's group * * @param Mage_Customer_Model_Customer $customer * * @return bool */ public function validateCustomerGroup($customer) { if (!$this->getId() || !$customer->getId()) { return FALSE; } $customerGroupId = $customer->getData('group_id'); $couponGroupIds = $this->getData('customer_group_ids'); $result = in_array($customerGroupId, $couponGroupIds); return $result; }
public function getLoginUrl(Mage_Customer_Model_Customer $customer) { return $this->getUrl('awdev/customer/login', array('customer_email' => $customer->getData('email'))); }