1: <?php
2: /**
3: * Magento
4: *
5: * NOTICE OF LICENSE
6: *
7: * This source file is subject to the Open Software License (OSL 3.0)
8: * that is bundled with this package in the file LICENSE.txt.
9: * It is also available through the world-wide-web at this URL:
10: * http://opensource.org/licenses/osl-3.0.php
11: * If you did not receive a copy of the license and are unable to
12: * obtain it through the world-wide-web, please send an email
13: * to license@magentocommerce.com so we can send you a copy immediately.
14: *
15: * DISCLAIMER
16: *
17: * Do not edit or add to this file if you wish to upgrade Magento to newer
18: * versions in the future. If you wish to customize Magento for your
19: * needs please refer to http://www.magentocommerce.com for more information.
20: *
21: * @category Mage
22: * @package Mage_Adminhtml
23: * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24: * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25: */
26:
27: /**
28: * Create order account form
29: *
30: * @author Magento Core Team <core@magentocommerce.com>
31: */
32: class Mage_Adminhtml_Block_Sales_Order_Create_Form_Account extends Mage_Adminhtml_Block_Sales_Order_Create_Form_Abstract
33: {
34: /**
35: * Return Header CSS Class
36: *
37: * @return string
38: */
39: public function getHeaderCssClass()
40: {
41: return 'head-account';
42: }
43:
44: /**
45: * Return header text
46: *
47: * @return string
48: */
49: public function getHeaderText()
50: {
51: return Mage::helper('sales')->__('Account Information');
52: }
53:
54: /**
55: * Prepare Form and add elements to form
56: *
57: * @return Mage_Adminhtml_Block_Sales_Order_Create_Form_Account
58: */
59: protected function _prepareForm()
60: {
61: /* @var $customerModel Mage_Customer_Model_Customer */
62: $customerModel = Mage::getModel('customer/customer');
63:
64: /* @var $customerForm Mage_Customer_Model_Form */
65: $customerForm = Mage::getModel('customer/form');
66: $customerForm->setFormCode('adminhtml_checkout')
67: ->setStore($this->getStore())
68: ->setEntity($customerModel);
69:
70: // prepare customer attributes to show
71: $attributes = array();
72:
73: // add system required attributes
74: foreach ($customerForm->getSystemAttributes() as $attribute) {
75: /* @var $attribute Mage_Customer_Model_Attribute */
76: if ($attribute->getIsRequired()) {
77: $attributes[$attribute->getAttributeCode()] = $attribute;
78: }
79: }
80:
81: if ($this->getQuote()->getCustomerIsGuest()) {
82: unset($attributes['group_id']);
83: }
84:
85: // add user defined attributes
86: foreach ($customerForm->getUserAttributes() as $attribute) {
87: /* @var $attribute Mage_Customer_Model_Attribute */
88: $attributes[$attribute->getAttributeCode()] = $attribute;
89: }
90:
91: $fieldset = $this->_form->addFieldset('main', array());
92:
93: $this->_addAttributesToForm($attributes, $fieldset);
94:
95: $this->_form->addFieldNameSuffix('order[account]');
96: $this->_form->setValues($this->getFormValues());
97:
98: return $this;
99: }
100:
101: /**
102: * Add additional data to form element
103: *
104: * @param Varien_Data_Form_Element_Abstract $element
105: * @return Mage_Adminhtml_Block_Sales_Order_Create_Form_Abstract
106: */
107: protected function _addAdditionalFormElementData(Varien_Data_Form_Element_Abstract $element)
108: {
109: switch ($element->getId()) {
110: case 'email':
111: $element->setRequired(0);
112: $element->setClass('validate-email');
113: break;
114: }
115: return $this;
116: }
117:
118: /**
119: * Return customer data
120: *
121: * @deprecated since 1.4.0.1
122: * @return array
123: */
124: public function getCustomerData()
125: {
126: return $this->getFormValues();
127: }
128:
129: /**
130: * Return Form Elements values
131: *
132: * @return array
133: */
134: public function getFormValues()
135: {
136: $data = $this->getCustomer()->getData();
137: foreach ($this->getQuote()->getData() as $key => $value) {
138: if (strpos($key, 'customer_') === 0) {
139: $data[substr($key, 9)] = $value;
140: }
141: }
142:
143: if ($this->getQuote()->getCustomerEmail()) {
144: $data['email'] = $this->getQuote()->getCustomerEmail();
145: }
146:
147: return $data;
148: }
149: }
150: