/** * Return array of additional account data * Value is option style array * * @return array */ public function getCustomerAccountData() { $accountData = array(); /* @var $config Mage_Eav_Model_Config */ $config = Mage::getSingleton('eav/config'); $entityType = 'customer'; $customer = Mage::getModel('customer/customer'); foreach ($config->getEntityAttributeCodes($entityType) as $attributeCode) { /* @var $attribute Mage_Customer_Model_Attribute */ $attribute = $config->getAttribute($entityType, $attributeCode); if (!$attribute->getIsVisible() || $attribute->getIsSystem()) { continue; } $orderKey = sprintf('customer_%s', $attribute->getAttributeCode()); $orderValue = $this->getOrder()->getData($orderKey); if ($orderValue != '') { $customer->setData($attribute->getAttributeCode(), $orderValue); $dataModel = Mage_Customer_Model_Attribute_Data::factory($attribute, $customer); $value = $dataModel->outputValue(Mage_Customer_Model_Attribute_Data::OUTPUT_FORMAT_HTML); $sortOrder = $attribute->getSortOrder() + $attribute->getIsUserDefined() ? 200 : 0; $sortOrder = $this->_prepareAccountDataSortOrder($accountData, $sortOrder); $accountData[$sortOrder] = array('label' => $attribute->getFrontendLabel(), 'value' => $value); } } ksort($accountData, SORT_NUMERIC); return $accountData; }
/** * 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 Mage_XmlConnect_Block_Checkout_Onepage_Address_List */ protected function _prepareAddressData(Mage_Customer_Model_Address $address, Mage_XmlConnect_Model_Simplexml_Element $item) { $attributes = Mage::helper('customer/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); $attributeValue = $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 $attributeIndex => $attributeVal) { $key = sprintf('%s%d', $attribute->getAttributeCode(), $attributeIndex + 1); $data[$key] = $attributeVal; } } $data[$attribute->getAttributeCode()] = $attributeValue; } } } foreach ($data as $key => $value) { if (empty($value)) { continue; } $item->addCustomChild($key, $value); } return $this; }
/** * Render address * * @param Mage_Customer_Model_Address_Abstract $address * @return string */ public function render(Mage_Customer_Model_Address_Abstract $address, $format = null) { switch ($this->getType()->getCode()) { case 'html': $dataFormat = Mage_Customer_Model_Attribute_Data::OUTPUT_FORMAT_HTML; break; case 'pdf': $dataFormat = Mage_Customer_Model_Attribute_Data::OUTPUT_FORMAT_PDF; break; case 'oneline': $dataFormat = Mage_Customer_Model_Attribute_Data::OUTPUT_FORMAT_ONELINE; break; default: $dataFormat = Mage_Customer_Model_Attribute_Data::OUTPUT_FORMAT_TEXT; break; } $formater = new Varien_Filter_Template(); $attributes = Mage::helper('customer/address')->getAttributes(); $data = array(); foreach ($attributes as $attribute) { /* @var $attribute Mage_Customer_Model_Attribute */ if (!$attribute->getIsVisible()) { continue; } if ($attribute->getAttributeCode() == 'country_id') { $data['country'] = $address->getCountryModel()->getName(); } else { if ($attribute->getAttributeCode() == 'region') { $data['region'] = Mage::helper('directory')->__($address->getRegion()); } else { $dataModel = Mage_Customer_Model_Attribute_Data::factory($attribute, $address); $value = $dataModel->outputValue($dataFormat); 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; } } } if ($this->getType()->getHtmlEscape()) { foreach ($data as $key => $value) { $data[$key] = $this->escapeHtml($value); } } $formater->setVariables($data); $format = !is_null($format) ? $format : $this->getFormat($address); return $formater->filter($format); }
/** * Validate attribute value * * @param array|string $value * @throws Mage_Core_Exception * @return boolean */ public function validateValue($value) { $dataModel = Mage_Customer_Model_Attribute_Data::factory($this->getAttributeObject(), $this->getEntity()); $result = $dataModel->validateValue($this->getValue()); return $result; }
/** * Return attribute data model by attribute * * @param Mage_Eav_Model_Entity_Attribute $attribute * @return Mage_Customer_Model_Attribute_Data_Abstract */ protected function _getAttributeDataModel(Mage_Eav_Model_Entity_Attribute $attribute) { $dataModel = Mage_Customer_Model_Attribute_Data::factory($attribute, $this->getEntity()); $dataModel->setIsAjaxRequest($this->getIsAjaxRequest()); return $dataModel; }