Creating Separate Registration Pages for Retailers and Wholesalers in Magento
In Magento, creating separate registration pages for retailers and wholesalers involves customizing the customer account creation process. By default, Magento provides a single registration page located at customer/account/create/. To create two distinct pages, we’ll need to extend this functionality.
Step 1: Create New Wholesaler Form Templates
First, let’s create new templates for our wholesale registration form. Navigate to your theme directory and locate the following files:
app/design/frontend/{Your_Theme}/{Package_Name}/template/customer/form/register.phtmlapp/design/frontend/{Your_Theme}/{Package_Name}/template/customer/form/wholesale_register.phtml
The latter is where we’ll define our new wholesale registration form. You can copy the contents of register.phtml into this file and modify it to include fields relevant for wholesalers, such as wholesale price range, minimum order quantity, etc.
Step 2: Customize Customer Form Model
Next, we need to customize the customer form model to validate our new wholesale registration data. In your theme directory:
app/design/frontend/{Your_Theme}/{Package_Name}/etc/config.xml
Add a new <form> element inside the <customer_form> container:
<form id="wholesale_register">
<label for="register[wholesale_price_range]">Wholesale Price Range:</label>
<input type="text" name="wholesale_price_range" id="wholesale_price_range"/>
</form>
Step 3: Modify Customer Controller
Now, let’s modify the customer controller to handle the wholesale registration form submission. Navigate to:
app/code/core/Mage/Customer/controllers/AccountController.php
Add a new action for the wholesale registration:
public function wholesaleRegisterAction()
{
$this->loadLayout();
$this->_initLayoutMessages('customer/session');
if ($this->_getSession()->isLoggedIn()) {
$this->_redirect('*/*/');
return;
}
if ( !$this->_validateFormKey() ) {
return $this->_goBack();
}
$session = $this->_getSession();
if ($this->getRequest()->isPost()) {
$customer = Mage::registry('current_customer');
$error = false;
try {
$customer->setConfirmation($session->getCustomer confirmation());
$customer->save();
$session->unsFormData();
$session->unsCustomerConfirmation();
$session->unsCustomerId();
if (Mage::helper('customer')->isConfirmedAccount($customer)) {
Mage::helper('customer')->sendNewAccountEmail(
$customer,
'wholesale_account_created',
'',
''
);
}
} catch (Exception $e) {
$session->unsCustomerConfirmation();
if ($e->getCode() == Mage_Customer_Model_User::EXISTS_CODE) {
$error = true;
$session->addError($this->__('This email address already exists in our system.'));
}
}
if ($error) {
return $this->_goBack();
} else {
$this->_redirect('customer/account/login');
return;
}
}
Mage::getSingleton('customer/session')->setCustomerConfirmation( true );
$session->addNotice($this->__('Please confirm the registration by clicking on the link that has been sent to your email. You must be an activated customer to gain access.'));
}
Step 4: Create Wholesale Registration URL
Finally, create a new link for the wholesale registration form in your theme’s layout XML:
app/design/frontend/{Your_Theme}/{Package_Name}/layout/local.xml
Add the following code inside a <block> or <reference> element relevant to your theme’s navigation:
<action method="addLink" translate="name">
<name>Wholesale Registration</name>
<path>/customer/account/create/wholesale/</path>
</action>
Conclusion
By following these steps, you can successfully create separate registration pages for retailers and wholesalers in Magento. This allows you to customize the sign-up process for each customer group, making your store more user-friendly for different types of customers.
Remember to clear your cache after making changes, and always test thoroughly before deploying to a production environment.
For more advanced customizations or if you’re looking to build a wholesale-focused e-commerce platform from scratch, consider leveraging Laravel’s powerful features through Laravel Company.