Jump to content

Add extra message for business customers on registration success


patrikar

Recommended Posts

Hi,

 

My shop will have both private and business customers. The business customers will need to be approved manually before seeing business prices and extra categories etc. Therefore I want to display an extra message to the customers who fill some of the business fields in the registration process. Like "You have applied to become a business customer, please wait until youre approved to get the whole experience."

 

This is what I have tried so far.

 

I've override updateContext() in /override/controllers/front/AuthController.php like this:

	/**
	 * Update context after customer creation
	 * @param Customer $customer Created customer
	 */
	/*
		adds $business_account_created for my-account.tpl
		and sends an email notification
	*/
	protected function updateContext(Customer $customer)
	{
		
		$this->context->customer = $customer;
		$this->context->smarty->assign('confirmation', 1);
		$this->context->cookie->id_customer = (int)$customer->id;
		$this->context->cookie->customer_lastname = $customer->lastname;
		$this->context->cookie->customer_firstname = $customer->firstname;
		$this->context->cookie->passwd = $customer->passwd;
		$this->context->cookie->logged = 1;
		// if register process is in two steps, we display a message to confirm account creation
		if (!Configuration::get('PS_REGISTRATION_PROCESS_TYPE'))
			$this->context->cookie->account_created = 1;
		
		// hack start
		if(
			!Configuration::get('PS_REGISTRATION_PROCESS_TYPE')
			&& isset($_POST['company'], $_POST['siret'])
			&& !empty($_POST['company'])
			&& !empty($_POST['siret'])
		) {
			// if this is a business customer we want to display a custom message
			//$this->context->cookie->business_account_created = 1;
			$this->context->smarty->assign('business_account_created', 1);
			
			// and send a notification email for quick approval
			mail(
				'[email protected]'
				, '=?utf-8?B?' . base64_encode('Ny företagskund (#' . $customer->id . ')') . '?='
				, 'En ny företagskund har registrerat sig i webbshoppen och väntar på godkännande.'
				, (
					'From: X Webshop <' . '[email protected]' . ">\r\n"
					. 'Message-ID: <' . date('ymdHis') . '-' . round(microtime(true)*1000) . '-1@' . 'example.com' . ">\r\n"
					. 'MIME-Version: 1.0' . "\r\n"
					. 'Content-Type: text/plain; charset=UTF-8' . "\r\n"
					. 'Content-Transfer-Encoding: quoted-printable'
				)
			);
		}
		// hack end
		
		$customer->logged = 1;
		$this->context->cookie->email = $customer->email;
		$this->context->cookie->is_guest = !Tools::getValue('is_new_customer', 1);
		// Update cart address
		$this->context->cart->secure_key = $customer->secure_key;
	}

I detect if company name and such is present and then I first tried to set $this->context->cookie->business_account_created like is done right above for $this->context->cookie->account_created. I believed this was gonna make it to the Smarty template, which it did not. Then I tried to assign the var to Smarty the usual way, which did not work either.

 

This is from my-account.tpl:

<h1>{l s='My account'}</h1>
{if isset($account_created)}
	<p class="success">
		{l s='Your account has been created.'}
	</p>
{/if}
{if isset($business_account_created)}
	<p class="warning">
		You have applied to become a business customer, please wait until youre approved to get the whole experience... Yada yada.
	</p>
{/if}
<h4>{l s='Welcome to your account. Here, you can manage your addresses and orders.'}</h4>

This does not work and I don't know what to do next. And i don't understand how the $account_variable (which works) makes it to the Smarty template!

 

Patrik

 

Edit: My Prestashop version is 1.5.2.0

Edited by patrikar (see edit history)
Link to comment
Share on other sites

I think the best approach to achieve your goal is by using Prestashop Customers Groups feature. Then you will need to modify the registrations flow and customers creation process, according to this customers groups.

Okay ... let's take a look the modifications you've described above.
Your modification will not successfully displaying "business customer" notification because your smarty var will not work.
By the time your customer successfully create an account, s/he will be redirected to another page, that's why your smarty var doesn't work because it only assigned for authentication.tpl

Link to comment
Share on other sites

I don't understand your recommended approach. What do you mean by Prestashop Customers Groups feature?

 

Regarding my attempt of modification: I believe it's true what you say, my Smarty variable doesn't make it to my-account.tpl. But how will I go about this? It should be fairly simple I guess, I'm just not familiar working with classes and template engines in PHP. Normally I'd just set a variable and check if it's set later on...

 

I expect the method Prestashop uses for setting the other variable would be the most sufficient. But I don't understand how they're doing it.

Link to comment
Share on other sites

Hmm ... You should read about Customers Groups

 

In AuthController.php you can add get variable into redirect URL

e.g: account_type=business

Tools::redirect('index.php?controller=my-account&account_type=business');

Then in your theme file, you can use $smarty.get

{if isset($smarty.get.account_type) && $smarty.get.account_type == 'business'}
   <p class="warning">
      <!-- YOUR TEXT -->
   </p>
{/if}
Link to comment
Share on other sites

I thought you meant something else then just Customer groups, I am using Customer groups.

 

That's real clever! Seems to me like an excellent approach. And I've managed to implement it successfully.

 

Big thanks to you. :)

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...