为了简单的讲解步骤,本文修改了magento的核心代码,这当然是不好的,但是今天的重点是将如何实现的。大家有空了,可以自己使用模块重写自己再去重写下这几个文件就行了。关于模板的美观修饰,大家自己弄吧,毕竟每个模板都不一样,还是有大量的css工作需要你们自己完成的。
进入正题,本文使用magento1.4版本,使用default模板,大家使用其它的版本注意文件路径的细微变化。
magento的登陆页面的模板文件路径是:app\design\frontend\base\default\template\customer\form\login.phtml
magento注册页面的模板文件路径是:app\design\frontend\base\default\template\customer\form\register.phtml
magento登陆页的block文件路径是:app\code\core\Mage\Customer\Block\Form\Login.php
magento注册页的block文件路径是:app\code\core\Mage\Customer\Block\Form\Register.php
这些文件是要涉及到的,步骤如下
1.我们直接将 register.phtml 文件中的代码贴到 login.phtml 中(先都贴到login.phtml文件的最后吧,布局以后再弄),这样在内容上他们就是在一个页面了。这个时候login.phtml文件的代码就如下了
1
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
|
<div
class
=
"account-login"
>
<div
class
=
"page-title"
>
<h1><?php
echo
$this
->__(
'Login or Create an Account'
) ?></h1>
</div>
<?php
echo
$this
->getMessagesBlock()->getGroupedHtml() ?>
<form action=
"<?php echo $this->getPostActionUrl() ?>"
method=
"post"
id=
"login-form"
>
<div
class
=
"col2-set"
>
<div
class
=
"col-1 new-users"
>
<div
class
=
"content"
>
<h2><?php
echo
$this
->__(
'New Customers'
) ?></h2>
<p><?php
echo
$this
->__(
'By creating an account with our store, you will be able to move through the checkout process faster, store multiple shipping addresses, view and track your orders in your account and more.'
) ?></p>
</div>
</div>
<div
class
=
"col-2 registered-users"
>
<div
class
=
"content"
>
<h2><?php
echo
$this
->__(
'Registered Customers'
) ?></h2>
<p><?php
echo
$this
->__(
'If you have an account with us, please log in.'
) ?></p>
<ul
class
=
"form-list"
>
<li>
<label
for
=
"email"
class
=
"required"
><em>*</em><?php
echo
$this
->__(
'Email Address'
) ?></label>
<div
class
=
"input-box"
>
<input type=
"text"
name=
"login[username]"
value=
"<?php echo $this->htmlEscape($this->getUsername()) ?>"
id=
"email"
class
=
"input-text required-entry"
title=
"<?php echo $this->__('Email Address') ?>"
/>
</div>
</li>
<li>
<label
for
=
"pass"
class
=
"required"
><em>*</em><?php
echo
$this
->__(
'Password'
) ?></label>
<div
class
=
"input-box"
>
<input type=
"password"
name=
"login[password]"
class
=
"input-text required-entry validate-password"
id=
"pass"
title=
"<?php echo $this->__('Password') ?>"
/>
</div>
</li>
</ul>
<p
class
=
"required"
><?php
echo
$this
->__(
'* Required Fields'
) ?></p>
</div>
</div>
</div>
<div
class
=
"col2-set"
>
<div
class
=
"col-1 new-users"
>
<div
class
=
"buttons-set"
>
<button type=
"button"
title=
"<?php echo $this->__('Create an Account') ?>"
class
=
"button"
onclick=
"window.location='<?php echo $this->getCreateAccountUrl() ?>';"
><span><span><?php
echo
$this
->__(
'Create an Account'
) ?></span></span></button>
</div>
</div>
<div
class
=
"col-2 registered-users"
>
<div
class
=
"buttons-set"
>
<a href=
"<?php echo $this->getForgotPasswordUrl() ?>"
class
=
"f-left"
><?php
echo
$this
->__(
'Forgot Your Password?'
) ?></a>
<button type=
"submit"
class
=
"button"
title=
"<?php echo $this->__('Login') ?>"
name=
"send"
id=
"send2"
><span><span><?php
echo
$this
->__(
'Login'
) ?></span></span></button>
</div>
</div>
</div>
</form>
<script type=
"text/javascript"
>
//<![CDATA[
var
dataForm =
new
VarienForm(
'login-form'
, true);
//]]>
</script>
</div>
<!-- from register.phtml-->
<div
class
=
"account-create"
>
<div
class
=
"page-title"
>
<h1><?php
echo
$this
->__(
'Create an Account'
) ?></h1>
</div>
<?php
echo
$this
->getChildHtml(
'form_fields_before'
)?>
<?php
echo
$this
->getMessagesBlock()->getGroupedHtml() ?>
<form action=
"<?php echo $this->getregisterPostActionUrl() ?>"
method=
"post"
id=
"form-validate"
>
<div
class
=
"fieldset"
>
<input type=
"hidden"
name=
"success_url"
value=
"<?php echo $this->getSuccessUrl() ?>"
/>
<input type=
"hidden"
name=
"error_url"
value=
"<?php echo $this->getErrorUrl() ?>"
/>
<h2
class
=
"legend"
><?php
echo
$this
->__(
'Personal Information'
) ?></h2>
<ul
class
=
"form-list"
>
<li
class
=
"fields"
>
<?php
echo
$this
->getLayout()->createBlock(
'customer/widget_name'
)->setObject(
$this
->getFormData())->toHtml() ?>
</li>
<li>
<label
for
=
"email_address"
class
=
"required"
><em>*</em><?php
echo
$this
->__(
'Email Address'
) ?></label>
<div
class
=
"input-box"
>
<input type=
"text"
name=
"email"
id=
"email_address"
value=
"<?php echo $this->htmlEscape($this->getFormData()->getEmail()) ?>"
title=
"<?php echo $this->__('Email Address') ?>"
class
=
"input-text validate-email required-entry"
/>
</div>
</li>
<?php
if
(
$this
->isNewsletterEnabled()): ?>
<li
class
=
"control"
>
<div
class
=
"input-box"
>
<input type=
"checkbox"
name=
"is_subscribed"
title=
"<?php echo $this->__('Sign Up for Newsletter') ?>"
value=
"1"
id=
"is_subscribed"
<?php
if
(
$this
->getFormData()->getIsSubscribed()): ?> checked=
"checked"
<?php
endif
; ?>
class
=
"checkbox"
/>
</div>
<label
for
=
"is_subscribed"
><?php
echo
$this
->__(
'Sign Up for Newsletter'
) ?></label>
</li>
<?php
endif
?>
<?php
$_dob
=
$this
->getLayout()->createBlock(
'customer/widget_dob'
) ?>
<?php
if
(
$_dob
->isEnabled()): ?>
<li><?php
echo
$_dob
->setDate(
$this
->getFormData()->getDob())->toHtml() ?></li>
<?php
endif
?>
<?php
$_taxvat
=
$this
->getLayout()->createBlock(
'customer/widget_taxvat'
) ?>
<?php
if
(
$_taxvat
->isEnabled()): ?>
<li><?php
echo
$_taxvat
->setTaxvat(
$this
->getFormData()->getTaxvat())->toHtml() ?></li>
<?php
endif
?>
<?php
$_gender
=
$this
->getLayout()->createBlock(
'customer/widget_gender'
) ?>
<?php
if
(
$_gender
->isEnabled()): ?>
<li><?php
echo
$_gender
->setGender(
$this
->getFormData()->getGender())->toHtml() ?></li>
<?php
endif
?>
</ul>
</div>
<?php
if
(
$this
->getShowAddressFields()): ?>
<div
class
=
"fieldset"
>
<input type=
"hidden"
name=
"create_address"
value=
"1"
/>
<h2
class
=
"legend"
><?php
echo
$this
->__(
'Address Information'
) ?></h2>
<ul
class
=
"form-list"
>
<li
class
=
"fields"
>
<div
class
=
"field"
>
<label
for
=
"company"
><?php
echo
$this
->__(
'Company'
) ?></label>
<div
class
=
"input-box"
>
<input type=
"text"
name=
"company"
id=
"company"
value=
"<?php echo $this->htmlEscape($this->getFormData()->getCompany()) ?>"
title=
"<?php echo $this->__('Company') ?>"
class
=
"input-text"
/>
</div>
</div>
<div
class
=
"field"
>
<label
for
=
"telephone"
class
=
"required"
><em>*</em><?php
echo
$this
->__(
'Telephone'
) ?></label>
<div
class
=
"input-box"
>
<input type=
"text"
name=
"telephone"
id=
"telephone"
value=
"<?php echo $this->htmlEscape($this->getFormData()->getTelephone()) ?>"
title=
"<?php echo $this->__('Telephone') ?>"
class
=
"input-text required-entry"
/>
</div>
</div>
</li>
<li
class
=
"wide"
>
<label
for
=
"street_1"
class
=
"required"
><em>*</em><?php
echo
$this
->__(
'Street Address'
) ?></label>
<div
class
=
"input-box"
>
<input type=
"text"
name=
"street[]"
value=
"<?php echo $this->htmlEscape($this->getFormData()->getStreet(1)) ?>"
title=
"<?php echo $this->__('Street Address') ?>"
id=
"street_1"
class
=
"input-text required-entry"
/>
</div>
</li>
<?php
for
(
$_i
=2,
$_n
=
$this
->helper(
'customer/address'
)->getStreetLines();
$_i
<=
$_n
;
$_i
++): ?>
<li
class
=
"wide"
>
<div
class
=
"input-box"
>
<input type=
"text"
name=
"street[]"
value=
"<?php echo $this->htmlEscape($this->getFormData()->getStreet($_i)) ?>"
title=
"<?php echo $this->__('Street Address '.$_i) ?>"
id=
"street_<?php echo $_i?>"
class
=
"input-text"
/>
</div>
</li>
<?php
endfor
?>
<li
class
=
"fields"
>
<div
class
=
"field"
>
<label
for
=
"city"
class
=
"required"
><em>*</em><?php
echo
$this
->__(
'City'
) ?></label>
<div
class
=
"input-box"
>
<input type=
"text"
name=
"city"
value=
"<?php echo $this->htmlEscape($this->getFormData()->getCity()) ?>"
title=
"<?php echo $this->__('City') ?>"
class
=
"input-text required-entry"
id=
"city"
/>
</div>
</div>
<div
class
=
"field"
>
<label
for
=
"region_id"
class
=
"required"
><em>*</em><?php
echo
$this
->__(
'State/Province'
) ?></label>
<div
class
=
"input-box"
>
<select id=
"region_id"
name=
"region_id"
title=
"<?php echo $this->__('State/Province') ?>"
class
=
"validate-select"
style=
"display:none;"
>
<option value=
""
><?php
echo
$this
->__(
'Please select region, state or province'
) ?></option>
</select>
<script type=
"text/javascript"
>
//<![CDATA[
$(
'region_id'
).setAttribute(
'defaultValue'
,
"<?php echo $this->getFormData()->getRegionId() ?>"
);
//]]>
</script>
<input type=
"text"
id=
"region"
name=
"region"
value=
"<?php echo $this->htmlEscape($this->getRegion()) ?>"
title=
"<?php echo $this->__('State/Province') ?>"
class
=
"input-text"
style=
"display:none;"
/>
</div>
</div>
</li>
<li
class
=
"fields"
>
<div
class
=
"field"
>
<label
for
=
"zip"
class
=
"required"
><em>*</em><?php
echo
$this
->__(
'Zip/Postal Code'
) ?></label>
<div
class
=
"input-box"
>
<input type=
"text"
name=
"postcode"
value=
"<?php echo $this->htmlEscape($this->getFormData()->getPostcode()) ?>"
title=
"<?php echo $this->__('Zip/Postal Code') ?>"
id=
"zip"
class
=
"input-text validate-zip-international required-entry"
/>
</div>
</div>
<div
class
=
"field"
>
<label
for
=
"country"
class
=
"required"
><em>*</em><?php
echo
$this
->__(
'Country'
) ?></label>
<div
class
=
"input-box"
>
<?php
echo
$this
->getCountryHtmlSelect() ?>
</div>
</div>
</li>
</ul>
<input type=
"hidden"
name=
"default_billing"
value=
"1"
/>
<input type=
"hidden"
name=
"default_shipping"
value=
"1"
/>
</div>
<?php
endif
; ?>
<div
class
=
"fieldset"
>
<h2
class
=
"legend"
><?php
echo
$this
->__(
'Login Information'
) ?></h2>
<ul
class
=
"form-list"
>
<li
class
=
"fields"
>
<div
class
=
"field"
>
<label
for
=
"password"
class
=
"required"
><em>*</em><?php
echo
$this
->__(
'Password'
) ?></label>
<div
class
=
"input-box"
>
<input type=
"password"
name=
"password"
id=
"password"
title=
"<?php echo $this->__('Password') ?>"
class
=
"input-text required-entry validate-password"
/>
</div>
</div>
<div
class
=
"field"
>
<label
for
=
"confirmation"
class
=
"required"
><em>*</em><?php
echo
$this
->__(
'Confirm Password'
) ?></label>
<div
class
=
"input-box"
>
<input type=
"password"
name=
"confirmation"
title=
"<?php echo $this->__('Confirm Password') ?>"
id=
"confirmation"
class
=
"input-text required-entry validate-cpassword"
/>
</div>
</div>
</li>
</ul>
</div>
<div
class
=
"buttons-set"
>
<p
class
=
"required"
><?php
echo
$this
->__(
'* Required Fields'
) ?></p>
<p
class
=
"back-link"
><a href=
"<?php echo $this->getBackUrl() ?>"
class
=
"back-link"
><small>« </small><?php
echo
$this
->__(
'Back'
) ?></a></p>
<button type=
"submit"
title=
"<?php echo $this->__('Submit') ?>"
class
=
"button"
><span><span><?php
echo
$this
->__(
'Submit'
) ?></span></span></button>
</div>
</form>
<script type=
"text/javascript"
>
//<![CDATA[
var
dataForm =
new
VarienForm(
'form-validate'
, true);
<?php
if
(
$this
->getShowAddressFields()): ?>
new
RegionUpdater(
'country'
,
'region'
,
'region_id'
, <?php
echo
$this
->helper(
'directory'
)->getRegionJson() ?>, undefined,
'zip'
);
<?php
endif
; ?>
//]]>
</script>
</div>
|
2.我们有选择的将Register.php中的函数贴到Login.php中,Login.php的内容就如下了。
1
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
|
class
Mage_Customer_Block_Form_Login
extends
Mage_Core_Block_Template
{
private
$_username
= -1;
protected
function
_prepareLayout()
{
$this
->getLayout()->getBlock(
'head'
)->setTitle(Mage::helper(
'customer'
)->__(
'Customer Login'
));
return
parent::_prepareLayout();
}
/**
* Retrieve form posting url
*
* @return string
*/
public
function
getPostActionUrl()
{
return
$this
->helper(
'customer'
)->getLoginPostUrl();
}
/**
* Retrieve create new account url
*
* @return string
*/
public
function
getCreateAccountUrl()
{
$url
=
$this
->getData(
'create_account_url'
);
if
(
is_null
(
$url
)) {
$url
=
$this
->helper(
'customer'
)->getRegisterUrl();
}
return
$url
;
}
/**
* Retrieve password forgotten url
*
* @return string
*/
public
function
getForgotPasswordUrl()
{
return
$this
->helper(
'customer'
)->getForgotPasswordUrl();
}
/**
* Retrieve username for form field
*
* @return string
*/
public
function
getUsername()
{
if
(-1 ===
$this
->_username) {
$this
->_username = Mage::getSingleton(
'customer/session'
)->getUsername(true);
}
return
$this
->_username;
}
/*test*/
public
function
getregisterPostActionUrl()
{
return
$this
->helper(
'customer'
)->getRegisterPostUrl();
}
public
function
getFormData()
{
$data
=
$this
->getData(
'form_data'
);
if
(
is_null
(
$data
)) {
$data
=
new
Varien_Object(Mage::getSingleton(
'customer/session'
)->getCustomerFormData(true));
$this
->setData(
'form_data'
,
$data
);
}
return
$data
;
}
/**
* Retrieve customer country identifier
*
* @return int
*/
public
function
getCountryId()
{
if
(
$countryId
=
$this
->getFormData()->getCountryId()) {
return
$countryId
;
}
return
parent::getCountryId();
}
/**
* Retrieve customer region identifier
*
* @return int
*/
public
function
getRegion()
{
if
(
$region
=
$this
->getFormData()->getRegion()) {
return
$region
;
}
elseif
(
$region
=
$this
->getFormData()->getRegionId()) {
return
$region
;
}
return
null;
}
/**
* Newsletter module availability
*
* @return boolean
*/
public
function
isNewsletterEnabled()
{
return
!Mage::getStoreConfigFlag(
'advanced/modules_disable_output/Mage_Newsletter'
);
}
}
|
3.我们可以注意到,我将register.phtml与register.php中的getPostActionUrl()函数的名字改成了getregisterPostActionUrl(),这个就是重点。
4.然后大家改改login.phtml,该删的删,该修改css的修改css,最后弄的美观些,就大功告成了。
ref:http://www.hellokeykey.com/magento-login-register-in-one-page/