1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25:
26:
27:
28: 29: 30: 31: 32: 33: 34:
35: class Mage_Customer_Block_Address_Renderer_Default extends Mage_Core_Block_Abstract implements Mage_Customer_Block_Address_Renderer_Interface
36: {
37: 38: 39: 40: 41:
42: protected $_type;
43:
44: 45: 46: 47: 48:
49: public function getType()
50: {
51: return $this->_type;
52: }
53:
54: 55: 56: 57: 58: 59:
60: public function setType(Varien_Object $type)
61: {
62: $this->_type = $type;
63: return $this;
64: }
65:
66: public function getFormat(Mage_Customer_Model_Address_Abstract $address=null)
67: {
68: $countryFormat = is_null($address) ? false : $address->getCountryModel()->getFormat($this->getType()->getCode());
69: $format = $countryFormat ? $countryFormat->getFormat() : $this->getType()->getDefaultFormat();
70: return $format;
71: }
72:
73: 74: 75: 76: 77: 78:
79: public function render(Mage_Customer_Model_Address_Abstract $address, $format=null)
80: {
81: switch ($this->getType()->getCode()) {
82: case 'html':
83: $dataFormat = Mage_Customer_Model_Attribute_Data::OUTPUT_FORMAT_HTML;
84: break;
85: case 'pdf':
86: $dataFormat = Mage_Customer_Model_Attribute_Data::OUTPUT_FORMAT_PDF;
87: break;
88: case 'oneline':
89: $dataFormat = Mage_Customer_Model_Attribute_Data::OUTPUT_FORMAT_ONELINE;
90: break;
91: default:
92: $dataFormat = Mage_Customer_Model_Attribute_Data::OUTPUT_FORMAT_TEXT;
93: break;
94: }
95:
96: $formater = new Varien_Filter_Template();
97: $attributes = Mage::helper('customer/address')->getAttributes();
98:
99: $data = array();
100: foreach ($attributes as $attribute) {
101:
102: if (!$attribute->getIsVisible()) {
103: continue;
104: }
105: if ($attribute->getAttributeCode() == 'country_id') {
106: $data['country'] = $address->getCountryModel()->getName();
107: } else if ($attribute->getAttributeCode() == 'region') {
108: $data['region'] = $address->getRegion();
109: } else {
110: $dataModel = Mage_Customer_Model_Attribute_Data::factory($attribute, $address);
111: $value = $dataModel->outputValue($dataFormat);
112: if ($attribute->getFrontendInput() == 'multiline') {
113: $values = $dataModel->outputValue(Mage_Customer_Model_Attribute_Data::OUTPUT_FORMAT_ARRAY);
114:
115: foreach ($values as $k => $v) {
116: $key = sprintf('%s%d', $attribute->getAttributeCode(), $k + 1);
117: $data[$key] = $v;
118: }
119: }
120: $data[$attribute->getAttributeCode()] = $value;
121: }
122: }
123:
124: if ($this->getType()->getHtmlEscape()) {
125: foreach ($data as $key => $value) {
126: $data[$key] = $this->htmlEscape($value);
127: }
128: }
129:
130: $formater->setVariables($data);
131:
132: $format = !is_null($format) ? $format : $this->getFormat($address);
133:
134: return $formater->filter($format);
135: }
136: }
137: