php - Magento dropdown group selection customer registration -
i trying make group selection dropdown on magento customer registration page work. have done of following:
inserted following code template/persistent/customer/form/register.phtml:
<label for="group_id" style='margin-top:15px;'><?php echo $this->__('which group belong to? (select "pet owner" if uncertain)') ?><span class="required">*</span></label> <div style='clear:both'><p style='color:red;'>note: dvm/dacvo , institution accounts require administrative approval.</p></div> <div class="input-box" style='margin-bottom:10px;'> <select style='border:1px solid gray;' name="group_id" id="group_id" title="<?php echo $this->__('group') ?>" class="validate-group required-entry input-text" /> <?php $groups = mage::helper('customer')->getgroups()->tooptionarray(); ?> <?php foreach($groups $group){ ?> <?php if ($group['label']=="pet owner" || $group['label']=="dvm / dacvo" || $group['label']=="institution"){?> <option value="<?php print $group['value'] ?>"><?php print $group['label'] ?></option> <?php } ?> <?php } ?> </select> </div>
then following in /app/code/local/mage/customer/controllers/accountcontroller.php in createpostaction():
$customer->setgroupid($this->getrequest()->getpost(‘group_id’));
finally following in /app/code/local/mage/customer/etc/config.xml group id added:
<fieldsets> <customer_account> <prefix> <create>1</create> <update>1</update> <name>1</name> </prefix> <firstname> <create>1</create> <update>1</update> <name>1</name> </firstname> <middlename> <create>1</create> <update>1</update> <name>1</name> </middlename> <lastname> <create>1</create> <update>1</update> <name>1</name> </lastname> <suffix> <create>1</create> <update>1</update> <name>1</name> </suffix> <email> <create>1</create> <update>1</update> </email> <password> <create>1</create> </password> <confirmation> <create>1</create> </confirmation> <dob> <create>1</create> <update>1</update> </dob> <group_id><create>1</create><update>1</update></group_id> <taxvat> <create>1</create> <update>1</update> </taxvat> <gender> <create>1</create> <update>1</update> </gender> </customer_account>
i have tested several times , every customer still being added default customer group. can see doing wrong?
create own module instate of using /app/code/local/mage/customer/controllers/accountcontroller.php. please add following code in congig.xml if module name custom , namespace mymodule.
<global> <fieldsets> <customer_account> <group_id><create>1</create><update>1</update></group_id> </customer_account> </fieldsets> </global> <frontend> <routers> <customer> <args> <modules> <mymodule_custom before="mage_customer_accountcontroller">mymodule_custom</mymodule_custom> </modules> </args> </customer> </routers>
override accountcontroller. find following code controller.
<?php require_once(mage::getmoduledir('controllers','mage_customer').ds.'accountcontroller.php'); class mymodule_custom_accountcontroller extends mage_customer_accountcontroller { public function createpostaction() { $session = $this->_getsession(); if ($session->isloggedin()) { $this->_redirect('*/*/'); return; } $session->setescapemessages(true); // prevent xss injection in user input if (!$this->getrequest()->ispost()) { $errurl = $this->_geturl('*/*/create', array('_secure' => true)); $this->_redirecterror($errurl); return; } $customer = $this->_getcustomer(); try { $errors = $this->_getcustomererrors($customer); if (empty($errors)) { if($this->getrequest()->getpost('group_id')){ $customer->setgroupid($this->getrequest()->getpost('group_id')); } else { $customer->getgroupid(); } $customer->cleanpasswordsvalidationdata(); $customer->save(); $this->_dispatchregistersuccess($customer); $this->_successprocessregistration($customer); return; } else { $this->_addsessionerror($errors); } } catch (mage_core_exception $e) { $session->setcustomerformdata($this->getrequest()->getpost()); if ($e->getcode() === mage_customer_model_customer::exception_email_exists) { $url = $this->_geturl('customer/account/forgotpassword'); $message = $this->__('there account email address. if sure email address, <a href="%s">click here</a> password , access account.', $url); $session->setescapemessages(false); } else { $message = $e->getmessage(); } $session->adderror($message); } catch (exception $e) { $session->setcustomerformdata($this->getrequest()->getpost()) ->addexception($e, $this->__('cannot save customer.')); } $errurl = $this->_geturl('*/*/create', array('_secure' => true)); $this->_redirecterror($errurl); } } ?>
hope work you.
Comments
Post a Comment