Private Orders Shop in PrestaShop and thirty bees part 1: manual customer verification

In this 2-part tutorial series, we will see how to create a private orders shop in PrestaShop and thirty bees.
In this first part we will see how to add a manual approval for new customers while in the second on we will learn how to prevent orders from people who are not registered and approved by us.

Watch the screencast

Text Version

I will use PrestaShop 1.6 for the demo but the modification works in thirty bees as well. Bear in mind it DOES NOT work in PrestaShop 1.7.

Open up controllers/front/AuthController.php

Look for the following code, around line 455. If it’s not in those whereabouts, just make sure you change every instance

$customer->active = 1;

set to 0, so that the user cannot perform any action right away.

Now we also want to give the user some feedback, so let’s redirect him to a custom page. Scroll down a few lines, and where you see all these redirects:

if (($back = Tools::getValue('back')) && $back == Tools::secureReferrer($back)) {
                            Tools::redirect(html_entity_decode($back));
                        }

And add a new one before

  Tools::redirect($this->context->link->getPageLink('welcome'));

Of course this page does not exist yet but we will create it in a moment.

Before that though, we have to take care of a little issue. Since the user has been created but set to inactive, the system treats it as banned by default. Even if we are to redirect to a page, we would instantly be kicked out of the session and redirected to the login. We want to create an exception so that the welcome page can be displayed.

Let’s go ahead and open up the customer class, so classes/customer.php
Look for the following method:

public static function isBanned($id_customer)

And at the very beginning, add:

        if(Context::getContext()->controller->php_self == 'welcome')
            return false;

That’s settled! Now for our welcome page, I will create a new controller and a template file in the theme folder

Let’s head to controllers/front, and create a new PHP file first, named WelcomeController.php:

class WelcomeControllerCore extends FrontController
{
    public $php_self = 'welcome';


    public function initContent()
    {
        parent::initContent();
        $this->setTemplate(_PS_THEME_DIR_.'welcome.tpl');
    }
}

Then in the theme folder, create a new file named welcome.tpl, adding the following code inside

{capture name="path"} {l s='Welcome'}{/capture}
<h1>{l s='Welcome to'} {$shop_name}! </h1>
<hr>
<p>
	{l s='Your account is currently under review, you will receive an email as soon as it is validated'}
</p>

So let’s go ahead and try it out now… but before let’s clear cache by erasing cache/class_index.php, since we added a new controller and the system wouldn’t read it otherwise.

The next step is to send out and email when a status is changed to active for the customer, in the back office.
Open controllers/admin/admincustomerscontroller.php

We will add a new method, which is inherited from the admincontroller class:


    public function processStatus()
    {
        if($object = parent::processStatus()) {
            if(get_class($object) == 'Customer' && $object->active) // the customer has been activated, send out an email
            {
                Mail::Send($object->id_lang, 'account_activated', $this->l('Your account has been activated'),
                    ['name' => $object->firstname .' '. $object->lastname],
                $object->email,
                $object->firstname .' '. $object->lastname,
                Configuration::get('PS_SHOP_EMAIL'),
                Configuration::get('PS_SHOP_NAME'));
            }
        }

       return $object;
    }

Of course, there is no such email template so we have to create it. I suggest copying an existing one, like the order confirmation, and adding new text, just to be quicker. The code is different for every template, just bear in mind to add the {name} variable inside it, so that the customer name is displayed!

This is it for part 1, make sure you test the email as well since sometimes they do fail for odd reasons, if you don’t see it coming, triple check the template names and make sure they are located in the proper path for each language you use.

In part two we will see how to prevent orders in case a customer is not registered, which is fundamental not to break the system if you have a one page checkout, as right now it would display an error.

You like the tuts and want to say "thank you"? Well, you can always feel free to donate:

You like the tuts and want to say "thank you"? Well, you can always feel free to donate: