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: class Mage_Adminhtml_Block_Sales_Order_Create_Form_Address
35: extends Mage_Adminhtml_Block_Sales_Order_Create_Form_Abstract
36: {
37: 38: 39: 40: 41:
42: protected $_addressForm;
43:
44: 45: 46: 47: 48:
49: public function getAddressCollection()
50: {
51: return $this->getCustomer()->getAddresses();
52: }
53:
54: 55: 56: 57: 58:
59: protected function _getAddressForm()
60: {
61: if (is_null($this->_addressForm)) {
62: $this->_addressForm = Mage::getModel('customer/form')
63: ->setFormCode('adminhtml_customer_address')
64: ->setStore($this->getStore());
65: }
66: return $this->_addressForm;
67: }
68:
69: 70: 71: 72: 73:
74: public function getAddressCollectionJson()
75: {
76: $addressForm = $this->_getAddressForm();
77: $data = array();
78:
79: $emptyAddress = $this->getCustomer()
80: ->getAddressById(null)
81: ->setCountryId(Mage::helper('core')->getDefaultCountry($this->getStore()));
82: $data[0] = $addressForm->setEntity($emptyAddress)
83: ->outputData(Mage_Customer_Model_Attribute_Data::OUTPUT_FORMAT_JSON);
84:
85: foreach ($this->getAddressCollection() as $address) {
86: $addressForm->setEntity($address);
87: $data[$address->getId()] = $addressForm->outputData(
88: Mage_Customer_Model_Attribute_Data::OUTPUT_FORMAT_JSON
89: );
90: }
91: return Mage::helper('core')->jsonEncode($data);
92: }
93:
94: 95: 96: 97: 98:
99: protected function _prepareForm()
100: {
101: $fieldset = $this->_form->addFieldset('main', array(
102: 'no_container' => true
103: ));
104:
105:
106: $addressModel = Mage::getModel('customer/address');
107:
108: $addressForm = $this->_getAddressForm()
109: ->setEntity($addressModel);
110:
111: $attributes = $addressForm->getAttributes();
112: if(isset($attributes['street'])) {
113: Mage::helper('adminhtml/addresses')
114: ->processStreetAttribute($attributes['street']);
115: }
116: $this->_addAttributesToForm($attributes, $fieldset);
117:
118: $prefixElement = $this->_form->getElement('prefix');
119: if ($prefixElement) {
120: $prefixOptions = $this->helper('customer')->getNamePrefixOptions($this->getStore());
121: if (!empty($prefixOptions)) {
122: $fieldset->removeField($prefixElement->getId());
123: $prefixField = $fieldset->addField($prefixElement->getId(),
124: 'select',
125: $prefixElement->getData(),
126: '^'
127: );
128: $prefixField->setValues($prefixOptions);
129: if ($this->getAddressId()) {
130: $prefixField->addElementValues($this->getAddress()->getPrefix());
131: }
132: }
133: }
134:
135: $suffixElement = $this->_form->getElement('suffix');
136: if ($suffixElement) {
137: $suffixOptions = $this->helper('customer')->getNameSuffixOptions($this->getStore());
138: if (!empty($suffixOptions)) {
139: $fieldset->removeField($suffixElement->getId());
140: $suffixField = $fieldset->addField($suffixElement->getId(),
141: 'select',
142: $suffixElement->getData(),
143: $this->_form->getElement('lastname')->getId()
144: );
145: $suffixField->setValues($suffixOptions);
146: if ($this->getAddressId()) {
147: $suffixField->addElementValues($this->getAddress()->getSuffix());
148: }
149: }
150: }
151:
152:
153: $regionElement = $this->_form->getElement('region_id');
154: if ($regionElement) {
155: $regionElement->setNoDisplay(true);
156: }
157:
158: $this->_form->setValues($this->getFormValues());
159:
160: if ($this->_form->getElement('country_id')->getValue()) {
161: $countryId = $this->_form->getElement('country_id')->getValue();
162: $this->_form->getElement('country_id')->setValue(null);
163: foreach ($this->_form->getElement('country_id')->getValues() as $country) {
164: if ($country['value'] == $countryId) {
165: $this->_form->getElement('country_id')->setValue($countryId);
166: }
167: }
168: }
169: if (is_null($this->_form->getElement('country_id')->getValue())) {
170: $this->_form->getElement('country_id')->setValue(
171: Mage::helper('core')->getDefaultCountry($this->getStore())
172: );
173: }
174:
175:
176: $vatIdElement = $this->_form->getElement('vat_id');
177: if ($vatIdElement && $this->getDisplayVatValidationButton() !== false) {
178: $vatIdElement->setRenderer(
179: $this->getLayout()->createBlock('adminhtml/customer_sales_order_address_form_renderer_vat')
180: ->setJsVariablePrefix($this->getJsVariablePrefix())
181: );
182: }
183:
184: return $this;
185: }
186:
187: 188: 189: 190: 191: 192:
193: protected function _addAdditionalFormElementData(Varien_Data_Form_Element_Abstract $element)
194: {
195: if ($element->getId() == 'region_id') {
196: $element->setNoDisplay(true);
197: }
198: return $this;
199: }
200:
201: 202: 203: 204: 205:
206: public function getAddressId()
207: {
208: return false;
209: }
210:
211: 212: 213: 214: 215: 216:
217: public function getAddressAsString($address)
218: {
219: return $this->htmlEscape($address->format('oneline'));
220: }
221: }
222: