00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 class Mage_Adminhtml_Block_Sales_Order_Create_Form_Account extends Mage_Adminhtml_Block_Sales_Order_Create_Abstract
00033 {
00034 protected $_form;
00035
00036 protected function _prepareLayout()
00037 {
00038 Varien_Data_Form::setElementRenderer(
00039 $this->getLayout()->createBlock('adminhtml/widget_form_renderer_element')
00040 );
00041 Varien_Data_Form::setFieldsetRenderer(
00042 $this->getLayout()->createBlock('adminhtml/widget_form_renderer_fieldset')
00043 );
00044 Varien_Data_Form::setFieldsetElementRenderer(
00045 $this->getLayout()->createBlock('adminhtml/widget_form_renderer_fieldset_element')
00046 );
00047 }
00048
00049 public function getHeaderCssClass()
00050 {
00051 return 'head-account';
00052 }
00053
00054 public function getHeaderText()
00055 {
00056 return Mage::helper('sales')->__('Account Information');
00057 }
00058
00059 public function getForm()
00060 {
00061 $this->_prepareForm();
00062 return $this->_form;
00063 }
00064
00065 protected function _prepareForm()
00066 {
00067 if (!$this->_form) {
00068
00069 $display = $this->getDisplayFields();
00070
00071 $this->_form = new Varien_Data_Form();
00072 $fieldset = $this->_form->addFieldset('main', array());
00073 $customerModel = Mage::getModel('customer/customer');
00074
00075 foreach ($customerModel->getAttributes() as $attribute) {
00076 if (!array_key_exists($attribute->getAttributeCode(), $display)) {
00077 continue;
00078 }
00079
00080 if ($inputType = $attribute->getFrontend()->getInputType()) {
00081 $field = $display[$attribute->getAttributeCode()];
00082 $element = $fieldset->addField($attribute->getAttributeCode(), $inputType,
00083 array(
00084 'name' => $attribute->getAttributeCode(),
00085 'label' => $attribute->getFrontend()->getLabel(),
00086 'class' => isset($field['class']) ? $field['class'] : $attribute->getFrontend()->getClass(),
00087 'required' => isset($field['required']) ? $field['required'] : $attribute->getIsRequired(),
00088 )
00089 )
00090 ->setEntityAttribute($attribute)
00091 ;
00092
00093 if ($inputType == 'select' || $inputType == 'multiselect') {
00094 $element->setValues($attribute->getFrontend()->getSelectOptions());
00095 }
00096 $element->setSortOrder($display[$attribute->getAttributeCode()]);
00097 }
00098 }
00099
00100
00101
00102
00103 if ($fieldset->getElements()->count()>1) {
00104 $fieldset->getElements()->usort(array($this, '_sortMethods'));
00105 }
00106
00107 $this->_form->addFieldNameSuffix('order[account]');
00108 $this->_form->setValues($this->getCustomerData());
00109 }
00110 return $this;
00111 }
00112
00113 public function _sortMethods($a, $b)
00114 {
00115 if (is_object($a)) {
00116 return (int)$a->sort_order < (int)$b->sort_order ? -1 : ((int)$a->sort_order > (int)$b->sort_order ? 1 : 0);
00117 }
00118 return 0;
00119 }
00120
00121
00122
00123
00124
00125
00126 public function getDisplayFields()
00127 {
00128 $fields = array(
00129 'group_id' => array(
00130 'order' => 1
00131 ),
00132 'email' => array(
00133 'order' => 2,
00134 'class' => 'validate-email',
00135 'required' => false
00136 ),
00137 );
00138
00139 if ($this->getQuote()->getCustomerIsGuest()) {
00140 unset($fields['group_id']);
00141 }
00142
00143 return $fields;
00144 }
00145
00146
00147 public function getCustomerData()
00148 {
00149 $data = $this->getCustomer()->getData();
00150 foreach ($this->getQuote()->getData() as $key=>$value) {
00151 if (strstr($key, 'customer_')) {
00152 $data[str_replace('customer_', '', $key)] = $value;
00153 }
00154 }
00155 $data['group_id'] = $this->getCreateOrderModel()->getCustomerGroupId();
00156 $data['email'] = ($this->getQuote()->getCustomerEmail() ? $this->getQuote()->getCustomerEmail() :$this->getCustomer()->getData('email'));
00157 return $data;
00158 }
00159 }