为了简单的讲解步骤,本文修改了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文件的代码就如下了
<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的内容就如下了。
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,最后弄的美观些,就大功告成了。
我把 Billing Information 项里面的city、telephone、zip/Postal Code等由必填设为可选,然后测试的时候,选择paypal支付出现以下错误提示:
PayPal gateway has rejected request. The field Shipping Address1 is required (#10727: Shipping Address1 Empty). The field Shipping Address City is required (#10728: Shipping Address City Empty). The field Shipping Address Postal Code is required (#10730: Shipping Address Postal Code Empty).
请问:是否上述几项必须填入Paypal才能正确下单吗? 也就是说我还是不能把telephone设为可选?
有的paypal支付方式是需要city、telephone、zip/Postal Code为必填项的。你设置使用paypal网站标准支付,其余paypal支付方式禁用下,此报警就不会出现了。