A New registration form for wholesale customer……

It is quite easy after doing this, but before doing, it looks very ugly
my motto is to create a new form for registration of a specific customer group. Here I will take “Wholesale” customer group for this example
So It need some basic step as we here can also see the override in magento which will also apply in it.
So first describe the way of it.
1. First we have to create the controller action for this method
2. the we have to override Helper for get the controller method
3. Now we have to override the Block for create the function to generate the wholesale register form url
4. Now we have to create the wholesale register form in template
5. Then we have to edit login.phtml to give the link for the customer to select the wholesale/general customer form
6. Finally we have to edit the customer layout for the page

Now here I give the code one by one
1. A xml file for the module
location:: app/etc/modules/Li_Customer.xml

<?xml version="1.0" encoding="UTF-8"?>
<config>
	<modules>
		<Li_Customer>
			<active>true</active>
			<codePool>local</codePool>
		</Li_Customer>
	</modules>
</config>

2. New new override module in local folder
Location:: local/Li/Customer/etc/confog.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Li_Customer>
            <version>0.1.0</version>
        </Li_Customer>
    </modules>
    <frontend>
        <routers>
            <customer>
                <use>standard</use>
                <args>
                    <module>Li_Customer</module>
                    <frontName>customer</frontName>
                </args>
            </customer>
        </routers>
</frontend>	
<global>
	<blocks>
	  <customer>
		  <rewrite>
			  <form_login>Li_Customer_Block_Form_Login</form_login>
		 </rewrite>
	  </customer>
   </blocks>

 	<routers>
		<customer>
			<rewrite>
				<li_customer_account>
				  <from><![CDATA[#^/account/#]]></from>
				  <to>/customer/account/</to>
				</li_customer_account>
			</rewrite>
		</customer>
	</routers>
	<helpers>
		  <customer>
			  <rewrite>
				  <data>Li_Customer_Helper_Data</data>
			 </rewrite>
		  </customer>
	 </helpers>
</global>
</config>

3. Now we can begin our work
Override controller
Localtion: Li/Customer/controllers/AccountController.php

<?php 
/**
******
**# Controllers are not autoloaded so you will have to do it manually:
**/
?>
<?php
require_once 'Mage/Customer/controllers/AccountController.php';
class Li_Customer_AccountController extends Mage_Customer_AccountController
{
	
   public function createwholesaleAction()
    {
        if ($this->_getSession()->isLoggedIn()) {
            $this->_redirect('*/*');
            return;
        }
        $this->loadLayout();
        $this->_initLayoutMessages('customer/session');
        $this->renderLayout();
    }
}

4.Override Helper
Location:Li/Customer/Helper/Data.php

<?php

class Li_Customer_Helper_Data extends Mage_Customer_Helper_Data
{
   /**
     * Retrieve Wholesale customer register form url
     *
     * @return string
     */
    public function getWholesaleRegisterUrl()
    {
        return $this->_getUrl('customer/account/createwholesale');
    }
}

5. Override Block
Location: Li/Customer/Block/Form/Login.php

<?php

class Li_Customer_Block_Form_Login extends Mage_Customer_Block_Form_Login
{
   // override existing method
  //write new function
   /**
     * Retrieve create new Whole sale account url
     *
     * @return string
     */
    public function getCreateWholesaleAccountUrl()
    {
        $url = $this->getData('create_account_url');
        if (is_null($url)) {
            $url = $this->helper('customer')->getWholesaleRegisterUrl();
        }
        return $url;
    }
}

6. customer layout for the new url
Location: yourtheme/layout/customer.xml

<!--after <customer_account_create translate="label">-->

<!-- new wholesale account
	-->
	<customer_account_createwholesale translate="label">
        <label>WholeSale Customer Account Registration Form</label>
        <!-- Mage_Customer -->
        <remove name="right"/>
        <remove name="left"/>

        <reference name="root">
            <action method="setTemplate"><template>page/1column.phtml</template></action>
        </reference>
        <reference name="content">
            <block type="customer/form_register" name="customer_form_wholesaleregister" template="customer/form/wholesaleregister.phtml">
                <block type="page/html_wrapper" name="customer.form.register.fields.before" as="form_fields_before" translate="label">
                    <label>Form Fields Before</label>
                </block>
            </block>
        </reference>
    </customer_account_createwholesale>

7.Link for the user 
Location: yourtheme/template/customer/form/login.phtml

<div class="buttons-set">
                    <button type="button" title="<?php echo $this->__('Create a Wholesale Customer Account') ?>" class="button" onclick="window.location='<?php echo $this->getCreateWholesaleAccountUrl() ?>';"><span><span><?php echo $this->__('Create a Wholesale Customer Account') ?></span></span></button>
                </div>

Add this where you want to see…

8. Now the register form
Location: yourtheme/template/customer/form/wholesaleregister.phtml

<?php
/**
 * Magento
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Academic Free License (AFL 3.0)
 * that is bundled with this package in the file LICENSE_AFL.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/afl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@magentocommerce.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Magento to newer
 * versions in the future. If you wish to customize Magento for your
 * needs please refer to http://www.magentocommerce.com for more information.
 *
 * @category    design
 * @package     base_default
 * @copyright   Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
 * @license     http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
 */
?>
<?php
/**
 * Create account form template
 *
 * @see Mage_Customer_Block_Form_Register
 */
?>
<?php $this->setShowAddressFields(true); ?>
<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->getPostActionUrl() ?>" 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 %s', $_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->escapeUrl($this->getBackUrl()) ?>" class="back-link"><small>&laquo; </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>

Advertisements

Tagged: , , , ,

21 thoughts on “A New registration form for wholesale customer……

  1. jaydee March 7, 2011 at 10:33 am

    can you please tell me if this work on 1.5.0.1 version? is this “Li” new root i must create? because i don’t see that folder anywhere. please advice

    Thanks

    • sushan senanayake March 7, 2011 at 10:43 am

      LI is the is his custom directory in /code/local …you must create that ..it not there by default

  2. sushan senanayake March 7, 2011 at 10:42 am

    hi…mate ,

    I have the same problem as you describing the article . I tried your code but when i go to the login page the templates does not show up.basically what I am trying to do is create customized customer register and billing pages . any help that you can give me in this regard is mostly appreciated .

    cheers ,
    sushan

  3. jaydee March 7, 2011 at 11:02 am

    sushan which version of magento did you try this on?

    • sushan senanayake March 8, 2011 at 8:18 am

      hi..mate .

      it is 1.5.0.1

  4. jaydee March 7, 2011 at 12:10 pm

    is this typo? Location:: local/Li/Customer/etc/confog.xml <—- not config.xml?

  5. jaydee March 7, 2011 at 1:03 pm

    ok after trying this… config.xml and the step 7. is in the step 6 end of code

    23 7.Link for the user
    24 Location: yourtheme/template/customer/form/login.phtml
    25

    can you please confirm if this really work? i’m using the latest version 1.5.01

    thanks

    • sushan senanayake March 8, 2011 at 8:21 am

      yes it is , but it hink few important steps are missing in here …..i currently working on this for week now , if manage to get this sorted will post the code

  6. sushan senanayake March 8, 2011 at 8:19 am

    yes it s config.xml

  7. jacksonpulickal March 9, 2011 at 8:36 pm

    @sushan senanayake please tell this code worked for you after changing the file name..
    Please its very urgent for me..i’m using 1.5.0.1

    Regards
    jaxon

  8. Frau Bürger May 3, 2011 at 3:34 am

    Ob das wirklich alles so stimmt?

  9. mrlostman May 12, 2011 at 5:08 am

    OK, you do have to add to this, as it doesn’t do very much on its own, but it’s a great initial reference, and I used this to cut a 3 hour job in half.

  10. Michael June 3, 2011 at 10:40 am

    Hi,

    Is this working, now?
    It doesnt look like…

    • Michael June 8, 2011 at 5:16 am

      ok, no its working with magento 1.4.2
      I changed the Methods Name to createWholesaleAction (CamelCase), the require_once line
      and inserted the indexAction from the parent class.
      _getSession()->isLoggedIn()) {
      $this->_redirect(‘*/*’);
      return;
      }
      $this->loadLayout();
      $this->_initLayoutMessages(‘customer/session’);
      $this->renderLayout();

      }

      }

  11. Michael June 8, 2011 at 5:18 am

    require_once Mage::getModuleDir(‘controllers’, ‘Mage_Customer’).DS.’AccountController.php’;
    //we need to add this one since Magento wont recognize it automatically

    class Li_Customer_AccountController extends Mage_Customer_AccountController {
    public function indexAction()
    {
    parent::indexAction();

    }

    public function createWholesaleAction() {
    if ($this->_getSession()->isLoggedIn()) {
    $this->_redirect(‘*/*’);
    return;
    }
    $this->loadLayout();
    $this->_initLayoutMessages(‘customer/session’);
    $this->renderLayout();

    }

    }

  12. Michael June 20, 2011 at 9:46 am

    I cahenged this block:

    standard

    Li_Customer
    customer

    to this:

    standard

    Li_Customer

    because the Address Manager(customer/address) was not working after login

    • Michael June 20, 2011 at 9:49 am

      <!–

      standard

      Li_Customer
      customer

      –>

    • pratik February 8, 2012 at 3:47 pm

      pls help address is not found….

  13. Michael June 20, 2011 at 9:50 am

    I dont know, there is a filter for pasting xml-code into…

  14. author July 5, 2011 at 12:26 pm

    can i have the URl for the above form.

  15. Pratik February 8, 2012 at 2:05 pm

    (customer/address) was not working after login
    pls help…….

Comments are closed.

%d bloggers like this: