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_Customer
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: * Customer register form block
29: *
30: * @author Magento Core Team <core@magentocommerce.com>
31: */
32: class Mage_Customer_Block_Form_Register extends Mage_Directory_Block_Data
33: {
34: /**
35: * Address instance with data
36: *
37: * @var Mage_Customer_Model_Address
38: */
39: protected $_address;
40:
41: protected function _prepareLayout()
42: {
43: $this->getLayout()->getBlock('head')->setTitle(Mage::helper('customer')->__('Create New Customer Account'));
44: return parent::_prepareLayout();
45: }
46:
47: /**
48: * Retrieve form posting url
49: *
50: * @return string
51: */
52: public function getPostActionUrl()
53: {
54: return $this->helper('customer')->getRegisterPostUrl();
55: }
56:
57: /**
58: * Retrieve back url
59: *
60: * @return string
61: */
62: public function getBackUrl()
63: {
64: $url = $this->getData('back_url');
65: if (is_null($url)) {
66: $url = $this->helper('customer')->getLoginUrl();
67: }
68: return $url;
69: }
70:
71: /**
72: * Retrieve form data
73: *
74: * @return Varien_Object
75: */
76: public function getFormData()
77: {
78: $data = $this->getData('form_data');
79: if (is_null($data)) {
80: $formData = Mage::getSingleton('customer/session')->getCustomerFormData(true);
81: $data = new Varien_Object();
82: if ($formData) {
83: $data->addData($formData);
84: $data->setCustomerData(1);
85: }
86: if (isset($data['region_id'])) {
87: $data['region_id'] = (int)$data['region_id'];
88: }
89: $this->setData('form_data', $data);
90: }
91: return $data;
92: }
93:
94: /**
95: * Retrieve customer country identifier
96: *
97: * @return int
98: */
99: public function getCountryId()
100: {
101: $countryId = $this->getFormData()->getCountryId();
102: if ($countryId) {
103: return $countryId;
104: }
105: return parent::getCountryId();
106: }
107:
108: /**
109: * Retrieve customer region identifier
110: *
111: * @return int
112: */
113: public function getRegion()
114: {
115: if (false !== ($region = $this->getFormData()->getRegion())) {
116: return $region;
117: } else if (false !== ($region = $this->getFormData()->getRegionId())) {
118: return $region;
119: }
120: return null;
121: }
122:
123: /**
124: * Newsletter module availability
125: *
126: * @return boolean
127: */
128: public function isNewsletterEnabled()
129: {
130: return Mage::helper('core')->isModuleOutputEnabled('Mage_Newsletter');
131: }
132:
133: /**
134: * Return customer address instance
135: *
136: * @return Mage_Customer_Model_Address
137: */
138: public function getAddress()
139: {
140: if (is_null($this->_address)) {
141: $this->_address = Mage::getModel('customer/address');
142: }
143:
144: return $this->_address;
145: }
146:
147: /**
148: * Restore entity data from session
149: * Entity and form code must be defined for the form
150: *
151: * @param Mage_Customer_Model_Form $form
152: * @return Mage_Customer_Block_Form_Register
153: */
154: public function restoreSessionData(Mage_Customer_Model_Form $form, $scope = null)
155: {
156: if ($this->getFormData()->getCustomerData()) {
157: $request = $form->prepareRequest($this->getFormData()->getData());
158: $data = $form->extractData($request, $scope, false);
159: $form->restoreData($data);
160: }
161:
162: return $this;
163: }
164: }
165: