sixthmind Posted April 27, 2012 Share Posted April 27, 2012 I am struggling with modifying some code in Customer registration management module. For some reason, Instant checkout is not working the way it should. When the Customer registration management module is disabled, the Instant Checkout is working fine, on submit and with no errors we go to the next step/screen. When Customer registration module is enabled, once we click on submit button under Instant checkout, we do not go to the next step/screen, instead we come back to the same screens, forms empty, and in url we have this: authentication?back=order.php%3Fstep%3D1 I think there is something in customerregistration.php, which is causing this, but cannot understand the code that well, so I don't know how and what to modify in order to make Instant checkout work. I would really appreciate it if somebody could explain the way this works, so I can then maybe try and modify the code myself. Please help me to resolve this issue. the code from customerregistration.php: <?php class customerRegistration extends Module { const __MAIL_DELIMITOR__ = ','; function __construct() { $this->name = 'customerregistration'; $this->tab = 'Tools'; $this->version = 2.0; parent::__construct(); // The parent construct is required for translations $this->page = basename(__FILE__, '.php'); $this->displayName = $this->l('Customer registration management'); $this->description = $this->l('This module allows to validate customer registration from the front office'); $this->_isCustomerRegistredByDefault = intval(Configuration::get('CUSTREG_IS_REGISTERED_BY_DEFAULT')); $this->_sendAdminMail = intval(Configuration::get('CUSTREG_SEND_ADMIN_MAIL')); $this->_mails = Configuration::get('CUSTREG_MAILS'); $this->_defaultGroups = explode (';', Configuration::get('CUSTREG_GROUPS')); $this->_registrationCode = Configuration::get('CUSTREG_REGISTRATION_CODE'); $this->_askPrivilegeAccess = Configuration::get('CUSTREG_ASK_PRIVILEGE_ACCESS'); } function install() { if (!parent::install()) return false; if (!$this->registerHook('authentication') or !$this->registerHook('createAccountForm') or !$this->registerHook('createAccount') or !$this->registerHook('backOfficeHome') or !$this->registerHook('adminCustomers')) return false; Configuration::updateValue('CUSTREG_IS_REGISTERED_BY_DEFAULT', 0); Configuration::updateValue('CUSTREG_SEND_ADMIN_MAIL', 1); Configuration::updateValue('CUSTREG_MAILS', Configuration::get('PS_SHOP_EMAIL')); Configuration::updateValue('CUSTREG_GROUPS', '1'); $tab = new Tab(); $tab->id_parent = 2; $tab->name = array(Language::getIdByIso('en') =>'Pending', Language::getIdByIso('fr') =>'En attente'); $tab->class_name = 'AdminPendingCustomers'; $tab->module = 'customerregistration'; $tab->add(); $query = 'CREATE TABLE '._DB_PREFIX_.'approvedcustomer ( `id_customer` int(2) NOT NULL, `is_approved` int(2) NOT NULL, `privilege_request` int(2) NOT NULL, `privilege_message` text, `date_add` datetime NOT NULL, `date_upd` datetime NOT NULL, PRIMARY KEY (`id_customer`)) ENGINE=MyISAM default CHARSET=utf8'; if (!Db::getInstance()->Execute($query)) return false; return true; } function uninstall() { require_once (dirname(__FILE__).'/ApprovedCustomer.php'); $allNotApproved = ApprovedCustomer::getAllNotApproved(); foreach ($allNotApproved as $approvalLine) { $customer = new Customer($approvalLine['id_customer']); $customer->delete(); } Configuration::deleteByName('CUSTREG_SEND_ADMIN_MAIL'); Configuration::deleteByName('CUSTREG_MAILS'); Configuration::deleteByName('CUSTREG_IS_REGISTERED_BY_DEFAULT'); Configuration::deleteByName('CUSTREG_GROUPS'); $tab = new Tab(Tab::getIdFromClassName ('AdminPendingCustomers')); if (! $tab->delete()) return false; if (!parent::uninstall()) return false; return Db::getInstance()->Execute('DROP TABLE '._DB_PREFIX_.'approvedcustomer'); } function hookAuthentication() { require_once (dirname(__FILE__).'/ApprovedCustomer.php'); global $cookie; $approved = ApprovedCustomer::isApproved ($cookie->id_customer); if (! $approved) { //you need add here $cookie->id_customer = 0; $cookie->logged = 0; $_POST['back'] = 'modules/customerregistration'.'/messages.php?msg=wait'; } } function hookCreateAccountForm($params) { global $smarty, $link; $smarty->assign(array( 'isRegistrationCodeManaged' => (($this->_registrationCode <>'') ?true : false), 'isPrivilegedManaged' => (($this->_askPrivilegeAccess == 1) ?true : false) )); return $this->display(__FILE__, 'registryForm.tpl'); } function hookCreateAccount($params) { require_once (dirname(__FILE__).'/ApprovedCustomer.php'); global $cookie, $back; $registration_code = pSQL(Tools::getValue('registration_code')); if ($registration_code != '' AND $registration_code == $this->_registrationCode) { $customer = $params['newCustomer']; $customer->cleanGroups(); $customer->addGroups ($this->_defaultGroups); } $cookie->logged = $this->_isCustomerRegistredByDefault; $cust = $params['newCustomer']; $approval = new ApprovedCustomer($cust->id); $approval->is_approved = $this->_isCustomerRegistredByDefault; $approval->privilege_request = intval(Tools::getValue('privilege_request'),0); $approval->privilege_message = pSQL(Tools::getValue('privilege_message'), '');; if (! $approval->save()) Tools:('Unable to save approval information'); if ($this->_sendAdminMail) $this->sendMail('pending_registration', array('customer' => $cust, 'approval'=>$approval)); if (! $approval->is_approved) { $back = 'modules/'.basename(__FILE__, '.php').'/messages.php?msg=noconnect&back=my-account.php'; $cookie->logged = 0; $cookie->id_customer = 0; } elseif ($back == '') $back = 'my-account.php'; } function hookAdminCustomers($params) { require_once (dirname(__FILE__).'/ApprovedCustomer.php'); global $cookie; $id_customer = intval($params['id_customer']); $isApproved = ApprovedCustomer::isApproved ($id_customer); $txt = '<p>'.$this->l('Customer registration').' : '; if ($isApproved) { $txt .= $this->l('Validated'); } else { $token = Tools::getAdminToken('AdminPendingCustomers'.intval(Tab::getIdFromClassName('AdminPendingCustomers')).intval($cookie->id_employee)); $txt .= '<a href="?tab=AdminPendingCustomers&approvecustomer&id_customer='.$id_customer.'&token='.$token. '&back='.urlencode($_SERVER['REQUEST_URI']).'"><span class="button">'.$this->l('Validate').'</span></a>'; $txt .= '<a href="?tab=AdminPendingCustomers&refusecustomer&id_customer='.$id_customer.'&token='.$token. '"><span class="button">'.$this->l('Refuse').'</span></a>'; } $txt .= '</p> <p>'.$this->l('Privilege access').' : '; $approvalInfos = ApprovedCustomer::getPrivilegeRequest ($id_customer); switch ($approvalInfos['privilege_request']) { case 0: /* no request */ $txt .= $this->l('Not requested'); break; case 1: /* requested */ $token = Tools::getAdminToken('AdminPendingCustomers'.intval(Tab::getIdFromClassName('AdminPendingCustomers')).intval($cookie->id_employee)); $txt .= '<a href="?tab=AdminPendingCustomers&id_customer='.$id_customer.'&approveprivilegecustomer&token='.$token.'&back='.urlencode($_SERVER['REQUEST_URI']).'" ><img src="../img/admin/enabled.gif"></a>'; $txt .= '<a href="?tab=AdminPendingCustomers&id_customer='.$id_customer.'&refuseprivilegecustomer&token='.$token.'&back='.urlencode($_SERVER['REQUEST_URI']).'" ><img src="../img/admin/disabled.gif"></a>'; break; case 2: /* granted */ $txt .= $this->l('Granted'); break; case 3: /* refused */ $txt .= $this->l('Refused'); break; default: /* unknown */ $txt .= $this->l('Not requested'); } if (isset($approvalInfos['privilege_message']) AND $approvalInfos['privilege_message'] <> '') { $txt .= '<p>'.$this->l('Message').' :<br/><textearea cols="26" rows="3">'.$approvalInfos['privilege_message'].'</textearea></p>'; } $txt .= '</p>'; return '<h2>'.$this->l('Registration').'</h2><fieldset style="width: 400px"> '.$txt . ' </fieldset> <div class="clear"> </div>'; } function hookBackOfficeHome () { require_once (dirname(__FILE__).'/ApprovedCustomer.php'); global $cookie; $allNotApproved = ApprovedCustomer::getAllNotApproved(); $nbCustomers = sizeof ($allNotApproved); $txt = ''; $txt .= '<div class="clear space"><br /><br /></div><fieldset class="width3"><legend>'. $this->l('Pending customer registration').'</legend>'; $txt .= $this->l('Number of customers waiting for registration : '); if ($nbCustomers == 0) $txt .= '<b>'.$this->l('None').'</b>'; else $txt .= '<b>'.$nbCustomers.'</b> <a href="?tab=AdminPendingCustomers&configure=customerRegistration&token='.Tools::getAdminToken('AdminPendingCustomers'.intval(Tab::getIdFromClassName('AdminPendingCustomers')).intval($cookie->id_employee)).'"><span class="button">'.$this->l('View').'</span></a>'; $txt .= '</fieldset><br/>'; return $txt; } function _display_config () { global $cookie; require_once (dirname(__FILE__).'/ApprovedCustomer.php'); $this->_html .= '<form action="'.$_SERVER['REQUEST_URI'].'" method="post"><fieldset style="width: 700px"><legend>'.$this->l('Settings').'</legend>'; $this->_html .= ' <p>'.$this->l('You can choose if customers are registrered by default or blocked until admin validation.').'<br>'. $this->l('Depending of the option, use appropriate mail template to be sent to customers.').'</p> <label>'.$this->l('Registered by default :').'</label> <div class="margin-form"> <input type="radio" name="is_default_registered" id="is_default_registered_on" value="1" '.(($this->_isCustomerRegistredByDefault) ? 'checked="checked" ' : '').'/> <label class="t" for="is_default_registered_on"> <img src="../img/admin/enabled.gif" alt="'.$this->l('Yes').'" title="'.$this->l('Yes').'" /></label> <input type="radio" name="is_default_registered" id="is_default_registered_off" value="0" '.((!$this->_isCustomerRegistredByDefault) ? 'checked="checked" ' : '').'/> <label class="t" for="is_default_registered_off"> <img src="../img/admin/disabled.gif" alt="'.$this->l('No').'" title="'.$this->l('No').'" /></label> </div> <br /> <p>'.$this->l('An email can be sent to administrator on new pending customer registration').'</p> <label>'.$this->l('Send e-mail :').'</label> <div class="margin-form"> <input type="radio" name="mail_active" id="mail_active_on" value="1" '.(($this->_sendAdminMail) ? 'checked="checked" ' : '').'/> <label class="t" for="mail_active_on"> <img src="../img/admin/enabled.gif" alt="'.$this->l('Yes').'" title="'.$this->l('Yes').'" /></label> <input type="radio" name="mail_active" id="mail_active_off" value="0" '.((!$this->_sendAdminMail) ? 'checked="checked" ' : '').'/> <label class="t" for="mail_active_off"> <img src="../img/admin/disabled.gif" alt="'.$this->l('No').'" title="'.$this->l('No').'" /></label> </div> <label>'.$this->l('E-mail adresses :').'</label> <div class="margin-form"> <textarea name="mails" rows="4" cols="40">'.str_replace(self::__MAIL_DELIMITOR__, "\n", $this->_mails).'</textarea> <p>'.$this->l('One e-mail address per line').'</p> </div> <div class="margin-form"> <input type="submit" value="'.$this->l('Update').'" name="update" class="button" /> </div> </fieldset>'; $this->_html .= ' <br/> <fieldset style="width: 700px"><legend>'.$this->l('Associated groups').'</legend>'; $this->_html .= '<p>'. $this->l('Customer registering with the given registration code will automatically be affected to the specified groups') .'<br/>'.$this->l('Let empty to disable this feature') .'</p>'; $this->_html .= '<label>'.$this->l('Privilege request :').'</label> <div class="margin-form"> <input type="radio" name="ask_privilege_access" id="ask_privilege_access_on" value="1" '.(($this->_askPrivilegeAccess) ? 'checked="checked" ' : '').'/> <label class="t" for="ask_privilege_access_on"> <img src="../img/admin/enabled.gif" alt="'.$this->l('Yes').'" title="'.$this->l('Yes').'" /></label> <input type="radio" name="ask_privilege_access" id="ask_privilege_access_off" value="0" '.((!$this->_askPrivilegeAccess) ? 'checked="checked" ' : '').'/> <label class="t" for="ask_privilege_access_off"> <img src="../img/admin/disabled.gif" alt="'.$this->l('No').'" title="'.$this->l('No').'" /></label> </div>'; $this->_html .= '<br/><label>'.$this->l('Registration code :').'</label> <div class="margin-form"> <input type="text" name="registration_code" value="'.$this->_registrationCode.'" style="width: 300px;" /> </div> <label>'.$this->l('Groups:').' </label> <div class="margin-form">'; $groups = Group::getGroups($cookie->id_lang, true); if (sizeof($groups)) { $this->_html .= ' <table cellspacing="0" cellpadding="0" class="table" style="width: 29.5em;"> <tr> <th><input type="checkbox" name="checkme" class="noborder" onclick="checkDelBoxes(this.form, \'groupBox[]\', this.checked)" /></th> <th>'.$this->l('ID').'</th> <th>'.$this->l('Group name').'</th> </tr>'; $irow = 0; foreach ($groups as $group) { $this->_html .= ' <tr class="'.($irow++ % 2 ? 'alt_row' : '').'"> <td>'.($group['id_group'] != 1 ? '<input type="checkbox" name="groupBox[]" class="groupBox" id="groupBox_'.$group['id_group'].'" value="'.$group['id_group'].'" '.(in_array($group['id_group'], $this->_defaultGroups) ? 'checked="checked" ' : '').'/>' : '').'</td> <td>'.$group['id_group'].'</td> <td><label for="groupBox_'.$group['id_group'].'" class="t">'.$group['name'].'</label></td> </tr>'; } $this->_html .= ' </table> <p style="padding:0px; margin:10px 0px 10px 0px;">'.$this->l('Mark all checkbox(es) of groups to which the customer is to be member').'</p> '; } else $this->_html .= '<p>'.$this->l('No group created').'</p>'; $this->_html .= '</div> <div class="margin-form"> <input type="submit" value="'.$this->l('Update').'" name="update" class="button" /> </div> </fieldset> </form><br>'; } function getContent () { require_once (dirname(__FILE__).'/ApprovedCustomer.php'); global $cookie; $this->_html = ''; if (!empty($_POST)) { $this->_postValidation(); if (!sizeof($this->_postErrors)) $this->_postProcess(); else foreach ($this->_postErrors AS $err) $this->_html .= '<div class="alert error">'.$err.'</div>'; } $this->_display_config (); /* Table clean-up : remove all entries for which the customer has already been deleted from customer table */ Db::getInstance()->Execute('DELETE FROM `'._DB_PREFIX_.'approvedcustomer` WHERE `id_customer` not in (SELECT a.id_customer from `'._DB_PREFIX_.'customer` a)'); return $this->_html; } private function _postProcess() { $this->_isCustomerRegistredByDefault = intval(Tools::getValue('is_default_registered', false)); Configuration::updateValue('CUSTREG_IS_REGISTERED_BY_DEFAULT', $this->_isCustomerRegistredByDefault); $this->_sendAdminMail = intval(Tools::getValue('mail_active')); Configuration::updateValue('CUSTREG_SEND_ADMIN_MAIL', $this->_sendAdminMail); $this->_askPrivilegeAccess = intval(Tools::getValue('ask_privilege_access')); Configuration::updateValue('CUSTREG_ASK_PRIVILEGE_ACCESS', $this->_askPrivilegeAccess); $this->_registrationCode = pSQL(Tools::getValue('registration_code')); Configuration::updateValue('CUSTREG_REGISTRATION_CODE', $this->_registrationCode); $mails = explode("\n", $_POST['mails']); $this->_mails = ''; foreach ($mails as $mail) $this->_mails .= trim($mail).self::__MAIL_DELIMITOR__; $this->_mails = trim($this->_mails, self::__MAIL_DELIMITOR__); Configuration::updateValue('CUSTREG_MAILS', $this->_mails); $this->_defaultGroups = Tools::getValue('groupBox'); if (is_array($this->_defaultGroups)) $this->_defaultGroupsString = '1;'.implode(';', $this->_defaultGroups); else $this->_defaultGroupsString = '1'; Configuration::updateValue('CUSTREG_GROUPS', $this->_defaultGroupsString); $this->_html .= '<div class="conf">'.$this->l('Settings updated').'</div>'; } private function _postValidation() { if (!isset($_POST['mails']) OR empty($_POST['mails'])) $this->_postErrors[] = $this->l('No e-mail addresses specified'); else { $mails = explode("\n", $_POST['mails']); foreach ($mails as $mail) { $mail = trim($mail); if (!empty($mail) AND !Validate::isEmail($mail)) $this->_postErrors[] = $this->l('Invalid e-mail: ').$mail.'.'; } } } public function sendMail ($mailName, $params) { require_once (dirname(__FILE__).'/ApprovedCustomer.php'); switch ($mailName) { case 'customer_registration_ok': $id_customer = intval($params['id_customer']); if ($id_customer <> 0) { $user = new Customer ($id_customer); Mail::Send(intval(Configuration::get('PS_LANG_DEFAULT')), 'customer_registration_ok', $this->l('Your account is activated'), array('{firstname}' => $user->firstname, '{lastname}' => $user->lastname, '{email}' => $user->email, '{passwd}' => $this->l('Already sent')), $user->email, NULL, strval(Configuration::get('PS_SHOP_EMAIL')), strval(Configuration::get('PS_SHOP_NAME')), NULL, NULL, dirname(__FILE__).'/mails/'); } break; case 'pending_registration': $customer = $params['customer']; $approval = $params['approval']; $template = 'pending_registration'; if ($approval->privilege_request) $subject = $this->l('New customer with privilege access waiting for registration'); else $subject = $this->l('New customer waiting for registration'); $templateVars = array( '{firstname}' => $customer->firstname, '{lastname}' => $customer->lastname, '{email}' => $customer->email, '{privilege_request}' => (($approval->privilege_request) ?$this->l('YES') :$this->l('NO') ) ); $dest = split(self::__MAIL_DELIMITOR__, $this->_mails); if (!Mail::Send(intval(Configuration::get('PS_LANG_DEFAULT')), $template, $subject, $templateVars, $dest, NULL, $configuration['PS_SHOP_EMAIL'], $configuration['PS_SHOP_NAME'], NULL, NULL, dirname(__FILE__).'/mails/') ) { //die('Send Mail Failed'); } break; case 'customer_privilege_ok': $id_customer = intval($params['id_customer']); if ($id_customer <> 0) { $user = new Customer ($id_customer); Mail::Send(intval(Configuration::get('PS_LANG_DEFAULT')), 'customer_privilege_ok', $this->l('Privilege access granted'), array('{firstname}' => $user->firstname, '{lastname}' => $user->lastname, '{email}' => $user->email, '{passwd}' => $this->l('Already sent')), $user->email, NULL, strval(Configuration::get('PS_SHOP_EMAIL')), strval(Configuration::get('PS_SHOP_NAME')), NULL, NULL, dirname(__FILE__).'/mails/'); } break; } } } ?> Link to comment Share on other sites More sharing options...
sixthmind Posted May 1, 2012 Author Share Posted May 1, 2012 OK, my progress so far: I managed to identify a piece a code which is preventing a customer from going to the following screen from Instant checkout form. It is the code in function hookCreateAccount($params). I disabled this code and Instant checkout works. Now, the next step is to somehow put additional code in there, like if statement, which will execute certain code only when the user is filling in the main registration form, but not the Instant checkout form. Link to comment Share on other sites More sharing options...
sixthmind Posted May 3, 2012 Author Share Posted May 3, 2012 so I identified a piece of code which stops user proceeding after Instant Checkout form is filled in: function hookCreateAccount($params) { require_once (dirname(__FILE__).'/ApprovedCustomer.php'); global $cookie, $back; $registration_code = pSQL(Tools::getValue('registration_code')); if ($registration_code != '' AND $registration_code == $this->_registrationCode) { $customer = $params['newCustomer']; $customer->cleanGroups(); $customer->addGroups ($this->_defaultGroups); } $cookie->logged = $this->_isCustomerRegistredByDefault; $cust = $params['newCustomer']; $approval = new ApprovedCustomer($cust->id); $approval->is_approved = $this->_isCustomerRegistredByDefault; $approval->privilege_request = intval(Tools::getValue('privilege_request'),0); $approval->privilege_message = pSQL(Tools::getValue('privilege_message'), '');; if (! $approval->save()) Tools:('Unable to save approval information'); if ($this->_sendAdminMail) $this->sendMail('pending_registration', array('customer' => $cust, 'approval'=>$approval)); if (! $approval->is_approved) { $back = 'modules/'.basename(__FILE__, '.php').'/messages.php?msg=noconnect&back=my-account.php'; $cookie->logged = 0; $cookie->id_customer = 0; } elseif ($back == '') $back = 'my-account.php'; } Anybody has any ideas what in this code is causing this? any help would be really appreciated. exactly what happens: once the user fill in Instant checkout form and clicks on submit, the form is redirected to the same page: ... /authentication?back=order.php%3Fstep%3D1 but it should go to: /order?step=2 the Instant Checkout form action: <form action="{$link->getPageLink('authentication.php', true)}?back={$back}" method="post" id="new_account_form" class="std"> so, should I change the action part then? how does this work? Link to comment Share on other sites More sharing options...
sixthmind Posted May 8, 2012 Author Share Posted May 8, 2012 Nobody can help with this? Link to comment Share on other sites More sharing options...
blogs Posted May 8, 2012 Share Posted May 8, 2012 good luck to you ,guys . Link to comment Share on other sites More sharing options...
Cyberservices Posted September 27, 2012 Share Posted September 27, 2012 (edited) I'm having the same problem and so far have not found a solution. Help for the master prestashop, anyone can help to solve this problem? Edited September 27, 2012 by Cyberservices (see edit history) Link to comment Share on other sites More sharing options...
FAST AERO Posted September 27, 2012 Share Posted September 27, 2012 Hello all, please help us.. I have also a requedt, many of my customers have their own transporter account number. If we can change the php code on the registration, to let the customer save many freight forwarders depening on the urgency of his request and fill up his account number.. It will be perfect ! Please help me. Prestashop can you help us ? Link to comment Share on other sites More sharing options...
Arkadia Posted October 2, 2012 Share Posted October 2, 2012 Hi guys anyone solved this issue? I fill out the instant checkout form...then I can't seem to get to the payment page...it just keeps going back to the authentication page. Link to comment Share on other sites More sharing options...
FAST AERO Posted October 2, 2012 Share Posted October 2, 2012 Hello guys, please help me.. Link to comment Share on other sites More sharing options...
Brighteyes Posted August 13, 2013 Share Posted August 13, 2013 Any joy with this? Same problem here! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now